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

Generic concept has itself as generic parameters cause type mismatch #8060

Open
7sDream opened this issue Jun 18, 2018 · 1 comment
Open
Labels

Comments

@7sDream
Copy link
Contributor

7sDream commented Jun 18, 2018

type
  Iterable[T] = concept x
    for v in x:
      type(v) is T

proc map2[T, U](itit: Iterable[Iterable[T]], f: proc(_: T): U): seq[U] =
  result = @[]
  for it in itit:
    for v in it:
      result.add(f(v))

echo map2(@[@[1, 2, 3], @[4, 5, 6]], proc (x: int): int = x + 1)

this code compile failed(try it on glot):

main.nim(12, 10) Error: type mismatch: got <seq[seq[int]], proc (x: int): int{.noSideEffect, gcsafe, locks: 0.}>
but expected one of: 
proc map2[T, U](itit: Iterable[Iterable[T]]; f: proc (_: T): U): seq[U]
  first type mismatch at position: 2
  required type: proc (_: T): U{.closure.}
  but expression 'proc (x: int): int = result = x + 1' is of type: proc (x: int): int{.noSideEffect, gcsafe, locks: 0.}

expression: map2(@[@[1, 2, 3], @[4, 5, 6]], proc (x: int): int = result = x + 1)

but if I change Iterable[Iterable[T]] to Iterable[seq[T]], it will run as expected.

@narimiran
Copy link
Member

this code compile failed ... but if I change Iterable[Iterable[T]] to Iterable[seq[T]], it will run as expected.

Still the same behaviour in July 2019 with the latest Nim (v0.20.99).

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

No branches or pull requests

3 participants