From 465815e8945ec7619ba7c8ec494a8f8064a0aae2 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Sat, 6 Jul 2019 23:59:23 +0200 Subject: [PATCH] improved the error message for #11494; closes #11494 --- compiler/semstmts.nim | 4 ++-- tests/template/ttempl3.nim | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 9718331d08..430380944c 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -427,8 +427,8 @@ proc fillPartialObject(c: PContext; n: PNode; typ: PType) = proc setVarType(c: PContext; v: PSym, typ: PType) = if v.typ != nil and not sameTypeOrNil(v.typ, typ): localError(c.config, v.info, "inconsistent typing for reintroduced symbol '" & - v.name.s & "': previous type was: " & typeToString(v.typ) & - "; new type is: " & typeToString(typ)) + v.name.s & "': previous type was: " & typeToString(v.typ, preferDesc) & + "; new type is: " & typeToString(typ, preferDesc)) v.typ = typ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = diff --git a/tests/template/ttempl3.nim b/tests/template/ttempl3.nim index 9feaa0b7b6..17421cd879 100644 --- a/tests/template/ttempl3.nim +++ b/tests/template/ttempl3.nim @@ -60,3 +60,24 @@ template create(typ: typeDesc, arg: untyped): untyped = `init typ`(arg) var ff = Foo.create(12) echo ff.arg + + +import macros + +# bug #11494 +macro staticForEach(arr: untyped, body: untyped): untyped = + result = newNimNode(nnkStmtList) + arr.expectKind(nnkBracket) + for n in arr: + let b = copyNimTree(body) + result.add quote do: + block: + type it {.inject.} = `n` + `b` + +template forEveryMatchingEntity*() = + staticForEach([int, string, float]): + var a {.inject.}: it + echo a + +forEveryMatchingEntity()