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

Regression of tuple type inference when @[] is used. #23199

Open
saffage opened this issue Jan 11, 2024 · 3 comments
Open

Regression of tuple type inference when @[] is used. #23199

saffage opened this issue Jan 11, 2024 · 3 comments

Comments

@saffage
Copy link

saffage commented Jan 11, 2024

Description

This code crashes the compiler with AssertionDefect.

proc doNothingWith[T](x: T): T = x

let x = doNothingWith((@[], 1))

Of course, everything works when the type is specified explicitly. Works on Nim 1.6.18 as expected.

Nim Version

Nim Compiler Version 2.1.1 [Windows: amd64]
Compiled at 2024-01-11
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 30cb682
active boot switches: -d:release


Nim Compiler Version 2.0.0 [Windows: amd64]
Compiled at 2023-08-01
Copyright (c) 2006-2023 by Andreas Rumpf

active boot switches: -d:release

Current Output

Error: unhandled exception: liftdestructors.nim(633, 5) `t.destructor != nil` [AssertionDefect]

Expected Output

Error: cannot infer the type of the tuple

Possible Solution

No response

Additional Information

No response

@metagn
Copy link
Collaborator

metagn commented Jan 11, 2024

Very likely doNothingWith[(seq[empty], int)] used to compile and assigning it to x gave the correct error message. Hence this also used to crash the compiler:

proc doNothingWith[T](x: T): T = x
echo doNothingWith((@[], 1))

We can probably add a hasEmpty check to the new finishOperand.

@ringabout
Copy link
Member

!nim c

proc doNothingWith[T](x: T): T = x

let x = doNothingWith((@[], 1))

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
assertions.nim(34)       raiseAssert
Error: unhandled exception: liftdestructors.nim(633, 5) `t.destructor != nil`  [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T12:05:15
  • Finished 2024-01-12T12:05:15
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkTupleConstr.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
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
assertions.nim(34)       raiseAssert
Error: unhandled exception: liftdestructors.nim(601, 5) `t.destructor != nil`  [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T12:05:16
  • Finished 2024-01-12T12:05:16
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkTupleConstr.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
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
assertions.nim(34)       raiseAssert
Error: unhandled exception: liftdestructors.nim(602, 5) `t.destructor != nil`  [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T12:05:19
  • Finished 2024-01-12T12:05:20
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkTupleConstr.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
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(2, 22) Error: cannot infer the type of the tuple
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-12T12:05:22
  • Finished 2024-01-12T12:05:22
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkTupleConstr.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
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(2, 22) Error: cannot infer the type of the tuple

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T12:05:25
  • Finished 2024-01-12T12:05:25
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkPar.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
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(2, 22) Error: cannot infer the type of the tuple

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T12:05:27
  • Finished 2024-01-12T12:05:27
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkPar.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
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(2, 22) Error: cannot infer the type of the tuple

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-01-12T12:05:29
  • Finished 2024-01-12T12:05:29
  • Duration

AST

nnkStmtList.newTree(
  nnkProcDef.newTree(
    newIdentNode("doNothingWith"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("T"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newIdentNode("T"),
      nnkIdentDefs.newTree(
        newIdentNode("x"),
        newIdentNode("T"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("x")
    )
  ),
  nnkLetSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("x"),
      newEmptyNode(),
      nnkCall.newTree(
        newIdentNode("doNothingWith"),
        nnkPar.newTree(
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
            )
          ),
          newLit(1)
        )
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 19.0
  • Created 2024-01-12T12:04:45Z
  • Comments 2
  • 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 17 minutes bisecting 7 commits at 0 commits per second

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

No branches or pull requests

3 participants