diff options
author | metagn <metagngn@gmail.com> | 2023-08-28 22:40:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 21:40:46 +0200 |
commit | 3de8d755135d94983ca087f448ad76832c341eaa (patch) | |
tree | 68e1487bf8899a4631f123f1bffd7a1faaf18e52 | |
parent | 94454addb2a045731f2b4f44d697a319e3a20071 (diff) | |
download | Nim-3de8d755135d94983ca087f448ad76832c341eaa.tar.gz |
correct logic for qualified symbol in templates (#22577)
* correct logic for qualified symbol in templates fixes #19865 * add test
-rw-r--r-- | compiler/semtempl.nim | 5 | ||||
-rw-r--r-- | tests/template/template_issues.nim | 4 |
2 files changed, 8 insertions, 1 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 85411f7c4..eec028122 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -567,6 +567,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = # so we use the generic code for nkDotExpr too let s = qualifiedLookUp(c.c, n, {}) if s != nil: + # mirror the nkIdent case # do not symchoice a quoted template parameter (bug #2390): if s.owner == c.owner and s.kind == skParam and n.kind == nkAccQuoted and n.len == 1: @@ -578,7 +579,9 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = elif contains(c.toMixin, s.name.id): return symChoice(c.c, n, s, scForceOpen, c.noGenSym > 0) else: - return symChoice(c.c, n, s, scOpen, c.noGenSym > 0) + if s.kind in {skType, skVar, skLet, skConst}: + discard qualifiedLookUp(c.c, n, {checkAmbiguity, checkModule}) + return semTemplSymbol(c.c, n, s, c.noGenSym > 0) if n.kind == nkDotExpr: result = n result[0] = semTemplBody(c, n[0]) diff --git a/tests/template/template_issues.nim b/tests/template/template_issues.nim index 58c40941d..5b7c54ed6 100644 --- a/tests/template/template_issues.nim +++ b/tests/template/template_issues.nim @@ -302,3 +302,7 @@ block: # bug #21920 discard t[void]() # Error: expression has no type: discard + +block: # issue #19865 + template f() = discard default(system.int) + f() |