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

Generic procs fails to properly instantiate a type #23287

Closed
beef331 opened this issue Feb 6, 2024 · 3 comments · Fixed by #24525
Closed

Generic procs fails to properly instantiate a type #23287

beef331 opened this issue Feb 6, 2024 · 3 comments · Fixed by #24525

Comments

@beef331
Copy link
Collaborator

beef331 commented Feb 6, 2024

Description

template emitTupleType(trait: typedesc): untyped =
  trait

type
  Traitor[Traits] = ref object of RootObj ##
    vtable: emitTupleType(Traits)

type Generic[X] = object

proc test2[Traits](val: Traitor[Generic[Traits]]) =
  static: assert val.vtable is int

proc test[X](val: Traitor[Generic[X]]) = discard

test2 Traitor[Generic[int]]() # This should error,  but passes
test Traitor[Generic[int]]()

Nim Version

2.0.2 and devel

Current Output

/home/jason/Documents/Nim/bin/test.nim(16, 1) template/generic instantiation of `test` from here
/home/jason/Documents/Nim/bin/test.nim(6, 27) Error: undeclared identifier: 'Traits'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 3): 'Traitor'


### Expected Output

```text
The assertion should fail, then `test` should compile fine.

Possible Solution

No response

Additional Information

No response

@ringabout
Copy link
Member

!nim c

template emitTupleType(trait: typedesc): untyped =
  trait

type
  Traitor[Traits] = ref object of RootObj ##
    vtable: emitTupleType(Traits)

type Generic[X] = object

proc test2[Traits](val: Traitor[Generic[Traits]]) =
  static: assert val.vtable is int

proc test[X](val: Traitor[Generic[X]]) = discard

test2 Traitor[Generic[int]]() # This should error,  but passes
test Traitor[Generic[int]]()

Copy link
Contributor

github-actions bot commented Feb 6, 2024

🐧 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(11, 1) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 3): 'Traitor'
assertions.nim(34)       raiseAssert
Error: unhandled exception: errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:17
  • Finished 2024-02-06T07:38:17
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
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(11, 1) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 3): 'Traitor'
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(681, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:18
  • Finished 2024-02-06T07:38:18
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
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(11, 1) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 3): 'Traitor'
assertions.nim(34)       raiseAssert
Error: unhandled exception: options.nim(664, 5) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:21
  • Finished 2024-02-06T07:38:21
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
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(11, 6) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'
candidates (edit distance, scope distance); see '--spellSuggest': 
 (2, 3): 'Traitor' [type declared in /home/runner/work/Nim/Nim/temp.nim(4, 3)]
fatal.nim(54)            sysFatal
Error: unhandled exception: options.nim(645, 14) `false` errGenerated [AssertionDefect]

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:23
  • Finished 2024-02-06T07:38:24
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
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(11, 6) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:26
  • Finished 2024-02-06T07:38:26
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
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(11, 6) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:28
  • Finished 2024-02-06T07:38:28
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
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(11, 6) template/generic instantiation of `test` from here
/home/runner/work/Nim/Nim/temp.nim(5, 27) Error: undeclared identifier: 'Traits'

IR

Compiled filesize 0 bytes (0 bytes)

Stats

  • Started 2024-02-06T07:38:30
  • Finished 2024-02-06T07:38:30
  • Duration

AST

nnkStmtList.newTree(
  nnkTemplateDef.newTree(
    newIdentNode("emitTupleType"),
    newEmptyNode(),
    newEmptyNode(),
    nnkFormalParams.newTree(
      newIdentNode("untyped"),
      nnkIdentDefs.newTree(
        newIdentNode("trait"),
        newIdentNode("typedesc"),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      newIdentNode("trait")
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Traitor"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("Traits"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkRefTy.newTree(
        nnkObjectTy.newTree(
          newEmptyNode(),
          nnkOfInherit.newTree(
            newIdentNode("RootObj")
          ),
          nnkRecList.newTree(
            nnkIdentDefs.newTree(
              newIdentNode("vtable"),
              nnkCall.newTree(
                newIdentNode("emitTupleType"),
                newIdentNode("Traits")
              ),
              newEmptyNode()
            )
          )
        )
      )
    )
  ),
  nnkTypeSection.newTree(
    nnkTypeDef.newTree(
      newIdentNode("Generic"),
      nnkGenericParams.newTree(
        nnkIdentDefs.newTree(
          newIdentNode("X"),
          newEmptyNode(),
          newEmptyNode()
        )
      ),
      nnkObjectTy.newTree(
        newEmptyNode(),
        newEmptyNode(),
        newEmptyNode()
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test2"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("Traits"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("Traits")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkStaticStmt.newTree(
        nnkStmtList.newTree(
          nnkCommand.newTree(
            newIdentNode("assert"),
            nnkInfix.newTree(
              newIdentNode("is"),
              nnkDotExpr.newTree(
                newIdentNode("val"),
                newIdentNode("vtable")
              ),
              newIdentNode("int")
            )
          )
        )
      )
    )
  ),
  nnkProcDef.newTree(
    newIdentNode("test"),
    newEmptyNode(),
    nnkGenericParams.newTree(
      nnkIdentDefs.newTree(
        newIdentNode("X"),
        newEmptyNode(),
        newEmptyNode()
      )
    ),
    nnkFormalParams.newTree(
      newEmptyNode(),
      nnkIdentDefs.newTree(
        newIdentNode("val"),
        nnkBracketExpr.newTree(
          newIdentNode("Traitor"),
          nnkBracketExpr.newTree(
            newIdentNode("Generic"),
            newIdentNode("X")
          )
        ),
        newEmptyNode()
      )
    ),
    newEmptyNode(),
    newEmptyNode(),
    nnkStmtList.newTree(
      nnkDiscardStmt.newTree(
        newEmptyNode()
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test2"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  ),
  nnkCommand.newTree(
    newIdentNode("test"),
    nnkCall.newTree(
      nnkBracketExpr.newTree(
        newIdentNode("Traitor"),
        nnkBracketExpr.newTree(
          newIdentNode("Generic"),
          newIdentNode("int")
        )
      )
    )
  )
)
Stats
  • GCC 11.4.0
  • Clang 14.0.0
  • NodeJS 19.0
  • Created 2024-02-06T07:37:47Z
  • 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

@metagn
Copy link
Collaborator

metagn commented Sep 18, 2024

Works now but val.vtable is Generic[int] not int unlike what the assert expects

metagn added a commit to metagn/Nim that referenced this issue Dec 8, 2024
@Araq Araq closed this as completed in aeb3fe9 Dec 9, 2024
narimiran pushed a commit that referenced this issue Jan 14, 2025
closes #6013, closes #7009, closes #9190, closes #12487, closes #12831,
closes #13184, closes #13252, closes #14860, closes #14877, closes
#14894, closes #14917, closes #16153, closes #16439, closes #17779,
closes #18074, closes #18202, closes #18314, closes #18648, closes
#19063, closes #19446, closes #20065, closes #20367, closes #22126,
closes #22820, closes #22888, closes #23020, closes #23287, closes
#23510

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

3 participants