Skip to content

Commit

Permalink
correct logic for qualified symbol in templates (#22577)
Browse files Browse the repository at this point in the history
* correct logic for qualified symbol in templates

fixes #19865

* add test
  • Loading branch information
metagn authored Aug 28, 2023
1 parent 94454ad commit 3de8d75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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])
Expand Down
4 changes: 4 additions & 0 deletions tests/template/template_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 3de8d75

Please sign in to comment.