Skip to content

Commit

Permalink
fix #13515 [backport] (#20315)
Browse files Browse the repository at this point in the history
(cherry picked from commit 58e6d43)
  • Loading branch information
metagn authored and narimiran committed Sep 19, 2022
1 parent ece219d commit e32de02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,14 @@ proc semTemplSymbol(c: PContext, n: PNode, s: PSym; isField: bool): PNode =
of skUnknown:
# Introduced in this pass! Leave it as an identifier.
result = n
of OverloadableSyms-{skEnumField}:
of OverloadableSyms-{skEnumField, skTemplate, skMacro}:
result = symChoice(c, n, s, scOpen, isField)
of skTemplate, skMacro:
result = symChoice(c, n, s, scOpen, isField)
if result.kind == nkSym:
# template/macro symbols might need to be semchecked again
# prepareOperand etc don't do this without setting the type to nil
result.typ = nil
of skGenericParam:
if isField and sfGenSym in s.flags: result = n
else: result = newSymNodeTypeDesc(s, c.idgen, n.info)
Expand Down
16 changes: 16 additions & 0 deletions tests/template/t13515.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
discard """
action: compile
"""

template test: bool = true

# compiles:
if not test:
echo "wtf"

# does not compile:
template x =
if not test:
echo "wtf"

x

0 comments on commit e32de02

Please sign in to comment.