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-1.6.14 regression: overload resolution between function that returns iterator and other type always expects iterator #23200

Closed
dsemi opened this issue Jan 12, 2024 · 3 comments · Fixed by #23207

Comments

@dsemi
Copy link

dsemi commented Jan 12, 2024

Description

This code compiles and runs fine under 1.6.12, but fails under 1.6.14 and newer:

import sugar
import sequtils

proc dosomething(iter: int -> (iterator: int)) =
  discard

proc dosomething(iter: int -> seq[int]) =
  discard

proc makeSeq(x: int): seq[int] =
  @[x]

# Works fine with 1.6.12 and 1.6.14
dosomething(makeSeq)

# Works with 1.6.12, fails with 1.6.14
dosomething((y) => makeSeq(y))

Nim Version

Nim Compiler Version 1.6.14 [MacOSX: arm64]
Compiled at 2024-01-11
Copyright (c) 2006-2023 by Andreas Rumpf

(also reproduced on x86_64 linux)

Current Output

$ ./Nim-1.6.14/bin/nim c -r test.nim
Hint: used config file '/Users/dsemi/Nim-1.6.14/config/nim.cfg' [Conf]
Hint: used config file '/Users/dsemi/Nim-1.6.14/config/config.nims' [Conf]
...............................................................
/Users/dsemi/test.nim(17, 22) Error: type mismatch: got 'seq[int]' for 'makeSeq(y)' but expected 'iterator (): int{.closure.}'

Expected Output

Successful compilation

Possible Solution

No response

Additional Information

Removing the iterator overload causes the code to compile in both versions.

@ringabout
Copy link
Member

!nim c

import sugar
import sequtils

proc dosomething(iter: int -> (iterator: int)) =
  discard

proc dosomething(iter: int -> seq[int]) =
  discard

proc makeSeq(x: int): seq[int] =
  @[x]

# Works fine with 1.6.12 and 1.6.14
dosomething(makeSeq)

# Works with 1.6.12, fails with 1.6.14
dosomething((y) => makeSeq(y))

Copy link
Contributor

🐧 Linux bisect by @ringabout (member)
devel 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 27) Error: type mismatch: got 'seq[int]' for 'makeSeq(y)' but expected 'iterator (): int{.closure.}'
assertions.nim(34)       raiseAssert
Error: unhandled exception: errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:22
  • Finished 2024-01-12T03:07:22
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
stable 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 27) Error: type mismatch: got 'seq[int]' for 'makeSeq(y)' but expected 'iterator (): int{.closure.}'
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(681, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:23
  • Finished 2024-01-12T03:07:23
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
2.0.0 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 27) Error: type mismatch: got 'seq[int]' for 'makeSeq(y)' but expected 'iterator (): int{.closure.}'
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(664, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:26
  • Finished 2024-01-12T03:07:26
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
1.6.14 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 27) Error: type mismatch: got 'seq[int]' for 'makeSeq(y)' but expected 'iterator (): int{.closure.}'
fatal.nim(54)            sysFatal
Error: unhandled exception: options.nim(645, 14) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:28
  • Finished 2024-01-12T03:07:29
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
1.4.8 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 12) Error: ambiguous call; both temp.dosomething(iter: proc (i0: int): iterator (): int{.closure.}{.closure.}) [declared in /home/runner/work/Nim/Nim/temp.nim(3, 6)] and temp.dosomething(iter: proc (i0: int): seq[int]{.closure.}) [declared in /home/runner/work/Nim/Nim/temp.nim(5, 6)] match for: (proc (y: GenericParam): untyped)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:31
  • Finished 2024-01-12T03:07:31
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
1.2.18 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 12) Error: ambiguous call; both temp.dosomething(iter: proc (i0: int): iterator (): int{.closure.}{.closure.}) [declared in /home/runner/work/Nim/Nim/temp.nim(3, 6)] and temp.dosomething(iter: proc (i0: int): seq[int]{.closure.}) [declared in /home/runner/work/Nim/Nim/temp.nim(5, 6)] match for: (proc (y: GenericParam): untyped)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:33
  • Finished 2024-01-12T03:07:33
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
1.0.10 👎 FAIL

Output

Error: Command failed: nim c --run  -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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(12, 12) Error: ambiguous call; both temp.dosomething(iter: proc (i0: int): iterator (): int{.closure.}{.closure.}) [declared in /home/runner/work/Nim/Nim/temp.nim(3, 6)] and temp.dosomething(iter: proc (i0: int): seq[int]{.closure.}) [declared in /home/runner/work/Nim/Nim/temp.nim(5, 6)] match for: (proc (y: GenericParam): untyped)

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T03:07:35
  • Finished 2024-01-12T03:07:35
  • Duration

AST

nnkStmtList.newTree(
  nnkImportStmt.newTree(
    newIdentNode("sugar")
  ),
  nnkImportStmt.newTree(
    newIdentNode("sequtils")
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkPar.newTree(
            nnkIteratorTy.newTree(
              nnkFormalParams.newTree(
                newIdentNode("int")
              ),
              newEmptyNode()
            )
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("dosomething"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("iter"),
        nnkInfix.newTree(
          newIdentNode("->"),
          newIdentNode("int"),
          nnkBracketExpr.newTree(
            newIdentNode("seq"),
            newIdentNode("int")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("makeSeq"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("seq"),
        newIdentNode("int")
      ),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("int"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkPrefix.newTree(
        newIdentNode("@"),
        nnkBracket.newTree(
          newIdentNode("x")
        )
      )
    )
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    newIdentNode("makeSeq")
  ),
  nnkCall.newTree(
    newIdentNode("dosomething"),
    nnkInfix.newTree(
      newIdentNode("=>"),
      nnkPar.newTree(
        newIdentNode("y")
      ),
      nnkCall.newTree(
        newIdentNode("makeSeq"),
        newIdentNode("y")
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 19.0
  • Created 2024-01-12T03:06:52Z
  • Comments 1
  • Commands nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints: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 16 minutes bisecting 7 commits at 0 commits per second

@dsemi
Copy link
Author

dsemi commented Jan 12, 2024

Neat tool! Maybe a good feature request is to be able to set boundaries in case there's some set of code that's also broken on old versions like it appears this is.

I manually bisected and found 4ea0ce9 to be the culprit.

dsemi added a commit to dsemi/advent_nim that referenced this issue Jan 14, 2024
metagn added a commit to metagn/Nim that referenced this issue Jan 14, 2024
@Araq Araq closed this as completed in f46f26e Jan 17, 2024
narimiran pushed a commit that referenced this issue Apr 19, 2024
fixes #23200, fixes #18866

#21065 made it so `auto` proc return types remained as `tyAnything` and
not turned to `tyUntyped`. This had the side effect that anything
previously bound to `tyAnything` in the proc type match was then bound
to the proc return type, which is wrong since we don't know the proc
return type even if we know the expected parameter types (`tyUntyped`
also [does not care about its previous bindings in
`typeRel`](https://github.com/nim-lang/Nim/blob/ab4278d2179639f19967431a7aa1be858046f7a7/compiler/sigmatch.nim#L1059-L1061)
maybe for this reason).

Now we mark `tyAnything` return types for routines as `tfRetType` [as
done for other meta return
types](https://github.com/nim-lang/Nim/blob/18b5fb256d4647efa6a64df451d37129d36e96f3/compiler/semtypes.nim#L1451),
and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`.
On top of this, we reset the type relation in `paramTypesMatch` only
after creating the instantiation (instead of trusting
`isInferred`/`isInferredConvertible` before creating the instantiation),
using the same mechanism that `isBothMetaConvertible` uses.

This fixes the issues as well as making the disabled t15386_2 test
introduced in #21065 work. As seen in the changes for the other tests,
the error messages give an obscure `proc (a: GenericParam): auto` now,
but it does give the correct error that the overload doesn't match
instead of matching the overload pre-emptively and expecting a specific
return type.

tsugar had to be changed due to #16906, which is the problem where
`void` is not inferred in the case where `result` was never touched.

(cherry picked from commit f46f26e)
narimiran pushed a commit that referenced this issue Apr 27, 2024
fixes #23200, fixes #18866

not turned to `tyUntyped`. This had the side effect that anything
previously bound to `tyAnything` in the proc type match was then bound
to the proc return type, which is wrong since we don't know the proc
return type even if we know the expected parameter types (`tyUntyped`
also [does not care about its previous bindings in
`typeRel`](https://github.com/nim-lang/Nim/blob/ab4278d2179639f19967431a7aa1be858046f7a7/compiler/sigmatch.nim#L1059-L1061)
maybe for this reason).

Now we mark `tyAnything` return types for routines as `tfRetType` [as
done for other meta return
types](https://github.com/nim-lang/Nim/blob/18b5fb256d4647efa6a64df451d37129d36e96f3/compiler/semtypes.nim#L1451),
and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`.
On top of this, we reset the type relation in `paramTypesMatch` only
after creating the instantiation (instead of trusting
`isInferred`/`isInferredConvertible` before creating the instantiation),
using the same mechanism that `isBothMetaConvertible` uses.

This fixes the issues as well as making the disabled t15386_2 test
introduced in #21065 work. As seen in the changes for the other tests,
the error messages give an obscure `proc (a: GenericParam): auto` now,
but it does give the correct error that the overload doesn't match
instead of matching the overload pre-emptively and expecting a specific
return type.

tsugar had to be changed due to #16906, which is the problem where
`void` is not inferred in the case where `result` was never touched.

(cherry picked from commit f46f26e)
narimiran pushed a commit that referenced this issue Apr 27, 2024
fixes #23200, fixes #18866

not turned to `tyUntyped`. This had the side effect that anything
previously bound to `tyAnything` in the proc type match was then bound
to the proc return type, which is wrong since we don't know the proc
return type even if we know the expected parameter types (`tyUntyped`
also [does not care about its previous bindings in
`typeRel`](https://github.com/nim-lang/Nim/blob/ab4278d2179639f19967431a7aa1be858046f7a7/compiler/sigmatch.nim#L1059-L1061)
maybe for this reason).

Now we mark `tyAnything` return types for routines as `tfRetType` [as
done for other meta return
types](https://github.com/nim-lang/Nim/blob/18b5fb256d4647efa6a64df451d37129d36e96f3/compiler/semtypes.nim#L1451),
and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`.
On top of this, we reset the type relation in `paramTypesMatch` only
after creating the instantiation (instead of trusting
`isInferred`/`isInferredConvertible` before creating the instantiation),
using the same mechanism that `isBothMetaConvertible` uses.

This fixes the issues as well as making the disabled t15386_2 test
introduced in #21065 work. As seen in the changes for the other tests,
the error messages give an obscure `proc (a: GenericParam): auto` now,
but it does give the correct error that the overload doesn't match
instead of matching the overload pre-emptively and expecting a specific
return type.

tsugar had to be changed due to #16906, which is the problem where
`void` is not inferred in the case where `result` was never touched.

(cherry picked from commit f46f26e)
narimiran pushed a commit that referenced this issue Apr 27, 2024
fixes #23200, fixes #18866

not turned to `tyUntyped`. This had the side effect that anything
previously bound to `tyAnything` in the proc type match was then bound
to the proc return type, which is wrong since we don't know the proc
return type even if we know the expected parameter types (`tyUntyped`
also [does not care about its previous bindings in
`typeRel`](https://github.com/nim-lang/Nim/blob/ab4278d2179639f19967431a7aa1be858046f7a7/compiler/sigmatch.nim#L1059-L1061)
maybe for this reason).

Now we mark `tyAnything` return types for routines as `tfRetType` [as
done for other meta return
types](https://github.com/nim-lang/Nim/blob/18b5fb256d4647efa6a64df451d37129d36e96f3/compiler/semtypes.nim#L1451),
and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`.
On top of this, we reset the type relation in `paramTypesMatch` only
after creating the instantiation (instead of trusting
`isInferred`/`isInferredConvertible` before creating the instantiation),
using the same mechanism that `isBothMetaConvertible` uses.

This fixes the issues as well as making the disabled t15386_2 test
introduced in #21065 work. As seen in the changes for the other tests,
the error messages give an obscure `proc (a: GenericParam): auto` now,
but it does give the correct error that the overload doesn't match
instead of matching the overload pre-emptively and expecting a specific
return type.

tsugar had to be changed due to #16906, which is the problem where
`void` is not inferred in the case where `result` was never touched.

(cherry picked from commit f46f26e)
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