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

Nim cannot detect proper overload without importing the used generic module in wrapper module #22543

Closed
hamidb80 opened this issue Aug 23, 2023 · 4 comments · Fixed by #22573
Closed

Comments

@hamidb80
Copy link
Contributor

hamidb80 commented Aug 23, 2023

Description

compile wrapper.nim.

wrapper.nim

# import std/lists # XXX if uncommented, code complies!!!
import inside

bug 1, @[1]

inside.nim

import std/lists

proc bug*[L](
  val: L, # XXX without generics code compiles. 
  arr: seq[int]
) = 
  discard toDoublyLinkedList arr

Nim Version

Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-08-23
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 6b04d03
active boot switches: -d:release

Current Output

/home/hamidb80/.choosenim/toolchains/nim-#devel/lib/pure/collections/lists.nim(188, 11) Error: type mismatch
Expression: add(result, elem)
  [1] result: DoublyLinkedList[system.int]
  [2] elem: int

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](x: var seq[T]; y: openArray[T])
[1] proc add[T](x: var seq[T]; y: sink T)

Expected Output

nothing - just compiles successfully

Possible Solution

seems like the generic call is tied to the caller module?

@juancarlospaco
Copy link
Collaborator

!nim c

import temp1
bug(1, @[1])
import std/lists
proc bug*[L](v: L; a: seq[int]) = discard toDoublyLinkedList(a)

@github-actions
Copy link
Contributor

@juancarlospaco (collaborator)

devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 4) template/generic instantiation of `bug` from here
/home/runner/work/Nim/Nim/temp1.nim(2, 61) template/generic instantiation of `toDoublyLinkedList` from here
/home/runner/.choosenim/toolchains/nim-#devel/lib/pure/collections/lists.nim(188, 11) Error: type mismatch
Expression: add(result, elem)
  [1] result: DoublyLinkedList[system.int]
  [2] elem: int

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](x: var seq[T]; y: openArray[T])
[1] proc add[T](x: var seq[T]; y: sink T)

Stats

  • Started 2023-08-23T20:05:17
  • Finished 2023-08-23T20:05:17
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 4) template/generic instantiation of `bug` from here
/home/runner/work/Nim/Nim/temp1.nim(2, 61) template/generic instantiation of `toDoublyLinkedList` from here
/home/runner/.choosenim/toolchains/nim-2.0.0/lib/pure/collections/lists.nim(188, 11) Error: type mismatch
Expression: add(result, elem)
  [1] result: DoublyLinkedList[system.int]
  [2] elem: int

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](x: var seq[T]; y: openArray[T])
[1] proc add[T](x: var seq[T]; y: sink T)

Stats

  • Started 2023-08-23T20:05:18
  • Finished 2023-08-23T20:05:19
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 4) template/generic instantiation of `bug` from here
/home/runner/work/Nim/Nim/temp1.nim(2, 61) template/generic instantiation of `toDoublyLinkedList` from here
/home/runner/.choosenim/toolchains/nim-2.0.0/lib/pure/collections/lists.nim(188, 11) Error: type mismatch
Expression: add(result, elem)
  [1] result: DoublyLinkedList[system.int]
  [2] elem: int

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](x: var seq[T]; y: openArray[T])
[1] proc add[T](x: var seq[T]; y: sink T)

Stats

  • Started 2023-08-23T20:05:19
  • Finished 2023-08-23T20:05:19
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
1.6.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp.nim(2, 4) template/generic instantiation of `bug` from here
/home/runner/work/Nim/Nim/temp1.nim(2, 61) template/generic instantiation of `toDoublyLinkedList` from here
/home/runner/.choosenim/toolchains/nim-1.6.0/lib/pure/collections/lists.nim(189, 11) Error: type mismatch: got <DoublyLinkedList[system.int], int>
but expected one of:
proc add(x: var string; y: char)
  first type mismatch at position: 1
  required type for x: var string
  but expression 'result' is of type: DoublyLinkedList[system.int]
proc add(x: var string; y: cstring)
  first type mismatch at position: 1
  required type for x: var string
  but expression 'result' is of type: DoublyLinkedList[system.int]
proc add(x: var string; y: string)
  first type mismatch at position: 1
  required type for x: var string
  but expression 'result' is of type: DoublyLinkedList[system.int]
proc add[T](x: var seq[T]; y: openArray[T])
  first type mismatch at position: 1
  required type for x: var seq[T]
  but expression 'result' is of type: DoublyLinkedList[system.int]
proc add[T](x: var seq[T]; y: sink T)
  first type mismatch at position: 1
  required type for x: var seq[T]
  but expression 'result' is of type: DoublyLinkedList[system.int]

expression: add(result, elem)

Stats

  • Started 2023-08-23T20:05:22
  • Finished 2023-08-23T20:05:22
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
1.4.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp1.nim(2, 61) Error: undeclared identifier: 'toDoublyLinkedList'

Stats

  • Started 2023-08-23T20:05:25
  • Finished 2023-08-23T20:05:26
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
1.2.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp1.nim(2, 61) Error: undeclared identifier: 'toDoublyLinkedList'

Stats

  • Started 2023-08-23T20:05:42
  • Finished 2023-08-23T20:05:42
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
1.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp1.nim(2, 61) Error: undeclared identifier: 'toDoublyLinkedList'

Stats

  • Started 2023-08-23T20:05:53
  • Finished 2023-08-23T20:05:54
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
0.20.2 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
/home/runner/work/Nim/Nim/temp1.nim(2, 61) Error: undeclared identifier: 'toDoublyLinkedList'

Stats

  • Started 2023-08-23T20:06:03
  • Finished 2023-08-23T20:06:03
  • Duration

IR

Compiled filesize 0 bytes (0 bytes)

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("temp1")
  ),
  nnkCall.newTree(
    newIdentNode("bug"),
    newLit(1),
    nnkPrefix.newTree(
      newIdentNode("@"),
      nnkBracket.newTree(
        newLit(1)
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • LibC 2.35
  • Valgrind 3.18.1
  • NodeJS 17.1
  • Linux 5.15.0
  • Created 2023-08-23T20:04:26Z
  • Comments 1
  • Commands nim c --run -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --warnings:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim

🤖 Bug found in 49 minutes bisecting 8 commits at 0 commits per second.

@Araq
Copy link
Member

Araq commented Aug 23, 2023

Use a bind or mixin statement.

@Araq Araq closed this as completed Aug 23, 2023
@metagn
Copy link
Collaborator

metagn commented Aug 28, 2023

I think the issue is that toDoublyLinkedList/toSinglyLinkedList in lists are declared before add for lists (single/double)

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

Successfully merging a pull request may close this issue.

4 participants