Tuple unpacking now works for for vars (#10152)
* Tuple unpacking now works for `for` vars * Give error if length of tuple vars != length of tuple * Fix error message showing wrong tuple length * unpacking now works now for mutable items * Update changelog
This commit is contained in:
parent
e89aaaeaab
commit
9884129058
7 changed files with 156 additions and 45 deletions
39
tests/tuples/tfortupleunpack.nim
Normal file
39
tests/tuples/tfortupleunpack.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
discard """
|
||||
output: '''
|
||||
123
|
||||
113283
|
||||
0
|
||||
123
|
||||
1
|
||||
113283
|
||||
@[(88, 99, 11), (88, 99, 11)]
|
||||
@[(7, 6, -28), (7, 6, -28)]
|
||||
'''
|
||||
"""
|
||||
|
||||
let t1 = (1, 2, 3)
|
||||
let t2 = (11, 32, 83)
|
||||
let s = @[t1, t2]
|
||||
|
||||
for (a, b, c) in s:
|
||||
echo a, b, c
|
||||
|
||||
for i, (a, b, c) in s:
|
||||
echo i
|
||||
echo a, b, c
|
||||
|
||||
var x = @[(1,2,3), (4,5,6)]
|
||||
|
||||
for (a, b, c) in x.mitems:
|
||||
a = 88
|
||||
b = 99
|
||||
c = 11
|
||||
echo x
|
||||
|
||||
for i, (a, b, c) in x.mpairs:
|
||||
a = 7
|
||||
b = 6
|
||||
c = -28
|
||||
echo x
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue