Skip to content

template substitution leads to compiler crash (ident called on symbol node) #1619

@Luyten-Orion

Description

@Luyten-Orion

Specification

In a template, substitution takes priority when you have an object with a field name, and a parameter with a name, which makes sense, but the issue here is that it isn't reported correctly.

Example

type
  LogLevel* = enum
    llTrace

  LogData = object
    lvl: LogLevel

template log*(
  lvl: LogLevel,
) = LogData(lvl: lvl)

log(LogLevel.llTrace)

Actual Output

nim.nim                  nim
nim.nim                  handleCmdLine
main.nim                 mainCommand
main.nim                 compileToBackend
main.nim                 commandCompileToC
modules.nim              compileProject
modules.nim              compileModule
passes.nim               processModule
passes.nim               processTopLevelStmt
sem.nim                  myProcess
sem.nim                  semStmtAndGenerateGenerics nkStmtList 383994 /var/home/chronos/test/main.nim(12, 3)
semstmts.nim             semStmt
semexprs.nim             semExprNoType
semexprs.nim             semExpr nkStmtList 383994 /var/home/chronos/test/main.nim(12, 3)
semstmts.nim             semStmtList nkStmtList 383994 /var/home/chronos/test/main.nim(12, 3)
semexprs.nim             semExpr nkCall 383989 /var/home/chronos/test/main.nim(12, 3)
semexprs.nim             semDirectOp
semexprs.nim             afterCallActions
semexprs.nim             semTemplateExpr
sem.nim                  semAfterMacroCall nkStmtList 384003 /var/home/chronos/test/main.nim(12, 3)
semstmts.nim             semStmt
semexprs.nim             semExprNoType
semexprs.nim             semExpr nkStmtList 384003 /var/home/chronos/test/main.nim(12, 3)
semstmts.nim             semStmtList nkStmtList 384003 /var/home/chronos/test/main.nim(12, 3)
semexprs.nim             semExpr nkObjConstr 384004 /var/home/chronos/test/main.nim(12, 3)
semobjconstr.nim         semObjConstr
errorhandling.nim        newError nkSym 384007 /var/home/chronos/test/main.nim(12, 12)
msgs.nim                 emit
msgs.nim                 defaultDiagHandler
msgs.nim                 handleReport
options.nim              report
cli_reporter.nim         reportHook
cli_reporter.nim         reportFull
cli_reporter.nim         reportFull
cli_reporter.nim         reportBody
fatal.nim                sysFatal
Error: unhandled exception: field 'ident' is not accessible for type 'TNode' using 'kind = nkSym' [FieldDefect]

Expected Output

Two options:

  • Error: undeclared field: 'llTrace' for type main.LogData

Possible Solution

Additional Information

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler/semRelated to semantic-analysis system of the compiler

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions