Implements #2154.
When unpacking tuples in var/let declarations a part of the tuple can now be discarded using a single underscore.
This commit is contained in:
parent
3751019823
commit
b38eb2e2a8
8 changed files with 39 additions and 6 deletions
18
tests/parser/ttupleunpack.nim
Normal file
18
tests/parser/ttupleunpack.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
discard """
|
||||
file: "ttupleunpack.nim"
|
||||
output: ""
|
||||
exitcode: 0
|
||||
"""
|
||||
proc foo(): tuple[x, y, z: int] =
|
||||
return (4, 2, 3)
|
||||
|
||||
var (x, _, y) = foo()
|
||||
doAssert x == 4
|
||||
doAssert y == 3
|
||||
|
||||
iterator bar(): tuple[x, y, z: int] =
|
||||
yield (1,2,3)
|
||||
|
||||
for x, y, _ in bar():
|
||||
doAssert x == 1
|
||||
doAssert y == 2
|
||||
Loading…
Add table
Add a link
Reference in a new issue