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

iterator: wrong + called - lib/system.nim(1102, 12): Cannot instantiate T #5702

Open
mratsim opened this issue Apr 13, 2017 · 2 comments
Open

Comments

@mratsim
Copy link
Collaborator

mratsim commented Apr 13, 2017

Here is what works, uncommenting bar gives an error in system.nim

iterator zip[T1, T2](a: openarray[T1], b: openarray[T2]): (T1,T2) {.inline.} =
  let len = min(a.len, b.len)
  for i in 0..<len:
    yield (a[i], b[i])

iterator zipWith[T1,T2,T3](f: proc(u: T1, v:T2): T3, a: openarray[T1], b: openarray[T2]): T3  {.inline.} =
  for i,j in zip(a,b):
    yield f(i,j)

proc foo(args: varargs[int]) =
    for i in zip(args,args):
        echo i

## Uncommenting this fails: "Error: cannot instantiate: T"
## There is no T anywhere in the code

# proc bar(args: varargs[int]) =
#     for i in zipWith(`+`,args,args):
#         echo i


foo(1,2,3,4)

When uncommenting bar:

playground.nim(18, 22) template/generic instantiation from here
lib/system.nim(1102, 12) Error: cannot instantiate: 'T'

18, 22 is +
Line 1102,12: https://github.com/nim-lang/Nim/blob/devel/lib/system.nim#L1102

proc `+` *[T](x, y: set[T]): set[T] {.magic: "PlusSet", noSideEffect.}

It seems like instead of calling + for numbers, I'm calling + for set

(edit: correcting mistake, changed for i in for i,j in bar)

@mratsim
Copy link
Collaborator Author

mratsim commented Apr 13, 2017

Modifing to +[int] makes the error clearer:

proc bar(args: varargs[int]) =
    for i in zipWith(`+`[int],args,args):
        echo i

Error:

playground.nim(18, 21) Error: type mismatch: got (proc (x: set[int], y: set[int]): set[int]{.noSideEffect.}, varargs[int],
varargs[int])
but expected one of:
iterator zipWith[T1, T2, T3](f: proc (u: T1; v: T2): T3; a: openArray[T1]; b: openArray[T2]): T3

@Araq
Copy link
Member

Araq commented Apr 13, 2017

You cannot pass system.+ around as a first class proc, it's a builtin.

@ghost ghost added the Generics label Oct 15, 2017
timotheecour added a commit to timotheecour/Nim that referenced this issue Aug 21, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Sep 1, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Sep 6, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Sep 7, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Sep 8, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Sep 8, 2019
timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 3, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 28, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 11, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 11, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 18, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 18, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 19, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 22, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 23, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jun 23, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Jul 5, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Nov 2, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants