mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-28 02:03:59 +00:00
type annotations for variable tuple unpacking, better error messages (#22611)
* type annotations for variable tuple unpacking, better error messages
closes #17989, closes https://github.com/nim-lang/RFCs/issues/339
* update grammar
* fix test
(cherry picked from commit ba158d73dc)
This commit is contained in:
@@ -75,3 +75,20 @@ block: # unary assignment unpacking
|
||||
var a: int
|
||||
(a,) = (1,)
|
||||
doAssert a == 1
|
||||
|
||||
block: # type annotations
|
||||
block: # basic
|
||||
let (a, b): (int, int) = (1, 2)
|
||||
doAssert (a, b) == (1, 2)
|
||||
block: # type inference
|
||||
let (a, b): (byte, float) = (1, 2)
|
||||
doAssert (a, b) == (1.byte, 2.0)
|
||||
block: # type mismatch
|
||||
doAssert not (compiles do:
|
||||
let (a, b): (int, string) = (1, 2))
|
||||
block: # nested
|
||||
let (a, (b, c)): (int, (int, int)) = (1, (2, 3))
|
||||
doAssert (a, b, c) == (1, 2, 3)
|
||||
block: # nested type inference
|
||||
let (a, (b, c)): (byte, (float, cstring)) = (1, (2, "abc"))
|
||||
doAssert (a, b, c) == (1.byte, 2.0, cstring"abc")
|
||||
|
||||
Reference in New Issue
Block a user