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

Error with generic types #127

Open
arkt8 opened this issue Apr 2, 2022 · 1 comment
Open

Error with generic types #127

arkt8 opened this issue Apr 2, 2022 · 1 comment

Comments

@arkt8
Copy link

arkt8 commented Apr 2, 2022

The following code compiles and runs ok, but nimsuggest complains about function calls in assert lines (last two):

type MaybeS = enum Nothing, Just
type Maybe[T] = tuple[fst:MaybeS,snd:T]

proc fromMaybe[T](self:Maybe[T],a:T) : T =
  if self[0] == Nothing :
    return a
  else :
    return self[1]

proc fromJust[T](self:Maybe[T]) : T =
  if self.fst == Just :
    return self.snd
  else :
    raise newException(IOError,"not Just")

let nothing : Maybe[int] = (Nothing,0)
let something : Maybe[int] = (Just,2)

assert fromMaybe(nothing,10) == 10
assert fromJust(something) == 2

x

Running directly with nimsuggest from terminal return this:

chk     skUnknown               Error   /home/thadeu/Nim/learn/types.nim        156     17      "type mismatch: got <Maybe[system.int]>\x0Abut expected one of:\x0Aproc fromJust[T](s: Maybe[T]): T\x0A  first type mismatch at position: 1\x0A  required type for s: Maybe[fromJust.T]\x0A  but expression \'something\' is of type: Maybe[system.int]\x0A\x0Aexpression: fromJust(something)"    0

Nim version: 1.6.4 (installed with choosenim)

@iacore
Copy link

iacore commented Jul 3, 2022

Can reproduce

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

2 participants