summary refs log tree commit diff stats
path: root/tests/parser/ttupleunpack.nim
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2023-09-01 07:26:53 +0300
committerGitHub <noreply@github.com>2023-09-01 06:26:53 +0200
commitba158d73dc23fb6e61ebe88f6485f95c8dcb96c2 (patch)
treeb81216df57196946115e4219322b712ddefa5d79 /tests/parser/ttupleunpack.nim
parentb3912c25d3dcb78bc1c8f7d6acc3c512964d3ea8 (diff)
downloadNim-ba158d73dc23fb6e61ebe88f6485f95c8dcb96c2.tar.gz
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
Diffstat (limited to 'tests/parser/ttupleunpack.nim')
-rw-r--r--tests/parser/ttupleunpack.nim17
1 files changed, 17 insertions, 0 deletions
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")