diff options
-rw-r--r-- | compiler/semgnrc.nim | 6 | ||||
-rw-r--r-- | lib/core/macros.nim | 2 | ||||
-rw-r--r-- | tests/template/mgensym_generic_cross_module.nim | 14 | ||||
-rw-r--r-- | tests/template/tgensym_generic_cross_module.nim | 14 |
4 files changed, 35 insertions, 1 deletions
diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index bc80c41ad..9c05ab2f9 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -174,7 +174,11 @@ proc semGenericStmt(c: PContext, n: PNode, # XXX for example: ``result.add`` -- ``add`` needs to be looked up here... var dummy: bool result = fuzzyLookup(c, n, flags, ctx, dummy) - of nkEmpty, nkSym..nkNilLit: + of nkSym: + let a = n.sym + let b = getGenSym(c, a) + if b != a: n.sym = b + of nkEmpty, succ(nkSym)..nkNilLit: # see tests/compile/tgensymgeneric.nim: # We need to open the gensym'ed symbol again so that the instantiation # creates a fresh copy; but this is wrong the very first reason for gensym diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 3adf4670d..83776f16b 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -742,6 +742,8 @@ proc `$`*(node: NimNode): string {.compileTime.} = result = $node.symbol of nnkOpenSymChoice, nnkClosedSymChoice: result = $node[0] + of nnkAccQuoted: + result = $node[0] else: badNodeKind node.kind, "$" diff --git a/tests/template/mgensym_generic_cross_module.nim b/tests/template/mgensym_generic_cross_module.nim new file mode 100644 index 000000000..80b681db4 --- /dev/null +++ b/tests/template/mgensym_generic_cross_module.nim @@ -0,0 +1,14 @@ + +template makeDomElement(x: untyped, name: string = nil) = + const tag {.gensym.} = if name == nil: astToStr(x) else: name + + proc x*(p: int|float) = + echo tag, p + + proc x*(p: string|cstring) = + echo tag, p + +#proc wrappedUp[T](x: T) = +# mixin foo, bar +makeDomElement(foo, "foo") +makeDomElement(bar) diff --git a/tests/template/tgensym_generic_cross_module.nim b/tests/template/tgensym_generic_cross_module.nim new file mode 100644 index 000000000..856ab676d --- /dev/null +++ b/tests/template/tgensym_generic_cross_module.nim @@ -0,0 +1,14 @@ +discard """ + output: '''foo55 +foo8.0 +fooaha +bar7''' +""" +# bug #5419 +import mgensym_generic_cross_module + +foo(55) +foo 8.0 +foo "aha" +bar 7 + |