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

IndexDefect thrown when destructuring a lent value #23454

Closed
Nycto opened this issue Mar 28, 2024 · 2 comments · Fixed by #23993
Closed

IndexDefect thrown when destructuring a lent value #23454

Nycto opened this issue Mar 28, 2024 · 2 comments · Fixed by #23993
Assignees

Comments

@Nycto
Copy link
Contributor

Nycto commented Mar 28, 2024

Description

The following code throws a compiler error, when it is expected to work:

type
    Letter = enum A

    LetterPairs = object
        values: seq[(Letter, string)]

iterator items(list: var LetterPairs): lent (Letter, string) =
    for item in list.values:
        yield item

var instance = LetterPairs(values: @[ (A, "foo") ])

for (a, _) in instance:
    case a
    of A: discard

Nim Version

Nim Compiler Version 2.0.2 [Linux: amd64]
Compiled at 2023-12-15
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: c4c44d10df8a14204a75c34e499def200589cb7c
active boot switches: -d:release

And also:

> ~/Code/Nim/compiler/nim --version       
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-03-14
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 7657a637b8500e7ab95c18c8559d66cc2da2d124
active boot switches:

Current Output

The thrown error is:


Hint: used config file '/home/nycto/Code/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/nycto/Code/Nim/config/config.nims' [Conf]
...................................................................../home/nycto/Code/Nim/compiler/nim.nim(169) nim
/home/nycto/Code/Nim/compiler/nim.nim(124) handleCmdLine
/home/nycto/Code/Nim/compiler/main.nim(338) mainCommand
/home/nycto/Code/Nim/compiler/main.nim(304) compileToBackend
/home/nycto/Code/Nim/compiler/main.nim(142) commandCompileToC
/home/nycto/Code/Nim/compiler/pipelines.nim(325) compilePipelineProject
/home/nycto/Code/Nim/compiler/pipelines.nim(245) compilePipelineModule
/home/nycto/Code/Nim/compiler/pipelines.nim(188) processPipelineModule
/home/nycto/Code/Nim/compiler/pipelines.nim(26) processPipeline
/home/nycto/Code/Nim/compiler/cgen.nim(2123) genTopLevelStmt
/home/nycto/Code/Nim/compiler/transf.nim(1244) transformStmt
/home/nycto/Code/Nim/compiler/transf.nim(1160) processTransf
/home/nycto/Code/Nim/compiler/transf.nim(1139) transform
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1031) transform
/home/nycto/Code/Nim/compiler/transf.nim(804) transformFor
/home/nycto/Code/Nim/compiler/transf.nim(1038) transform
/home/nycto/Code/Nim/compiler/transf.nim(269) transformBlock
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1139) transform
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1139) transform
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1038) transform
/home/nycto/Code/Nim/compiler/transf.nim(269) transformBlock
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1036) transform
/home/nycto/Code/Nim/compiler/transf.nim(293) transformWhile
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1139) transform
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1139) transform
/home/nycto/Code/Nim/compiler/transf.nim(109) transformSons
/home/nycto/Code/Nim/compiler/transf.nim(1105) transform
/home/nycto/Code/Nim/compiler/transf.nim(448) transformYield
/home/nycto/Code/Nim/compiler/lowerings.nim(34) newTupleAccess
/home/nycto/Code/Nim/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]


### Expected Output

```text
I expect this code to compile, or at the very least produce an actionable error message

Possible Solution

No response

Additional Information

No response

@juancarlospaco
Copy link
Collaborator

!nim c

type
    Letter = enum A

    LetterPairs = object
        values: seq[(Letter, string)]

iterator items(list: var LetterPairs): lent (Letter, string) =
    for item in list.values:
        yield item

var instance = LetterPairs(values: @[ (A, "foo") ])

for (a, _) in instance:
    case a
    of A: discard

Copy link
Contributor

🐧 Linux bisect by @juancarlospaco (collaborator)
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
fatal.nim(53)            sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:28
  • Finished 2024-03-28T21:08:28
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkTupleConstr.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkTupleConstr.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkTupleConstr.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
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
fatal.nim(53)            sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:28
  • Finished 2024-03-28T21:08:29
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkTupleConstr.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkTupleConstr.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkTupleConstr.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
2.0.2 👎 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
fatal.nim(53)            sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:29
  • Finished 2024-03-28T21:08:29
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkTupleConstr.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkTupleConstr.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkTupleConstr.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
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
fatal.nim(54)            sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:33
  • Finished 2024-03-28T21:08:33
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkTupleConstr.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkTupleConstr.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkTupleConstr.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
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
fatal.nim(49)            sysFatal
Error: unhandled exception: index 1 not in 0 .. 0 [IndexDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:35
  • Finished 2024-03-28T21:08:36
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkPar.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkPar.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkPar.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
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(7, 15) Error: address of 'item' may not escape its stack frame

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:38
  • Finished 2024-03-28T21:08:39
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkPar.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkPar.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkPar.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
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(7, 15) Error: address of 'item' may not escape its stack frame

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-03-28T21:08:41
  • Finished 2024-03-28T21:08:41
  • Duration

AST

nnkStmtList.newTree(
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Letter"),
      newEmptyNode(),
      nnkEnumTy.newTree(
        newEmptyNode(),
        newIdentNode("A")
      )
    ),
    nnkTypeDef.newTree(
      newIdentNode("LetterPairs"),
      newEmptyNode(),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        nnkRecList.newTree(
          nnkIdentDefs.newTree(
            newIdentNode("values"),
            nnkBracketExpr.newTree(
              newIdentNode("seq"),
              nnkPar.newTree(
                newIdentNode("Letter"),
                newIdentNode("string")
              )
            ),
            newEmptyNode()
          )
        )
      )
    )
  ),
  nnkIteratorDef.newTree(
    newIdentNode("items"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      nnkCommand.newTree(
        newIdentNode("lent"),
        nnkPar.newTree(
          newIdentNode("Letter"),
          newIdentNode("string")
        )
      ),
      nnkIdentDefs.newTree(
        newIdentNode("list"),
        nnkVarTy.newTree(
          newIdentNode("LetterPairs")
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkForStmt.newTree(
        newIdentNode("item"),
        nnkDotExpr.newTree(
          newIdentNode("list"),
          newIdentNode("values")
        ),
        nnkStmtList.newTree(
          nnkYieldStmt.newTree(
            newIdentNode("item")
          )
        )
      )
    )
  ),
  nnkVarSection.newTree(
    nnkIdentDefs.newTree(
      newIdentNode("instance"),
      newEmptyNode(),
      nnkObjConstr.newTree(
        newIdentNode("LetterPairs"),
        nnkExprColonExpr.newTree(
          newIdentNode("values"),
          nnkPrefix.newTree(
            newIdentNode("@"),
            nnkBracket.newTree(
              nnkPar.newTree(
                newIdentNode("A"),
                newLit("foo")
              )
            )
          )
        )
      )
    )
  ),
  nnkForStmt.newTree(
    nnkVarTuple.newTree(
      newIdentNode("a"),
      newIdentNode("_"),
      newEmptyNode()
    ),
    newIdentNode("instance"),
    nnkStmtList.newTree(
      nnkCaseStmt.newTree(
        newIdentNode("a"),
        nnkOfBranch.newTree(
          newIdentNode("A"),
          nnkStmtList.newTree(
            nnkDiscardStmt.newTree(
              newEmptyNode()
            )
          )
        )
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 19.1
  • Created 2024-03-28T21:07:58Z
  • 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

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