From ba158d73dc23fb6e61ebe88f6485f95c8dcb96c2 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 1 Sep 2023 07:26:53 +0300 Subject: 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 --- tests/parser/ttupleunpack.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/parser/ttupleunpack.nim') diff --git a/tests/parser/ttupleunpack.nim b/tests/parser/ttupleunpack.nim index 860ef66cf..993501fbb 100644 --- a/tests/parser/ttupleunpack.nim +++ b/tests/parser/ttupleunpack.nim @@ -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") -- cgit 1.4.1-2-gfad0