mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-01 17:41:17 +00:00
round out tuple unpacking assignment, support underscores (#22537)
* round out tuple unpacking assignment, support underscores
fixes #18710
* fix test messages
* use discard instead of continue
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
---------
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit 53d43e9671)
This commit is contained in:
@@ -39,13 +39,13 @@ var
|
||||
lresult
|
||||
lvalue
|
||||
lnext
|
||||
_
|
||||
tmpTupleAsgn
|
||||
lresult = @[123]
|
||||
_ = (
|
||||
tmpTupleAsgn = (
|
||||
let blitTmp = lresult
|
||||
blitTmp, ";")
|
||||
lvalue = _[0]
|
||||
lnext = _[1]
|
||||
lvalue = tmpTupleAsgn[0]
|
||||
lnext = tmpTupleAsgn[1]
|
||||
`=sink`(result.value, move lvalue)
|
||||
`=destroy`(lnext)
|
||||
`=destroy_1`(lvalue)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
var a, b = 0
|
||||
(a, b) = 1 #[tt.Error
|
||||
^ type mismatch: got <int literal(1)> but expected 'tuple']#
|
||||
^ 'tuple' expected]#
|
||||
|
||||
@@ -197,3 +197,15 @@ block: # bug #22054
|
||||
|
||||
var v = A(field: (a: 1314))
|
||||
doAssert get(v)[0] == 1314
|
||||
|
||||
block: # tuple unpacking assignment with underscore
|
||||
var
|
||||
a = 1
|
||||
b = 2
|
||||
doAssert (a, b) == (1, 2)
|
||||
(a, _) = (3, 4)
|
||||
doAssert (a, b) == (3, 2)
|
||||
(_, a) = (5, 6)
|
||||
doAssert (a, b) == (6, 2)
|
||||
(b, _) = (7, 8)
|
||||
doAssert (a, b) == (6, 7)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
discard """
|
||||
errormsg: "invalid type: 'empty' in this context: '(seq[empty], (seq[empty], set[empty]))' for let"
|
||||
errormsg: "cannot infer the type of the tuple"
|
||||
file: "tassignemptytuple.nim"
|
||||
line: 11
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user