From 238efc025e0d20b85328afc61f1cdc53fbba9d53 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 21 Jun 2023 22:30:55 +0800 Subject: [PATCH] fixes #21231; template with module as parameter elides usage/checking of module name specifier (#22109) * fixes #21231; template with module as parameter elides usage/checking of module name specifier * add a test case (cherry picked from commit ac7b8b678c9e8eff70bb8147d411664470a882fd) --- compiler/lookups.nim | 3 +++ tests/template/t21231.nim | 10 ++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/template/t21231.nim diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 9e6da157d6..1ddeeade26 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -604,6 +604,9 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym = result = errorUndeclaredIdentifierHint(c, n[1], ident) elif n[1].kind == nkSym: result = n[1].sym + if result.owner != nil and result.owner != m and checkUndeclared in flags: + # dotExpr in templates can end up here + result = errorUndeclaredIdentifierHint(c, n[1], considerQuotedIdent(c, n[1])) elif checkUndeclared in flags and n[1].kind notin {nkOpenSymChoice, nkClosedSymChoice}: localError(c.config, n[1].info, "identifier expected, but got: " & diff --git a/tests/template/t21231.nim b/tests/template/t21231.nim new file mode 100644 index 0000000000..51e96cdd65 --- /dev/null +++ b/tests/template/t21231.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "undeclared identifier: 'x'" +""" + +var x: int +# bug #21231 +template f(y: untyped) = echo y.x +for i in 1 .. 10: + x = i + f(system)