Skip to content

Commit

Permalink
fix #15972 (#15994)
Browse files Browse the repository at this point in the history
* fix #15972

* add testcase

* more
  • Loading branch information
ringabout authored Nov 18, 2020
1 parent 632af8a commit 0869d2a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
else:
v.typ = iter[i]
n[0][i] = newSymNode(v)
if sfGenSym notin v.flags: addDecl(c, v)
if sfGenSym notin v.flags and not isDiscardUnderscore(v): addDecl(c, v)
elif v.owner == nil: v.owner = getCurrOwner(c)
else:
var v = symForVar(c, n[0])
Expand All @@ -749,7 +749,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
# for an example:
v.typ = iterBase
n[0] = newSymNode(v)
if sfGenSym notin v.flags: addDecl(c, v)
if sfGenSym notin v.flags and not isDiscardUnderscore(v): addDecl(c, v)
elif v.owner == nil: v.owner = getCurrOwner(c)
else:
localError(c.config, n.info, errWrongNumberOfVariables)
Expand Down
10 changes: 10 additions & 0 deletions tests/stmt/tforloop_tuple_multiple_underscore.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
discard """
errormsg: "undeclared identifier: '_'"
"""

iterator iter(): (int, int, int) =
yield (1, 1, 2)


for (_, i, _) in iter():
echo _
16 changes: 16 additions & 0 deletions tests/stmt/tforloop_tuple_underscore.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
discard """
errormsg: "undeclared identifier: '_'"
"""

iterator iter(): (int, int) =
yield (1, 2)
yield (3, 4)
yield (1, 2)
yield (3, 4)
yield (1, 2)
yield (3, 4)


for (_, i) in iter():
echo _

6 changes: 6 additions & 0 deletions tests/stmt/tforloop_underscore.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
discard """
errormsg: "undeclared identifier: '_'"
"""

for _ in ["a"]:
echo _

0 comments on commit 0869d2a

Please sign in to comment.