diff --git a/test/fail/eq00.v3 b/test/fail/eq00.v3 new file mode 100644 index 000000000..5ab3629b7 --- /dev/null +++ b/test/fail/eq00.v3 @@ -0,0 +1,18 @@ +//@execute =35 + +type U { + case A(x: int); + case B(y: int); +} + +def f() -> (U, U) { + return (U.A(12), U.B(23)); +} + +def main() -> int { + var a = f(); + var b = f(); + + if (a != b) return -1; + return U.A.!(a.0).x + U.B.!(a.1).y; +} \ No newline at end of file diff --git a/test/gc/variants.gc b/test/gc/variants.gc index 5c3ff0633..2827b163b 100644 --- a/test/gc/variants.gc +++ b/test/gc/variants.gc @@ -239,7 +239,7 @@ ../variants/unboxed01.v3 ../variants/unboxed02.v3 ../variants/unboxed03.v3 -../variants/unboxed_mixed_array00.v3 +../variants/ub_mixed_array00.v3 ../variants/v01.v3 ../variants/v13.v3 ../variants/v14.v3 diff --git a/test/variants/ub_array03.v3 b/test/variants/ub_array03.v3 new file mode 100644 index 000000000..1e6235579 --- /dev/null +++ b/test/variants/ub_array03.v3 @@ -0,0 +1,8 @@ +//@execute 0=-11; 1=-51111 +type U(x: int, y: int, z: int) #unboxed { } +def x = [U(11, 22, 44), U(3333, 1111, 55555)]; + +def main(a: int) -> int { + var u = x[a]; + return u.x + u.y - u.z; +} diff --git a/test/variants/ub_cast00.v3 b/test/variants/ub_cast00.v3 new file mode 100644 index 000000000..1a0701633 --- /dev/null +++ b/test/variants/ub_cast00.v3 @@ -0,0 +1,30 @@ +//@execute 0=12;1=78;2=123 +type A00 #unboxed { + case X(x: i32, y: i64, z: i32); + case Y(x: i32, y: i32); + case Z(y: i32); +} + +def x = A00.!(A00.X(12, 34, 56)); +def y = A00.!(A00.Y(78, 90)); +def z = A00.!(A00.Z(123)); + +def f(a: int) -> A00 { + match (a) { + 0 => return x; + 1 => return y; + 2 => return z; + } + return A00.Z(123); +} + +def main(a: int) -> int { + if (f(a) != f(a)) return -1; + + match (a) { + 0 => return A00.X.!(f(a)).x; + 1 => return A00.Y.!(f(a)).x; + 2 => return A00.Z.!(f(a)).y; + } + return 0; +} \ No newline at end of file diff --git a/test/variants/ub_cell00.v3 b/test/variants/ub_cell00.v3 new file mode 100644 index 000000000..0c5e24d11 --- /dev/null +++ b/test/variants/ub_cell00.v3 @@ -0,0 +1,30 @@ +//@execute 0=100; 1=101 +type MutCell #unboxed { + case Array(x: Array, i: int) { } + case Func(getf: void -> T, setf: T -> void) { } + + def get() -> T { + match (this) { + Array(x, i) => return x[i]; + Func(getf, setf) => return getf(); + } + } + def set(v: T) { + match (this) { + Array(x, i) => x[i] = v; + Func(getf, setf) => return setf(v); + } + } +} +var y = 99; +def get_y() -> int { return y; } +def set_y(v: int) { y = v; } +def cells = [ + MutCell.Array([0], 0), + MutCell.Func(get_y, set_y) +]; +def main(a: int) -> int { + var cell = cells[a]; + cell.set(a + 100); + return cell.get(); +} \ No newline at end of file diff --git a/test/variants/ub_cell01.v3 b/test/variants/ub_cell01.v3 new file mode 100644 index 000000000..f3a0ae94c --- /dev/null +++ b/test/variants/ub_cell01.v3 @@ -0,0 +1,21 @@ +//@execute 0=123; 1=-1 +type Cell #unboxed { + case Array(x: Array); + case Empty; + + def get() -> int { + match (this) { + Array(x) => return x[0]; + Empty => return -1; + } + } +} +def cells = [ + Cell.Array([123]), + Cell.Empty +]; + +def main(a: int) -> int { + var cell = cells[a]; + return cell.get(); +} \ No newline at end of file diff --git a/test/variants/ub_cell02.v3 b/test/variants/ub_cell02.v3 new file mode 100644 index 000000000..919058a03 --- /dev/null +++ b/test/variants/ub_cell02.v3 @@ -0,0 +1,17 @@ +//@execute 0=123 +type Cell #unboxed { + case Array(x: int); + case Empty; + + def get() -> int { + match (this) { + Array(x) => return x; + Empty => return -1; + } + } +} + +def main(a: int) -> int { + def cell = Cell.Array(123); + return cell.get(); +} \ No newline at end of file diff --git a/test/variants/ub_cell03.v3 b/test/variants/ub_cell03.v3 new file mode 100644 index 000000000..4e30bde12 --- /dev/null +++ b/test/variants/ub_cell03.v3 @@ -0,0 +1,22 @@ +//@execute 0=123 +type Cell #unboxed { + case Array(x: Array); + case Empty; +} + +def get(c: Cell) -> int { + match (c) { + Array(x) => return x[0]; + Empty => return -1; + } +} + +def cells = [ + Cell.Array([123]), + Cell.Empty +]; + +def main(a: int) -> int { + var cell = cells[a]; + return get(cell); +} \ No newline at end of file diff --git a/test/variants/ub_eq00.v3 b/test/variants/ub_eq00.v3 new file mode 100644 index 000000000..6d8811cfa --- /dev/null +++ b/test/variants/ub_eq00.v3 @@ -0,0 +1,23 @@ +//@execute 0=true;1=false;2=true;3=false +type A00 #unboxed { + case X; + case Y(x: int); +} + +def eq = A00.==; + +def main(a: int) -> bool { + var a00_x: A00 = A00.X; + var a00_x2: A00 = A00.X; + var a00_y: A00 = A00.Y(12); + var a00_y2: A00 = A00.Y(12); + var a00_y3: A00 = A00.Y(13); + + match (a) { + 0 => return eq(a00_x, a00_x2); + 1 => return eq(a00_x, a00_y); + 2 => return eq(a00_y, a00_y2); + 3 => return eq(a00_y, a00_y3); + } + return false; +} diff --git a/test/variants/ub_eq01.v3 b/test/variants/ub_eq01.v3 new file mode 100644 index 000000000..34cef518d --- /dev/null +++ b/test/variants/ub_eq01.v3 @@ -0,0 +1,27 @@ +//@execute =0 +type A00 #unboxed { + case X; + case Y(x: int); +} + +def eq(a: A00, b: A00) -> bool { + return a == b; +} + +def f() -> A00 { + return A00.X; +} + +def main() -> int { + var x: A00 = A00.X; + if (!eq(x, A00.X)) return -1; + + x = A00.Y(12); + if (eq(x, A00.X)) return -2; + if (!eq(x, A00.Y(12))) return -3; + + x = f(); + if (!eq(x, A00.X)) return -4; + + return 0; +} diff --git a/test/variants/ub_eq03.v3 b/test/variants/ub_eq03.v3 new file mode 100644 index 000000000..ed5a621f1 --- /dev/null +++ b/test/variants/ub_eq03.v3 @@ -0,0 +1,14 @@ +//@execute 0=true +type A00 #unboxed { + case X(x: i32, y: i64, z: i32); + case Y(x: i32, y: i32); + case Z(y: i64); +} + +def arr = [A00.X(12, 34, 56), A00.Y(12, 34), A00.Z(12)]; + +def main(a: int) -> bool { + if (arr[0] != arr[0]) return false; + + return true; +} \ No newline at end of file diff --git a/test/variants/ub_eq04.v3 b/test/variants/ub_eq04.v3 new file mode 100644 index 000000000..6224f9a3f --- /dev/null +++ b/test/variants/ub_eq04.v3 @@ -0,0 +1,17 @@ +//@execute 0=true;1=false;2=true;3=false;4=true;5=false +type A #unboxed { + case X(b: B); + case Y; +} + +type B { + case X(x: int); + case Y(y: int); +} + +def arr1 = [A.X(B.X(12)), A.X(B.X(12)), A.X(B.Y(34)), A.X(B.Y(56)), A.Y, A.Y]; +def arr2 = [A.X(B.X(12)), A.X(B.X(34)), A.X(B.Y(34)), A.Y, A.Y, A.X(B.X(7))]; + +def main(a: int) -> bool { + return arr1[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_eq05.v3 b/test/variants/ub_eq05.v3 new file mode 100644 index 000000000..c7135896f --- /dev/null +++ b/test/variants/ub_eq05.v3 @@ -0,0 +1,17 @@ +//@execute 0=true;1=false;2=true;3=false;4=true;5=false +type A { + case X(b: B); + case Y(y: int) #unboxed; +} + +type B { + case X(x: int); + case Y(y: int); +} + +def arr1 = [A.X(B.X(12)), A.X(B.X(12)), A.X(B.Y(34)), A.X(B.Y(56)), A.Y(99), A.Y(99)]; +def arr2 = [A.X(B.X(12)), A.X(B.X(34)), A.X(B.Y(34)), A.Y(99), A.Y(99), A.X(B.X(7))]; + +def main(a: int) -> bool { + return arr1[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_eq06.v3 b/test/variants/ub_eq06.v3 new file mode 100644 index 000000000..52cedbf22 --- /dev/null +++ b/test/variants/ub_eq06.v3 @@ -0,0 +1,15 @@ +//@execute 0=true;1=true;2=true;3=true;4=true;5=true +type T { + case A(x: int); + case B(y: int); + case C(a: Array) #unboxed; +} + +def a: Array = []; +def b: Array = [1, 2]; +def arr1 = [T.A(0), T.A(10), T.B(20), T.B(30), T.C(a), T.C(b)]; +def arr2 = [T.A(0), T.A(10), T.B(20), T.B(30), T.C(a), T.C(b)]; + +def main(a: int) -> bool { + return arr1[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_eq07.v3 b/test/variants/ub_eq07.v3 new file mode 100644 index 000000000..63ad12a8d --- /dev/null +++ b/test/variants/ub_eq07.v3 @@ -0,0 +1,15 @@ +//@execute 0=false;1=false;2=false;3=false;4=false;5=false +type T { + case A(x: int); + case B(y: int); + case C(a: Array) #unboxed; +} + +def a: Array = []; +def b: Array = [1, 2]; +def arr1 = [T.A(0), T.A(10), T.B(20), T.B(30), T.C(a), T.C(b)]; +def arr2 = [T.B(20), T.B(30), T.C(a), T.C(b), T.A(0), T.A(10)]; + +def main(a: int) -> bool { + return arr1[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_fun00.v3 b/test/variants/ub_fun00.v3 new file mode 100644 index 000000000..ee9878689 --- /dev/null +++ b/test/variants/ub_fun00.v3 @@ -0,0 +1,22 @@ +//@execute 0=123;1=456 +type A00 #unboxed { + case X { + def val() -> i32 { return 123; } + } + case Y(a: i32) { + def val() -> i32 { return a; } + } + + def val() -> i32; +} + +def main(a: int) -> int { + var a00_x: A00 = A00.X; + var a00_y: A00 = A00.Y(456); + + match (a) { + 0 => return a00_x.val(); + 1 => return a00_y.val(); + _ => return 0; + } +} \ No newline at end of file diff --git a/test/variants/ub_fun01.v3 b/test/variants/ub_fun01.v3 new file mode 100644 index 000000000..ff499bfb5 --- /dev/null +++ b/test/variants/ub_fun01.v3 @@ -0,0 +1,12 @@ +//@execute =35 +type A00(x: int, y: int) #unboxed { + def f() -> int { + return x + y; + } +} + +def main() -> i32 { + var x = A00(12, 23); + + return x.f(); +} \ No newline at end of file diff --git a/test/variants/ub_fun02.v3 b/test/variants/ub_fun02.v3 new file mode 100644 index 000000000..ae3a2e6f5 --- /dev/null +++ b/test/variants/ub_fun02.v3 @@ -0,0 +1,29 @@ +//@execute 0=123;1=456;2=789;3=345;4=-456 +type A00 #unboxed { + case X { + def val() -> i32 { return 123; } + def f() -> i32 { return 345; } + def g() -> i32 { return 789; } + } + case Y(a: i32) { + def val() -> i32 { return a; } + def f() -> i32 { return -a; } + } + + def val() -> i32; + def f() -> i32; +} + +def main(a: int) -> i32 { + var a00_x: A00 = A00.X; + var a00_y: A00 = A00.Y(456); + + match (a) { + 0 => return a00_x.val(); + 1 => return a00_y.val(); + 2 => return A00.X.!(a00_x).g(); + 3 => return a00_x.f(); + 4 => return a00_y.f(); + _ => return 0; + } +} \ No newline at end of file diff --git a/test/variants/ub_fun03.v3 b/test/variants/ub_fun03.v3 new file mode 100644 index 000000000..9178946f8 --- /dev/null +++ b/test/variants/ub_fun03.v3 @@ -0,0 +1,31 @@ +//@execute 0=0;1=10;2=50;3=1;4=34 + +type A00 #unboxed { + case X; + case Y(x: int); + case Z(x: int, y: int); + case W(x: Array); + case V(x: Array, y: int); + + def f() -> int { + match (this) { + X => return 0; + Y(x) => return x; + Z(x, y) => return x + y; + W(x) => return x[0]; + V(x, y) => return x[y]; + } + } +} + +def vals = [ + A00.X, + A00.Y(10), + A00.Z(20, 30), + A00.W([1, 2, 3]), + A00.V([12, 23, 34], 2) +]; + +def main(a: int) -> int { + return vals[a].f(); +} \ No newline at end of file diff --git a/test/variants/ub_fun04.v3 b/test/variants/ub_fun04.v3 new file mode 100644 index 000000000..e29e164b8 --- /dev/null +++ b/test/variants/ub_fun04.v3 @@ -0,0 +1,16 @@ +//@execute 0=102;1=!TypeCheckException +type A00 #unboxed { + case X(x: i32, y: i64, z: i32); + case Y(x: i32, y: i32); + case Z(y: i64); +} + +def f(a: A00.X) -> int { + return int.!(a.x + a.y + a.z); +} + +def arr = [A00.X(12, 34, 56), A00.Y(12, 34), A00.Z(12)]; + +def main(a: int) -> int { + return f(A00.X.!(arr[a])); +} \ No newline at end of file diff --git a/test/variants/ub_merge00.v3 b/test/variants/ub_merge00.v3 new file mode 100644 index 000000000..387c0cb56 --- /dev/null +++ b/test/variants/ub_merge00.v3 @@ -0,0 +1,23 @@ +//@execute =3 +type A00 #unboxed { + case X(a: u64); + case Y(b: u32); +} + +def f(a: A00) -> u64 { + return A00.X.!(a).a; +} + +def g(a: A00) -> u32 { + return A00.Y.!(a).b; +} + +def main() -> u32 { + var a00_x = A00.X(0xFFFFFFFF00000000ul); + var a00_y = A00.Y(11); + + if (f(a00_x) != 0xFFFFFFFF00000000ul) return 1; + if (g(a00_y) != 11) return 2; + + return 3; +} \ No newline at end of file diff --git a/test/variants/ub_merge01.v3 b/test/variants/ub_merge01.v3 new file mode 100644 index 000000000..f5052b7ed --- /dev/null +++ b/test/variants/ub_merge01.v3 @@ -0,0 +1,25 @@ +//@execute 0=12;1=34;2=56 +class A(x: int) { } + +class B extends A { + def y: int; + + new(x: int, y) super(x) { } +} + +type C #unboxed { + case X(a: A); + case Y(b: B); +} + +def main(a: int) -> int { + var x = C.X(A.new(12)); + var y = C.Y(B.new(34, 56)); + + match (a) { + 0 => return x.a.x; + 1 => return y.b.x; + 2 => return y.b.y; + _ => return 0; + } +} \ No newline at end of file diff --git a/test/variants/ub_merge02.v3 b/test/variants/ub_merge02.v3 new file mode 100644 index 000000000..89fd4ff94 --- /dev/null +++ b/test/variants/ub_merge02.v3 @@ -0,0 +1,24 @@ +//@execute =712 +type A0 #unboxed { + case X(a: Array); + case Y(b: Array); +} + +def f(a0: A0) -> int { + match (a0) { + X(a) => return a[0] + 123; + Y(b) => return b.length + 456; + } +} + +def values = [ + A0.X([7, 8, 9]), + A0.Y([true, false]), + A0.X([1, 2, 3]) +]; + +def main() -> int { + var sum = 0; + for (value in values) sum += f(value); + return sum; +} \ No newline at end of file diff --git a/test/variants/ub_meth00.v3 b/test/variants/ub_meth00.v3 new file mode 100644 index 000000000..faa2a3415 --- /dev/null +++ b/test/variants/ub_meth00.v3 @@ -0,0 +1,13 @@ +//@execute 0=0; 1=33; 2=444; 3=555; 4=!BoundsCheckException +type X #unboxed { + case A(v: int) { def m() -> int { return v; } } + case B(v: long) { def m() -> int { return int.view(v); } } + + def m() -> int; +} + +var vals = [X.A(0), X.A(33), X.B(444L), X.B(555L)]; + +def main(a: int) -> int { + return vals[a].m(); +} diff --git a/test/variants/ub_meth01.v3 b/test/variants/ub_meth01.v3 new file mode 100644 index 000000000..0e47c33d4 --- /dev/null +++ b/test/variants/ub_meth01.v3 @@ -0,0 +1,13 @@ +//@execute 0=0; 1=36; 2=447; 3=559; 4=!BoundsCheckException +type X { + case A(v: int) #unboxed { def m() -> int { return v; } } + case B(v: long) { def m() -> int { return int.view(v); } } + + def m() -> int; +} + +var vals = [X.A(0), X.A(36), X.B(447L), X.B(559L)]; + +def main(a: int) -> int { + return vals[a].m(); +} diff --git a/test/variants/ub_meth02.v3 b/test/variants/ub_meth02.v3 new file mode 100644 index 000000000..79e82aef6 --- /dev/null +++ b/test/variants/ub_meth02.v3 @@ -0,0 +1,13 @@ +//@execute 0=0; 1=36; 2=447; 3=559; 4=!BoundsCheckException +type X { + case A(v: int) { def m() -> int { return v; } } + case B(v: long) #unboxed { def m() -> int { return int.view(v); } } + + def m() -> int; +} + +var vals = [X.A(0), X.A(36), X.B(447L), X.B(559L)]; + +def main(a: int) -> int { + return vals[a].m(); +} diff --git a/test/variants/ub_meth03.v3 b/test/variants/ub_meth03.v3 new file mode 100644 index 000000000..1626730bc --- /dev/null +++ b/test/variants/ub_meth03.v3 @@ -0,0 +1,14 @@ +//@execute 0=0; 1=36; 2=447; 3=559; 4=!BoundsCheckException +type X { + case A(v: int) { def m() -> int { return v; } } + case B(v: long) #unboxed { def m() -> int { return int.view(v); } } + + def m() -> int; +} + +var d: X.A; +var vals = [d, X.A(36), X.B(447L), X.B(559L)]; + +def main(a: int) -> int { + return vals[a].m(); +} diff --git a/test/variants/ub_meth04.v3 b/test/variants/ub_meth04.v3 new file mode 100644 index 000000000..9311a4e26 --- /dev/null +++ b/test/variants/ub_meth04.v3 @@ -0,0 +1,15 @@ +//@execute 0=0; 1=36; 2=447; 3=559; 4=0; 5=!BoundsCheckException +type X { + case A(v: int) { def m() -> int { return v; } } + case B(v: long) #unboxed { def m() -> int { return int.view(v); } } + + def m() -> int; +} + +var d: X.A; +var e: X.B; +var vals = [d, X.A(36), X.B(447L), X.B(559L), e]; + +def main(a: int) -> int { + return vals[a].m(); +} diff --git a/test/variants/ub_meth05.v3 b/test/variants/ub_meth05.v3 new file mode 100644 index 000000000..55cf15eb5 --- /dev/null +++ b/test/variants/ub_meth05.v3 @@ -0,0 +1,26 @@ +//@execute 0=10;1=22;2=22;3=68;4=68 +type A00 { + case X(x: int) { + def f() -> int { + return x + 10; + } + } + case Y(x: int) #unboxed { + def f() -> int { + return x * 2; + } + } + + def f() -> int; +} + +var a00_null: A00; +var a00_x: A00 = A00.X(12); +var a00_x1: A00.X = A00.X(12); +var a00_y: A00 = A00.Y(34); +var a00_y1: A00.Y = A00.Y(34); +def arr = [a00_null, a00_x, a00_x1, a00_y, a00_y1]; + +def main(a: int) -> int { + return arr[a].f(); +} \ No newline at end of file diff --git a/test/variants/ub_mixed00.v3 b/test/variants/ub_mixed00.v3 new file mode 100644 index 000000000..e722ba50f --- /dev/null +++ b/test/variants/ub_mixed00.v3 @@ -0,0 +1,19 @@ +//@execute =33 +type A00 { + case X(x: int); + case Y(x: int) #unboxed; +} + +def f(a: A00) -> int { + match (a) { + X(x) => return x; + Y(x) => return x; + } +} + +def main() -> int { + var a00_x = A00.X(22); + var a00_y = A00.Y(11); + + return f(a00_x) + f(a00_y); +} \ No newline at end of file diff --git a/test/variants/ub_mixed01.v3 b/test/variants/ub_mixed01.v3 new file mode 100644 index 000000000..6d4abea21 --- /dev/null +++ b/test/variants/ub_mixed01.v3 @@ -0,0 +1,18 @@ +//@execute =22 +type A00 { + case X #unboxed; + case Y(x: int); +} + +def f(a: A00) -> int { + match (a) { + X => return 0; + Y(x) => return x; + } +} + +def main() -> int { + var a00_y = A00.Y(22); + + return f(a00_y); +} \ No newline at end of file diff --git a/test/variants/ub_mixed02.v3 b/test/variants/ub_mixed02.v3 new file mode 100644 index 000000000..efee0cd03 --- /dev/null +++ b/test/variants/ub_mixed02.v3 @@ -0,0 +1,23 @@ +//@execute 0=0;1=10 +type Option { + case None; + case Some(val: T) #unboxed; +} + +def f(x: Option) -> int { + match (x) { + None => return 0; + Some(val) => return val; + } +} + +def main(a: int) -> int { + var n = Option.None; + var s = Option.Some(10); + + match (a) { + 0 => return f(n); + 1 => return f(s); + _ => return 0; + } +} \ No newline at end of file diff --git a/test/variants/ub_mixed03.v3 b/test/variants/ub_mixed03.v3 new file mode 100644 index 000000000..455365e71 --- /dev/null +++ b/test/variants/ub_mixed03.v3 @@ -0,0 +1,43 @@ +//@execute =110 +type A00 { + case X #unboxed; + case Y(x: int); +} + +type A01 { + case X; + case Y(x: int) #unboxed; +} + +type A02 { + case X #unboxed; + case Y(x: int) #unboxed; +} + +type A03 { + case X #unboxed; + case Y(x: int) #unboxed; +} + +def main() -> int { + var a00_x = A00.X; + var a00_y = A00.Y(11); + + var a01_x = A01.X; + var a01_y = A01.Y(22); + + var a02_x = A02.X; + var a02_y = A02.Y(33); + + var a03_x = A03.X; + var a03_y = A03.Y(44); + + // Prevent fields from getting eliminated + var sum = 0; + match (a00_y) { Y(x) => sum += x; _ => ; } + match (a01_y) { Y(x) => sum += x; _ => ; } + match (a02_y) { Y(x) => sum += x; _ => ; } + match (a03_y) { Y(x) => sum += x; _ => ; } + + return sum; +} \ No newline at end of file diff --git a/test/variants/ub_mixed04.v3 b/test/variants/ub_mixed04.v3 new file mode 100644 index 000000000..9a76db514 --- /dev/null +++ b/test/variants/ub_mixed04.v3 @@ -0,0 +1,16 @@ +//@execute 0=99;1=20;2=123;3=46 +type A00 { + case X(x: u32) #unboxed; + case Y(x: u32, y: u32); +} + +def arr = [A00.X(99), A00.Y(11, 9), A00.X(123), A00.Y(12, 34)]; + +def main(a: int) -> u32 { + var val: A00 = arr[a]; + + match (val) { + X(x) => return x; + Y(x, y) => return x + y; + } +} \ No newline at end of file diff --git a/test/variants/ub_mixed05.v3 b/test/variants/ub_mixed05.v3 new file mode 100644 index 000000000..20eb063fb --- /dev/null +++ b/test/variants/ub_mixed05.v3 @@ -0,0 +1,18 @@ +//@execute =-10 +type A00 { + case X #unboxed; + case Y(x: (int, int), y: int); +} + +def f(a: A00) -> int { + match (a) { + X => return 0; + Y(ab, c) => return ab.0 + ab.1 - c; + } +} + +def main() -> int { + var a00_y = A00.Y((12, 34), 56); + + return f(a00_y); +} \ No newline at end of file diff --git a/test/variants/ub_mixed06.v3 b/test/variants/ub_mixed06.v3 new file mode 100644 index 000000000..5bd433df0 --- /dev/null +++ b/test/variants/ub_mixed06.v3 @@ -0,0 +1,30 @@ +//@execute 0=5;1=26;2=57;3=48 +type A00 { + case X(x: int) #unboxed; + case Y(x: int, y: int) #unboxed; + case Z(x: int, y: int); + case W(x: int); +} + +def f(a: A00) -> int { + match (a) { + X(x) => return x; + Y(x, y) => return 2 * (x + y); + Z(x, y) => return 3 * (x + y); + W(x) => return 4 * x; + } +} + +def g(a: int, b: int) -> A00 { + match (a) { + 0 => return A00.X(b); + 1 => return A00.Y(b, b + 1); + 2 => return A00.Z(b + 2, b + 3); + 3 => return A00.W(b + 4); + _ => return A00.X(0); + } +} + +def main(a: int) -> int { + return f(g(a, a + 5)); +} \ No newline at end of file diff --git a/test/variants/ub_mixed07.v3 b/test/variants/ub_mixed07.v3 new file mode 100644 index 000000000..c61925f50 --- /dev/null +++ b/test/variants/ub_mixed07.v3 @@ -0,0 +1,27 @@ +//@execute =0 +type Either { + case Left(val: T) #unboxed; + case Right(val: U); +} + +def f(a: Either) -> int { + match (a) { + Left(val) => return 1; + Right(val) => return 2; + } +} + +def main() -> int { + var a = Either.Left(12); + var b = Either.Right(false); + + var c = Either.Left(123ul); + var d = Either.Right(123); + + if (f(a) != 1 || Either.Left.!(a).val != 12) return -1; + if (f(b) != 2 || Either.Right.!(b).val != false) return -2; + if (f(c) != 1 || Either.Left.!(c).val != 123ul) return -3; + if (f(d) != 2 || Either.Right.!(d).val != 123) return -4; + + return 0; +} \ No newline at end of file diff --git a/test/variants/ub_mixed08.v3 b/test/variants/ub_mixed08.v3 new file mode 100644 index 000000000..8ec3f7d23 --- /dev/null +++ b/test/variants/ub_mixed08.v3 @@ -0,0 +1,29 @@ +//@execute =0 +type Option { + case Some(val: T) #unboxed; + case None; +} + +def f(a: Option) -> int { + match (a) { + Some(val) => return 1; + None => return -1; + } +} + +def main() -> int { + var a = Option.Some(12); + var b = Option.None; + + var c = Option.Some(false); + var d = Option.None; + + if (f(a) != 1) return -1; + if (Option.Some.!(a).val != 12) return -2; + if (f(b) != -1) return -3; + if (f(c) != 1) return -4; + if (Option.Some.!(c).val != false) return -5; + if (f(d) != -1) return -6; + + return 0; +} \ No newline at end of file diff --git a/test/variants/ub_mixed09.v3 b/test/variants/ub_mixed09.v3 new file mode 100644 index 000000000..0b2bf5432 --- /dev/null +++ b/test/variants/ub_mixed09.v3 @@ -0,0 +1,20 @@ +//@execute 0=102;1=168;2=87 +type A00 { + case X(x: i32, y: i64, z: i32) #unboxed; + case Y(x: i32, y: i32); + case Z(y: i64) #unboxed; +} + +def arr = [ + A00.X(12, 34, 56), + A00.Y(78, 90), + A00.Z(87) +]; + +def main(a: int) -> i32 { + match (arr[a]) { + X(x, y, z) => return i32.!(x + y + z); + Y(x, y) => return x + y; + Z(y) => return i32.!(y); + } +} \ No newline at end of file diff --git a/test/variants/ub_mixed10.v3 b/test/variants/ub_mixed10.v3 new file mode 100644 index 000000000..75f192556 --- /dev/null +++ b/test/variants/ub_mixed10.v3 @@ -0,0 +1,16 @@ +//@execute 0=99;1=20;2=123;3=46 +type A00 { + case X(x: u32); + case Y(x: u32, y: u32) #unboxed; +} + +def arr = [A00.X(99), A00.Y(11, 9), A00.X(123), A00.Y(12, 34)]; + +def main(a: int) -> u32 { + var val: A00 = arr[a]; + + match (val) { + X(x) => return x; + Y(x, y) => return x + y; + } +} \ No newline at end of file diff --git a/test/variants/ub_mixed11.v3 b/test/variants/ub_mixed11.v3 new file mode 100644 index 000000000..b013e888e --- /dev/null +++ b/test/variants/ub_mixed11.v3 @@ -0,0 +1,21 @@ +//@execute 0=13;1=1;2=134 + +type T { + case A(x: (i32, i32)) #unboxed; + case B(y: i64, z: Array) #unboxed; + case C(v: int, w: int); +} + +def arr = [ + T.A((12, 34)), + T.B(1l, [0, 1, 2]), + T.C(56, 78) +]; + +def main(a: int) -> int { + match (arr[a]) { + A(x) => return x.0 + 1; + B(y, z) => return z[y]; + C(v, w) => return v + w; + } +} \ No newline at end of file diff --git a/test/variants/ub_mixed12.v3 b/test/variants/ub_mixed12.v3 new file mode 100644 index 000000000..99e167b78 --- /dev/null +++ b/test/variants/ub_mixed12.v3 @@ -0,0 +1,23 @@ +//@execute 0=true;1=false;2=true + +type T { + case A(x: (i32, i32)) #unboxed; + case B(y: i64, z: Array) #unboxed; + case C(v: int, w: int); +} + +def arr = [ + T.A((12, 34)), + T.B(1l, [0, 1, 2]), + T.C(56, 78) +]; + +def arr2 = [ + T.A((12, 34)), + T.B(1l, [0, 1, 2]), + T.C(56, 78) +]; + +def main(a: int) -> bool { + return arr[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_mixed13.v3 b/test/variants/ub_mixed13.v3 new file mode 100644 index 000000000..89f87a2fa --- /dev/null +++ b/test/variants/ub_mixed13.v3 @@ -0,0 +1,29 @@ +//@execute 0=true;1=true;2=true;3=true + +type T { + case A(x: i32) #unboxed; + case B(x: i32); +} + +type U { + case A(x: T) #unboxed; + case B(x: T); +} + +def arr = [ + U.A(T.A(12)), + U.A(T.B(23)), + U.B(T.A(34)), + U.B(T.B(45)) +]; + +def arr2 = [ + U.A(T.A(12)), + U.A(T.B(23)), + U.B(T.A(34)), + U.B(T.B(45)) +]; + +def main(a: int) -> bool { + return arr[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_mixed_array00.v3 b/test/variants/ub_mixed_array00.v3 new file mode 100644 index 000000000..62e859828 --- /dev/null +++ b/test/variants/ub_mixed_array00.v3 @@ -0,0 +1,28 @@ +//@execute 0=6; 1=17; 9234789=101582685; -2=-16 +class Tree { + def sum() -> int; +} +class Branch(l: Tree, r: Tree) extends Tree { + def sum() -> int { return l.sum() + r.sum(); } +} +class Leaf(val: int) extends Tree { + def sum() -> int { return val; } +} +type Pair(x: int, t: Tree) #unboxed { } + +def main(a: int) -> int { + var x = Array.new(4); + for (i < x.length) { + x[i] = Pair(i, newTree(a, i)); + } + var sum = 0; + for (e in x) { + sum += e.x + e.t.sum(); + } + return sum; +} + +def newTree(a: int, i: int) -> Tree { + if (i <= 0) return Leaf.new(a); + return Branch.new(newTree(a, i - 2), newTree(a, i - 1)); +} \ No newline at end of file diff --git a/test/variants/ub_null00.v3 b/test/variants/ub_null00.v3 new file mode 100644 index 000000000..87ec57a77 --- /dev/null +++ b/test/variants/ub_null00.v3 @@ -0,0 +1,14 @@ +//@execute 0=false;1=false;2=true;3=false;4=false;5=true +type A00 #unboxed { + case X(a: u64); + case Y(b: u32); +} + +var n: A00; + +var arr: Array = [n, n, n, A00.X(12), A00.Y(34), A00.X(0)]; +var arr2 = [A00.X(12), A00.Y(34), A00.X(0), n, n, n]; + +def main(a: int) -> bool { + return arr[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_null01.v3 b/test/variants/ub_null01.v3 new file mode 100644 index 000000000..cd81ccc5d --- /dev/null +++ b/test/variants/ub_null01.v3 @@ -0,0 +1,14 @@ +//@execute 0=false;1=false;2=true;3=false;4=false;5=true +type A00 { + case X(a: u64) #unboxed; + case Y(b: u32); +} + +var n: A00; + +var arr: Array = [n, n, n, A00.X(12), A00.Y(34), A00.X(0)]; +var arr2 = [A00.X(12), A00.Y(34), A00.X(0), n, n, n]; + +def main(a: int) -> bool { + return arr[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_null02.v3 b/test/variants/ub_null02.v3 new file mode 100644 index 000000000..19b1b3a87 --- /dev/null +++ b/test/variants/ub_null02.v3 @@ -0,0 +1,14 @@ +//@execute 0=false;1=false;2=true;3=false;4=false;5=true +type A00 { + case X(a: u64); + case Y(b: u32) #unboxed; +} + +var n: A00; + +var arr: Array = [n, n, n, A00.X(12), A00.Y(34), A00.X(0)]; +var arr2 = [A00.X(12), A00.Y(34), A00.X(0), n, n, n]; + +def main(a: int) -> bool { + return arr[a] == arr2[a]; +} \ No newline at end of file diff --git a/test/variants/ub_query.v3 b/test/variants/ub_query.v3 new file mode 100644 index 000000000..211140109 --- /dev/null +++ b/test/variants/ub_query.v3 @@ -0,0 +1,19 @@ +//@execute 0=true;1=true;2=true +type A00 #unboxed { + case X(x: i32, y: i64, z: i32); + case Y(x: i32, y: i32); + case Z(y: i64); +} + +def arr = [A00.X(12, 34, 56), A00.Y(78, 90), A00.Z(87)]; + +def main(a: int) -> bool { + if (arr[a] != arr[a]) return false; + + match (a) { + 0 => return A00.X.?(arr[a]); + 1 => return A00.Y.?(arr[a]); + 2 => return A00.Z.?(arr[a]); + } + return true; +} \ No newline at end of file diff --git a/test/variants/ub_rec00.v3 b/test/variants/ub_rec00.v3 new file mode 100644 index 000000000..4d1037d91 --- /dev/null +++ b/test/variants/ub_rec00.v3 @@ -0,0 +1,10 @@ +//@execute =12 +type A00 #unboxed { + case A(x: A00); + case B(x: int); +} + +def main() -> int { + var a = A00.A(A00.B(12)); + return A00.B.!(a.x).x; +} \ No newline at end of file diff --git a/test/variants/ub_rec01.v3 b/test/variants/ub_rec01.v3 new file mode 100644 index 000000000..5ceda33de --- /dev/null +++ b/test/variants/ub_rec01.v3 @@ -0,0 +1,15 @@ +//@execute =12 +type T { + case A(x: A00); + case B(x: int); +} + +type A00 #unboxed { + case A(x: T); + case B(x: int); +} + +def main() -> int { + var a = A00.A(T.A(A00.A(T.B(12)))); + return T.B.!(A00.A.!(T.A.!(A00.A.!(a).x).x).x).x; +} \ No newline at end of file diff --git a/test/variants/ub_small00.v3 b/test/variants/ub_small00.v3 new file mode 100644 index 000000000..0baf807e1 --- /dev/null +++ b/test/variants/ub_small00.v3 @@ -0,0 +1,15 @@ +//@execute =11 +type A00 #unboxed { + case X; + case Y(x: int); +} + +def main() -> int { + var a00_x = A00.X; + var a00_y = A00.Y(11); + + match (a00_y) { + Y(x) => return x; + _ => return -1; + } +} diff --git a/test/variants/ub_small01.v3 b/test/variants/ub_small01.v3 new file mode 100644 index 000000000..0e70c2c02 --- /dev/null +++ b/test/variants/ub_small01.v3 @@ -0,0 +1,15 @@ +//@execute =134 +type A00 #unboxed { + case X(x: int, y: int); + case Y(x: int, y: int); +} + +def main() -> int { + var a00_x = A00.X(12, 34); + var a00_y = A00.Y(56, 78); + + match (a00_y) { + Y(x, y) => return x + y; + X(x, y) => return -1; + } +} \ No newline at end of file diff --git a/test/variants/ub_small02.v3 b/test/variants/ub_small02.v3 new file mode 100644 index 000000000..be1c69d33 --- /dev/null +++ b/test/variants/ub_small02.v3 @@ -0,0 +1,15 @@ +//@execute =11 +type A00 #unboxed { + case X; + case Y(x: int); +} + +def main() -> int { + var a00_x: A00 = A00.X; + var a00_y: A00 = A00.Y(11); + + match (a00_y) { + Y(x) => return x; + _ => return -1; + } +} \ No newline at end of file diff --git a/test/variants/ub_small03.v3 b/test/variants/ub_small03.v3 new file mode 100644 index 000000000..27e486228 --- /dev/null +++ b/test/variants/ub_small03.v3 @@ -0,0 +1,18 @@ +//@execute =168 +type A00 #unboxed { + case X(x: i32, y: i64, z: i32); + case Y(x: i32, y: i32); + case Z(y: i64); +} + +def main() -> i32 { + var a00_x: A00 = A00.X(12, 34, 56); + var a00_y: A00 = A00.Y(78, 90); + var a00_z: A00 = A00.Z(87); + + match (a00_y) { + Y(x, y) => return x + y; + X(x, y, z) => return i32.!(x + y + z); + Z(y) => return i32.!(y); + } +} \ No newline at end of file diff --git a/test/variants/ub_small04.v3 b/test/variants/ub_small04.v3 new file mode 100644 index 000000000..22ce43e26 --- /dev/null +++ b/test/variants/ub_small04.v3 @@ -0,0 +1,15 @@ +//@execute =168 +type A00 #unboxed { + case X(x: i32, y: i64, z: i32); + case Y(x: i32, y: i32); +} + +def main() -> i32 { + var a00_x: A00 = A00.X(12, 34, 56); + var a00_y: A00 = A00.Y(78, 90); + + match (a00_y) { + Y(x, y) => return x + y; + X(x, y, z) => return int.!(x + y + z); + } +} \ No newline at end of file diff --git a/test/variants/ub_small05.v3 b/test/variants/ub_small05.v3 new file mode 100644 index 000000000..cb47640c6 --- /dev/null +++ b/test/variants/ub_small05.v3 @@ -0,0 +1,21 @@ +//@execute =3 +type Option #unboxed { + case None; + case Some(val: T); +} + +def f(x: Option) -> int { + match (x) { + None => return 0; + Some(val) => return val; + } +} + +def main() -> int { + var n = Option.None; + var s = Option.Some(10); + + if (f(n) != 0) return -1; + if (f(s) != 10) return -2; + return 3; +} \ No newline at end of file diff --git a/test/variants/ub_small06.v3 b/test/variants/ub_small06.v3 new file mode 100644 index 000000000..4e88b37ff --- /dev/null +++ b/test/variants/ub_small06.v3 @@ -0,0 +1,21 @@ +//@execute =3 +type Option #unboxed { + case None; + case Some(val: int); +} + +def f(x: Option) -> int { + match (x) { + None => return 0; + Some(val) => return val; + } +} + +def main() -> int { + var n = Option.None; + var s = Option.Some(10); + + if (f(n) != 0) return -1; + if (f(s) != 10) return -2; + return 3; +} \ No newline at end of file diff --git a/test/variants/ub_small07.v3 b/test/variants/ub_small07.v3 new file mode 100644 index 000000000..438843d28 --- /dev/null +++ b/test/variants/ub_small07.v3 @@ -0,0 +1,32 @@ +//@execute 0=1;1=2;2=1;3=2 +type Either #unboxed { + case Left(val: T); + case Right(val: U); +} + +def f(a: Either) -> int { + match (a) { + Left(val) => return 1; + Right(val) => return 2; + } +} + +def g(a: Either, b: Either) -> bool { + return a == b; +} + +def main(i: int) -> int { + var a = Either.Left(12); + var b = Either.Right(false); + + var c = Either.Left(123ul); + var d = Either.Right(123); + + match (i) { + 0 => return f(a); + 1 => return f(b); + 2 => return f(c); + 3 => return f(d); + } + return 0; +} \ No newline at end of file diff --git a/test/variants/ub_tag00.v3 b/test/variants/ub_tag00.v3 new file mode 100644 index 000000000..e4ba09cf4 --- /dev/null +++ b/test/variants/ub_tag00.v3 @@ -0,0 +1,35 @@ +//@execute 0=0;1=1;2=2;3=3;4=4 + +type A00 #unboxed { + case X; + case Y(x: int); + case Z(x: int, y: int); + case W(x: Array); + case V(x: Array, y: int); + + def t() -> int { + return tag; + } + + def f() -> int { + match (this) { + X => return 0; + Y(x) => return x; + Z(x, y) => return x + y; + W(x) => return x[0]; + V(x, y) => return x[y]; + } + } +} + +def vals = [ + A00.X, + A00.Y(10), + A00.Z(20, 30), + A00.W([1, 2, 3]), + A00.V([12, 23, 34], 2) +]; + +def main(a: int) -> int { + return vals[a].t(); +} \ No newline at end of file