mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-16 08:04:20 +00:00
* fix #15972
* add testcase
* more
(cherry picked from commit 0869d2a477)
This commit is contained in:
@@ -738,7 +738,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])
|
||||
@@ -748,7 +748,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)
|
||||
|
||||
10
tests/stmt/tforloop_tuple_multiple_underscore.nim
Normal file
10
tests/stmt/tforloop_tuple_multiple_underscore.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
discard """
|
||||
errormsg: "undeclared identifier: '_'"
|
||||
"""
|
||||
|
||||
iterator iter(): (int, int, int) =
|
||||
yield (1, 1, 2)
|
||||
|
||||
|
||||
for (_, i, _) in iter():
|
||||
echo _
|
||||
16
tests/stmt/tforloop_tuple_underscore.nim
Normal file
16
tests/stmt/tforloop_tuple_underscore.nim
Normal file
@@ -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
tests/stmt/tforloop_underscore.nim
Normal file
6
tests/stmt/tforloop_underscore.nim
Normal file
@@ -0,0 +1,6 @@
|
||||
discard """
|
||||
errormsg: "undeclared identifier: '_'"
|
||||
"""
|
||||
|
||||
for _ in ["a"]:
|
||||
echo _
|
||||
Reference in New Issue
Block a user