Araq/Nimrod — Issue #101: Macro causes: internal error: mapType
Author: dom96
Created: 2012-02-22 22:45:18+00:00
State: open

Compiling the following code:

```nimrod
import macros

proc newNilNode*(): PNimrodNode =
## produces a new ``nil`` node.
result = newNimNode(nnkNilLit)

proc newStmtList*(statements: openArray[PNimrodNode]): PNimrodNode =
result = newNimNode(nnkProcDef)
result.add(statements)

proc newProc*(name: TNimrodIdent, params: openArray[TNimrodIdent],
body: PNimrodNode, returnVal: TNimrodIdent): PNimrodNode =
## produces a new procedure declaration, ``body`` should be a ``nnkStmtList``.
assert(body.kind == nnkStmtList)
result = newNimNode(nnkProcDef)
result.add(newIdentNode(name))
result.add(newNilNode())

result.add(newNimNode(nnkFormalParams))
result[2].add(newIdentNode(returnVal))
result[2].add(newNimNode(nnkIdentDefs))
for p in items(params):
result[2][1].add(p.newIdentNode)
result[2][1].add(newNilNode())

result.add(newNilNode())

result.add(body)

when isMainModule:
echo treeRepr(newProc(!"test", [!"x", !"y"], newStmtList(newCall(!"echo", newIdentNode(!"x"))), !"string"))

```

Causes the following error:

```
Error: internal error: mapType
Traceback (most recent call last)
nimrod.nim(104) nimrod
nimrod.nim(86) HandleCmdLine
main.nim(194) MainCommand
main.nim(111) CommandCompileToC
main.nim(84) CompileProject
main.nim(80) CompileModule
passes.nim(175) processModule
passes.nim(122) processTopLevelStmt
cgen.nim(958) myProcess
ccgstmts.nim(708) genStmts
ccgstmts.nim(721) genStmts
ccgexprs.nim(287) initLocExpr
ccgexprs.nim(1682) expr
ccgexprs.nim(1435) genMagicExpr
ccgexprs.nim(793) genEcho
ccgexprs.nim(287) initLocExpr
ccgexprs.nim(1684) expr
ccgcalls.nim(294) genCall
ccgcalls.nim(134) genPrefixCall
ccgcalls.nim(111) genArg
ccgexprs.nim(287) initLocExpr
ccgexprs.nim(1684) expr
ccgcalls.nim(294) genCall
ccgcalls.nim(125) genPrefixCall
ccgexprs.nim(287) initLocExpr
ccgexprs.nim(1641) expr
cgen.nim(711) genProc
cgen.nim(671) genProcNoForward
cgen.nim(662) genProcPrototype
ccgtypes.nim(552) genProcHeader
ccgtypes.nim(184) genProcParams
ccgtypes.nim(119) isInvalidReturnType
ccgtypes.nim(102) mapType
msgs.nim(667) InternalError
msgs.nim(613) rawMessage
msgs.nim(610) rawMessage
msgs.nim(565) handleError
system.nim(2177) raiseAssert
Error: unhandled exception: false [EAssertionFailed]
```