Hi,
I receive untyped expression as the macro argument. Expression refers to
variables that are not currently scope, hence it is truly untyped expression.
However, in the macro I am generating a new let section which defines all
missing variables and makes expression valid and now I want to know
expression's type, however getType fails with 'Node has no type'
Btw, I managed to get a type of expression in the outer function, but I need it
in the macro, because there are still a lot to be generated in macro based on
the type of expression.
I want to do something like this:
macro exprInTuple(ctx : typed, expr : untyped) : typed =
let ctxType = ctx.getTypeImpl
if ctxType.typeKind != ntyTuple: error("Tuple is expected as first
argument")
var letSection = newNimNode(nnkLetSection)
for field in ctxType:
let dotExpr = newDotExpr(ctx, newIdentNode($field[0]))
letSection.add(newIdentDefs(ident($field[0]),
newEmptyNode(),newDotExpr))
result = newStmtList(letSection, expr)
getType(result) ## currently fails