Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alternate fix + test for #12094, refs #13804 #20686

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ proc addToVarSection(c: PContext; result: var PNode; orig, identDefs: PNode) =
result.add identDefs

proc isDiscardUnderscore(v: PSym): bool =
# template generated underscore symbol name starts with _`gensym
if v.name.s == "_" or v.name.s.startsWith("_`"):
if v.name.s == "_":
v.flags.incl(sfGenSym)
result = true

Expand Down
2 changes: 1 addition & 1 deletion compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) =
closeScope(c)
let ident = getIdentNode(c, n)
if not isTemplParam(c, ident):
if n.kind != nkSym:
if n.kind != nkSym and not (n.kind == nkIdent and n.ident.s == "_"):
let local = newGenSym(k, ident, c)
addPrelimDecl(c.c, local)
styleCheckDef(c.c, n.info, local)
Expand Down
11 changes: 11 additions & 0 deletions tests/template/tunderscore1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
discard """
errormsg: "undeclared identifier: '_'"
"""

# issue #12094, #13804

template foo =
let _ = 1
echo _

foo()