diff options
-rw-r--r-- | compiler/semstmts.nim | 4 | ||||
-rw-r--r-- | tests/stmt/tforloop_tuple_multiple_underscore.nim | 10 | ||||
-rw-r--r-- | tests/stmt/tforloop_tuple_underscore.nim | 16 | ||||
-rw-r--r-- | tests/stmt/tforloop_underscore.nim | 6 |
4 files changed, 34 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index f83864775..cd7428b62 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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]) @@ -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) diff --git a/tests/stmt/tforloop_tuple_multiple_underscore.nim b/tests/stmt/tforloop_tuple_multiple_underscore.nim new file mode 100644 index 000000000..2afdb0b77 --- /dev/null +++ b/tests/stmt/tforloop_tuple_multiple_underscore.nim @@ -0,0 +1,10 @@ +discard """ + errormsg: "undeclared identifier: '_'" +""" + +iterator iter(): (int, int, int) = + yield (1, 1, 2) + + +for (_, i, _) in iter(): + echo _ \ No newline at end of file diff --git a/tests/stmt/tforloop_tuple_underscore.nim b/tests/stmt/tforloop_tuple_underscore.nim new file mode 100644 index 000000000..8cbb0fc10 --- /dev/null +++ b/tests/stmt/tforloop_tuple_underscore.nim @@ -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 _ + diff --git a/tests/stmt/tforloop_underscore.nim b/tests/stmt/tforloop_underscore.nim new file mode 100644 index 000000000..c5b49da77 --- /dev/null +++ b/tests/stmt/tforloop_underscore.nim @@ -0,0 +1,6 @@ +discard """ + errormsg: "undeclared identifier: '_'" +""" + +for _ in ["a"]: + echo _ |