diff options
Diffstat (limited to 'tests/tuples')
-rw-r--r-- | tests/tuples/t18125_1.nim | 14 | ||||
-rw-r--r-- | tests/tuples/t18125_2.nim | 20 | ||||
-rw-r--r-- | tests/tuples/ttuples_various.nim | 12 |
3 files changed, 46 insertions, 0 deletions
diff --git a/tests/tuples/t18125_1.nim b/tests/tuples/t18125_1.nim new file mode 100644 index 000000000..74fdfe8f5 --- /dev/null +++ b/tests/tuples/t18125_1.nim @@ -0,0 +1,14 @@ +# issue #18125 solved with type inference + +type + Parent = ref object of RootObj + + Child = ref object of Parent + c: char + +func foo(c: char): (Parent, int) = + # Works if you use (Parent(Child(c: c)), 0) + (Child(c: c), 0) + +let x = foo('x')[0] +doAssert Child(x).c == 'x' diff --git a/tests/tuples/t18125_2.nim b/tests/tuples/t18125_2.nim new file mode 100644 index 000000000..fe0a4a8bb --- /dev/null +++ b/tests/tuples/t18125_2.nim @@ -0,0 +1,20 @@ +discard """ + errormsg: "type mismatch: got <(Child, int)> but expected '(Parent, int)'" + line: 17 +""" + +# issue #18125 solved with correct type relation + +type + Parent = ref object of RootObj + + Child = ref object of Parent + c: char + +func foo(c: char): (Parent, int) = + # Works if you use (Parent(Child(c: c)), 0) + let x = (Child(c: c), 0) + x + +let x = foo('x')[0] +doAssert Child(x).c == 'x' diff --git a/tests/tuples/ttuples_various.nim b/tests/tuples/ttuples_various.nim index 97bc70bd2..e392731d2 100644 --- a/tests/tuples/ttuples_various.nim +++ b/tests/tuples/ttuples_various.nim @@ -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) |