Compiler crash when using seq[PNimrodNode] in macros #537

dom96 opened this Issue Jul 21, 2013 · 1 comment


None yet

3 participants

dom96 commented Jul 21, 2013

The following code:

import macros

proc test(): seq[PNimrodNode] {.compiletime.} =
  result = @[]
  result.add parseExpr("echo 56")
  result.add parseExpr("echo 123")
  result.add parseExpr("echo 56")

proc foo(): seq[PNimrodNode] {.compiletime.} =
  result = @[]
  #result.add test()
  result.add parseExpr("echo(5+56)")

macro bar(): stmt =
  result = newNimNode(nnkStmtList)
  result.add foo()
  echo treeRepr(result)


Crashes with

Traceback (most recent call last)
nimrod.nim(79)           nimrod
nimrod.nim(55)           HandleCmdLine
main.nim(296)            MainCommand
main.nim(72)             CommandCompileToC
modules.nim(193)         CompileProject
modules.nim(151)         compileModule
passes.nim(192)          processModule
passes.nim(136)          processTopLevelStmt
sem.nim(300)             myProcess
sem.nim(274)             SemStmtAndGenerateGenerics
semstmts.nim(1238)       semStmt
semexprs.nim(778)        semExprNoType
semexprs.nim(1943)       semExpr
semstmts.nim(1109)       semMacroDef
semstmts.nim(1023)       semProcAux
semexprs.nim(1157)       semProcBody
semexprs.nim(1923)       semExpr
semstmts.nim(1199)       semStmtList
semexprs.nim(1862)       semExpr
semexprs.nim(648)        semIndirectOp
semexprs.nim(1854)       semExpr
semexprs.nim(1462)       semMagic
semexprs.nim(738)        semDirectOp
semexprs.nim(722)        afterCallActions
semexprs.nim(437)        fixAbstractType
semexprs.nim(385)        arrayConstrType
system.nim(728)          skipTypes
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Perhaps I simply shouldn't use seq[PNimrodNode] and instead use a StmtList?


Currently, Win64 and Win32 builds on the devel branch do not crash when given the above code. Instead, the compiler throws the error "Error: expression '[(META|echo(5 + 56))]' has no type (or is ambiguous)"

I think this is because the echo() call is being put into a seq of nimrod nodes, which is being implicitly converted into a statement list, which must have a type.

@dom96 dom96 added the Semcheck label Aug 14, 2014
@Araq Araq added the Crash label Jun 1, 2016
@Araq Araq added a commit that closed this issue Jul 6, 2016
@Araq Araq fixes #537 e73fd64
@Araq Araq closed this in e73fd64 Jul 6, 2016
@Araq Araq added a commit that referenced this issue Jul 6, 2016
@Araq Araq added test case for #537 389f500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment