Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nimsuggest gives false errors with functions when using generics #24594

Open
MarceloLuisDantas opened this issue Dec 30, 2024 · 1 comment
Open

Comments

@MarceloLuisDantas
Copy link

MarceloLuisDantas commented Dec 30, 2024

Description

i'm studying how to use generics, and for a while now, i'm having a problem with nimsuggest, when i try to call functions that uses generics, i need explicitly say the type, otherwise the nimsuggest gives a false error, the code compiles and runs correctly even though nimsuggest says otherwise. The problem is a conflict between int literal and system int, I didn't find anything about this on the doc or something.

Code:

type Stack*[T] = ref object
    stack: seq[T]

proc newStack*[T](): Stack[T] = 
    new Stack[T]

proc add*[T](self: var Stack[T], valor: T) =
    self.stack.add(valor)

var nStack = newStack[int]()

nStack.add(10)          # false error
add(nStack, 11)         # false error
add[int](nStack, 12)    # "works"

Error

type mismatch
Expression: add(nStack, 12)
  [1] nStack: Stack[system.int]
  [2] 12: int literal(12)

Expected one of (first mismatch at [position]):
[1] proc add(x: var string; y: char)
[1] proc add(x: var string; y: cstring)
[1] proc add(x: var string; y: string)
[1] proc add[T](self: var Stack[T]; valor: T)
[1] proc add[T](x: var seq[T]; y: openArray[T])
[1] proc add[T](x: var seq[T]; y: sink T)

Nim Version

Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-07-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3b
active boot switches: -d:release

@MarceloLuisDantas
Copy link
Author

Also, i'm trying to find the bug on the nimsuggest source code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant