Commit ca12e4f33e
Changed files (181)
test
cases
test/cases/x86_64-linux/inline_assembly.0.zig
@@ -1,16 +0,0 @@
-pub fn main() void {
- const number = 1234;
- const x = asm volatile ("syscall"
- : [o] "{rax}" (-> number),
- : [number] "{rax}" (231),
- [arg1] "{rdi}" (60),
- : "rcx", "r11", "memory"
- );
- _ = x;
-}
-
-// error
-// output_mode=Exe
-// target=x86_64-linux
-//
-// :4:27: error: expected type 'type', found 'comptime_int'
test/cases/x86_64-linux/inline_assembly.1.zig
@@ -1,15 +0,0 @@
-const S = struct {
- comptime {
- asm volatile (
- \\zig_moment:
- \\syscall
- );
- }
-};
-pub fn main() void {
- _ = S;
-}
-
-// error
-//
-// :3:13: error: volatile is meaningless on global assembly
test/cases/x86_64-linux/inline_assembly.2.zig
@@ -1,12 +0,0 @@
-pub fn main() void {
- var bruh: u32 = 1;
- asm (""
- :
- : [bruh] "{rax}" (4),
- : "memory"
- );
-}
-
-// error
-//
-// :3:5: error: assembly expression with no output must be marked volatile
test/cases/x86_64-linux/inline_assembly.3.zig
@@ -1,12 +0,0 @@
-pub fn main() void {}
-comptime {
- asm (""
- :
- : [bruh] "{rax}" (4),
- : "memory"
- );
-}
-
-// error
-//
-// :3:5: error: global assembly cannot have inputs, outputs, or clobbers
test/cases/adding_numbers_at_runtime_and_comptime.0.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- add(3, 4);
-}
-
-fn add(a: u32, b: u32) void {
- if (a + b != 7) unreachable;
-}
-
-// run
-//
test/cases/adding_numbers_at_runtime_and_comptime.1.zig
@@ -1,12 +0,0 @@
-pub fn main() void {
- if (x - 7 != 0) unreachable;
-}
-
-fn add(a: u32, b: u32) u32 {
- return a + b;
-}
-
-const x = add(3, 4);
-
-// run
-//
test/cases/adding_numbers_at_runtime_and_comptime.2.zig
@@ -1,13 +0,0 @@
-pub fn main() void {
- var x: usize = 3;
- _ = &x;
- const y = add(1, 2, x);
- if (y - 6 != 0) unreachable;
-}
-
-inline fn add(a: usize, b: usize, c: usize) usize {
- return a + b + c;
-}
-
-// run
-//
test/cases/arithmetic_operations.0.zig
@@ -1,17 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- print(2, 4);
- print(1, 7);
-}
-
-fn print(a: u32, b: u32) void {
- const str = "123456789";
- const len = a + b;
- _ = std.posix.write(1, str[0..len]) catch {};
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-//
-// 12345612345678
test/cases/arithmetic_operations.1.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- print(10, 5);
- print(4, 3);
-}
-
-fn print(a: u32, b: u32) void {
- const str = "123456789";
- const len = a - b;
- _ = std.posix.write(1, str[0..len]) catch {};
-}
-
-// run
-//
-// 123451
test/cases/arithmetic_operations.2.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- print(8, 9);
- print(3, 7);
-}
-
-fn print(a: u32, b: u32) void {
- const str = "123456789";
- const len = a & b;
- _ = std.posix.write(1, str[0..len]) catch {};
-}
-
-// run
-//
-// 12345678123
test/cases/arithmetic_operations.3.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- print(4, 2);
- print(3, 7);
-}
-
-fn print(a: u32, b: u32) void {
- const str = "123456789";
- const len = a | b;
- _ = std.posix.write(1, str[0..len]) catch {};
-}
-
-// run
-//
-// 1234561234567
test/cases/arithmetic_operations.4.zig
@@ -1,16 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- print(42, 42);
- print(3, 5);
-}
-
-fn print(a: u32, b: u32) void {
- const str = "123456789";
- const len = a ^ b;
- _ = std.posix.write(1, str[0..len]) catch {};
-}
-
-// run
-//
-// 123456
test/cases/arithmetic_operations.5.zig
@@ -1,15 +0,0 @@
-pub fn main() void {
- var x: u32 = 1;
- assert(x << 1 == 2);
-
- x <<= 1;
- assert(x << 2 == 8);
- assert(x << 3 == 16);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/arithmetic_operations.6.zig
@@ -1,21 +0,0 @@
-pub fn main() void {
- var a: u32 = 1024;
- assert(a >> 1 == 512);
-
- a >>= 1;
- assert(a >> 2 == 128);
- assert(a >> 3 == 64);
- assert(a >> 4 == 32);
- assert(a >> 5 == 16);
- assert(a >> 6 == 8);
- assert(a >> 7 == 4);
- assert(a >> 8 == 2);
- assert(a >> 9 == 1);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.0.zig
@@ -1,15 +0,0 @@
-pub fn main() void {
- add(3, 4);
-}
-
-fn add(a: u32, b: u32) void {
- assert(a + b == 7);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-// target=x86_64-macos,x86_64-linux
-// link_libc=true
test/cases/assert_function.1.zig
@@ -1,17 +0,0 @@
-pub fn main() void {
- add(3, 4);
-}
-
-fn add(a: u32, b: u32) void {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- assert(e == 14);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.10.zig
@@ -1,27 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 116);
-}
-
-fn add(a: u32, b: u32) u32 {
- const x: u32 = blk: {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- const j = i + d; // 110
- break :blk j;
- };
- const y = x + a; // 113
- const z = y + a; // 116
- return z;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.11.zig
@@ -1,66 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 1221);
- assert(mul(3, 4) == 21609);
-}
-
-fn add(a: u32, b: u32) u32 {
- const x: u32 = blk: {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- const j = i + d; // 110
- const k = i + j; // 210
- const l = j + k; // 320
- const m = l + c; // 327
- const n = m + d; // 337
- const o = n + e; // 351
- const p = o + f; // 375
- const q = p + g; // 413
- const r = q + h; // 475
- const s = r + i; // 575
- const t = s + j; // 685
- const u = t + k; // 895
- const v = u + l; // 1215
- break :blk v;
- };
- const y = x + a; // 1218
- const z = y + a; // 1221
- return z;
-}
-
-fn mul(a: u32, b: u32) u32 {
- const x: u32 = blk: {
- const c = a * a * a * a; // 81
- const d = a * a * a * b; // 108
- const e = a * a * b * a; // 108
- const f = a * a * b * b; // 144
- const g = a * b * a * a; // 108
- const h = a * b * a * b; // 144
- const i = a * b * b * a; // 144
- const j = a * b * b * b; // 192
- const k = b * a * a * a; // 108
- const l = b * a * a * b; // 144
- const m = b * a * b * a; // 144
- const n = b * a * b * b; // 192
- const o = b * b * a * a; // 144
- const p = b * b * a * b; // 192
- const q = b * b * b * a; // 192
- const r = b * b * b * b; // 256
- const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
- break :blk s;
- };
- const y = x * a; // 7203
- const z = y * a; // 21609
- return z;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.12.zig
@@ -1,47 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 791);
- assert(add(4, 3) == 79);
-}
-
-fn add(a: u32, b: u32) u32 {
- const x: u32 = if (a < b) blk: {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- const j = i + d; // 110
- const k = i + j; // 210
- const l = k + c; // 217
- const m = l + d; // 227
- const n = m + e; // 241
- const o = n + f; // 265
- const p = o + g; // 303
- const q = p + h; // 365
- const r = q + i; // 465
- const s = r + j; // 575
- const t = s + k; // 785
- break :blk t;
- } else blk: {
- const t = b + b + a; // 10
- const c = a + t; // 14
- const d = c + t; // 24
- const e = d + t; // 34
- const f = e + t; // 44
- const g = f + t; // 54
- const h = c + g; // 68
- break :blk h + b; // 71
- };
- const y = x + a; // 788, 75
- const z = y + a; // 791, 79
- return z;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.13.zig
@@ -1,19 +0,0 @@
-pub fn main() void {
- const ignore =
- \\ cool thx
- \\
- ;
- _ = ignore;
- add('ใ', '\x03');
-}
-
-fn add(a: u32, b: u32) void {
- assert(a + b == 12356);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.14.zig
@@ -1,17 +0,0 @@
-pub fn main() void {
- add(aa, bb);
-}
-
-const aa = 'ใ';
-const bb = '\x03';
-
-fn add(a: u32, b: u32) void {
- assert(a + b == 12356);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.15.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- assert("hello"[0] == 'h');
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.16.zig
@@ -1,11 +0,0 @@
-const hello = "hello".*;
-pub fn main() void {
- assert(hello[1] == 'e');
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.17.zig
@@ -1,12 +0,0 @@
-pub fn main() void {
- var i: u64 = 0xFFEEDDCCBBAA9988;
- _ = &i;
- assert(i == 0xFFEEDDCCBBAA9988);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.18.zig
@@ -1,20 +0,0 @@
-const builtin = @import("builtin");
-
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- for ("hello") |_| print();
-}
-
-fn print() void {
- _ = write(1, @intFromPtr("hello\n"), 6);
-}
-
-// run
-//
-// hello
-// hello
-// hello
-// hello
-// hello
-//
test/cases/assert_function.2.zig
@@ -1,21 +0,0 @@
-pub fn main() void {
- add(3, 4);
-}
-
-fn add(a: u32, b: u32) void {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- assert(i == 100);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.3.zig
@@ -1,22 +0,0 @@
-pub fn main() void {
- add(3, 4);
-}
-
-fn add(a: u32, b: u32) void {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- const j = i + d; // 110
- assert(j == 110);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.4.zig
@@ -1,15 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 7);
- assert(add(20, 10) == 30);
-}
-
-fn add(a: u32, b: u32) u32 {
- return a + b;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.5.zig
@@ -1,19 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 7);
- assert(add(20, 10) == 30);
-}
-
-fn add(a: u32, b: u32) u32 {
- var x: u32 = undefined;
- x = 0;
- x += a;
- x += b;
- return x;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/assert_function.6.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- const a: u32 = 2;
- const b: ?u32 = a;
- const c = b.?;
- if (c != 2) unreachable;
-}
-
-// run
-//
test/cases/assert_function.7.zig
@@ -1,23 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- var i: u32 = 0;
- while (i < 4) : (i += 1) print();
- assert(i == 4);
-}
-
-fn print() void {
- _ = write(1, @intFromPtr("hello\n"), 6);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
-// hello
-// hello
-// hello
-// hello
-//
test/cases/assert_function.8.zig
@@ -1,20 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- var i: u32 = 0;
- inline while (i < 4) : (i += 1) print();
- assert(i == 4);
-}
-
-fn print() void {
- _ = write(1, @intFromPtr("hello\n"), 6);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// error
-//
-// :5:21: error: unable to resolve comptime value
-// :5:21: note: condition in comptime branch must be comptime-known
test/cases/assert_function.9.zig
@@ -1,22 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 20);
-}
-
-fn add(a: u32, b: u32) u32 {
- const x: u32 = blk: {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- break :blk e;
- };
- const y = x + a; // 17
- const z = y + a; // 20
- return z;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/binary_operands.0.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: u8 = 5;
- i += 20;
- if (i != 25) unreachable;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/binary_operands.1.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: i32 = 2147483647;
- _ = &i;
- if (i +% 1 != -2147483648) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.10.zig
@@ -1,14 +0,0 @@
-pub fn main() void {
- var i: u32 = 5;
- i *= 7;
- var result: u32 = foo(i, 10);
- _ = &result;
- if (result != 350) unreachable;
- return;
-}
-fn foo(x: u32, y: u32) u32 {
- return x * y;
-}
-
-// run
-//
test/cases/binary_operands.11.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- var i: i32 = 2147483647;
- _ = &i;
- const result = i *% 2;
- if (result != -2) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.12.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: u3 = 3;
- _ = &i;
- if (i *% 3 != 1) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.13.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: i4 = 3;
- _ = &i;
- if (i *% 3 != -7) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.14.zig
@@ -1,13 +0,0 @@
-pub fn main() void {
- var i: u32 = 352;
- i /= 7; // i = 50
- const result: u32 = foo(i, 7);
- if (result != 7) unreachable;
- return;
-}
-fn foo(x: u32, y: u32) u32 {
- return x / y;
-}
-
-// run
-//
test/cases/binary_operands.15.zig
@@ -1,8 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- i &= 6;
- return i - 4;
-}
-
-// run
-//
test/cases/binary_operands.16.zig
@@ -1,8 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- i |= 6;
- return i - 7;
-}
-
-// run
-//
test/cases/binary_operands.17.zig
@@ -1,8 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- i ^= 6;
- return i - 3;
-}
-
-// run
-//
test/cases/binary_operands.18.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = false;
- b = b or false;
- if (b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.19.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = true;
- b = b or false;
- if (!b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.2.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: i4 = 7;
- _ = &i;
- if (i +% 1 != -8) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.20.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = false;
- b = b or true;
- if (!b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.21.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = true;
- b = b or true;
- if (!b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.22.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = false;
- b = b and false;
- if (b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.23.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = true;
- b = b and false;
- if (b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.24.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = false;
- b = b and true;
- if (b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.25.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var b: bool = true;
- b = b and true;
- if (!b) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.3.zig
@@ -1,8 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 255;
- _ = &i;
- return i +% 1;
-}
-
-// run
-//
test/cases/binary_operands.4.zig
@@ -1,12 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- i += 20;
- const result: u8 = foo(i, 10);
- return result - 35;
-}
-fn foo(x: u8, y: u8) u8 {
- return x + y;
-}
-
-// run
-//
test/cases/binary_operands.5.zig
@@ -1,8 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 20;
- i -= 5;
- return i - 15;
-}
-
-// run
-//
test/cases/binary_operands.6.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: i32 = -2147483648;
- _ = &i;
- if (i -% 1 != 2147483647) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.7.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i: i7 = -64;
- _ = &i;
- if (i -% 1 != 63) unreachable;
- return;
-}
-
-// run
-//
test/cases/binary_operands.8.zig
@@ -1,8 +0,0 @@
-pub fn main() void {
- var i: u4 = 0;
- _ = &i;
- if (i -% 1 != 15) unreachable;
-}
-
-// run
-//
test/cases/binary_operands.9.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- i -= 3;
- var result: u8 = foo(i, 10);
- _ = &result;
- return result - 8;
-}
-fn foo(x: u8, y: u8) u8 {
- return y - x;
-}
-
-// run
-//
test/cases/break_continue.0.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- while (true) {
- break;
- }
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-//
test/cases/break_continue.1.zig
@@ -1,8 +0,0 @@
-pub fn main() void {
- foo: while (true) {
- break :foo;
- }
-}
-
-// run
-//
test/cases/break_continue.2.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- var i: u64 = 0;
- while (true) : (i += 1) {
- if (i == 4) return;
- continue;
- }
-}
-
-// run
-//
test/cases/break_continue.3.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- var i: u64 = 0;
- foo: while (true) : (i += 1) {
- if (i == 4) return;
- continue :foo;
- }
-}
-
-// run
-//
test/cases/catch_at_comptime.0.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const i: anyerror!u64 = 0;
- const caught = i catch 5;
- assert(caught == 0);
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/catch_at_comptime.1.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const i: anyerror!u64 = error.B;
- const caught = i catch 5;
- assert(caught == 5);
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/catch_at_comptime.2.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const a: anyerror!comptime_int = 42;
- const b: *const comptime_int = &(a catch unreachable);
- assert(b.* == 42);
-}
-fn assert(b: bool) void {
- if (!b) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/catch_at_comptime.3.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- const a: anyerror!u32 = error.B;
- _ = &(a catch |err| assert(err == error.B));
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/catch_at_comptime.4.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- const a: anyerror!u32 = error.Bar;
- a catch |err| assert(err == error.Bar);
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/compile_log.0.zig
@@ -1,22 +0,0 @@
-export fn _start() noreturn {
- const b = true;
- var f: u32 = 1;
- @compileLog(b, 20, f, x);
- @compileLog(1000);
- var bruh: usize = true;
- _ = .{ &f, &bruh };
- unreachable;
-}
-export fn other() void {
- @compileLog(1234);
-}
-fn x() void {}
-
-// error
-//
-// :6:23: error: expected type 'usize', found 'bool'
-//
-// Compile Log Output:
-// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
-// @as(comptime_int, 1000)
-// @as(comptime_int, 1234)
test/cases/compile_log.1.zig
@@ -1,21 +0,0 @@
-export fn _start() noreturn {
- const b = true;
- var f: u32 = 1;
- _ = &f;
- @compileLog(b, 20, f, x);
- @compileLog(1000);
- unreachable;
-}
-export fn other() void {
- @compileLog(1234);
-}
-fn x() void {}
-
-// error
-//
-// :9:5: error: found compile log statement
-// :4:5: note: also here
-//
-// Compile Log Output:
-// @as(bool, true), @as(comptime_int, 20), @as(u32, [runtime value]), @as(fn () void, (function 'x'))
-// @as(comptime_int, 1000)
test/cases/comptime_var.0.zig
@@ -1,14 +0,0 @@
-pub fn main() void {
- var a: u32 = 0;
- _ = &a;
- comptime var b: u32 = 0;
- if (a == 0) b = 3;
-}
-
-// error
-// output_mode=Exe
-// target=x86_64-macos,x86_64-linux
-// link_libc=true
-//
-// :5:19: error: store to comptime variable depends on runtime condition
-// :5:11: note: runtime condition here
test/cases/comptime_var.1.zig
@@ -1,14 +0,0 @@
-pub fn main() void {
- var a: u32 = 0;
- _ = &a;
- comptime var b: u32 = 0;
- switch (a) {
- 0 => {},
- else => b = 3,
- }
-}
-
-// error
-//
-// :6:19: error: store to comptime variable depends on runtime condition
-// :4:13: note: runtime condition here
test/cases/comptime_var.2.zig
@@ -1,17 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- comptime var len: u32 = 5;
- print(len);
- len += 9;
- print(len);
-}
-
-fn print(len: usize) void {
- _ = write(1, @intFromPtr("Hello, World!\n"), len);
-}
-
-// run
-//
-// HelloHello, World!
-//
test/cases/comptime_var.3.zig
@@ -1,10 +0,0 @@
-comptime {
- var x: i32 = 1;
- x += 1;
- if (x != 1) unreachable;
-}
-pub fn main() void {}
-
-// error
-//
-// :4:17: error: reached unreachable code
test/cases/comptime_var.4.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- comptime var i: u64 = 0;
- while (i < 5) : (i += 1) {}
-}
-
-// error
-//
-// :3:24: error: cannot store to comptime variable in non-inline loop
-// :3:5: note: non-inline loop here
test/cases/comptime_var.5.zig
@@ -1,16 +0,0 @@
-pub fn main() void {
- var a: u32 = 0;
- _ = &a;
- if (a == 0) {
- comptime var b: u32 = 0;
- b = 1;
- }
-}
-comptime {
- var x: i32 = 1;
- x += 1;
- if (x != 2) unreachable;
-}
-
-// run
-//
test/cases/comptime_var.6.zig
@@ -1,15 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- comptime var i: u64 = 2;
- inline while (i < 6) : (i += 1) {
- print(i);
- }
-}
-fn print(len: usize) void {
- _ = write(1, @intFromPtr("Hello"), len);
-}
-
-// run
-//
-// HeHelHellHello
test/cases/conditional_branches.0.zig
@@ -1,23 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- foo(123);
-}
-
-fn foo(x: u64) void {
- if (x > 42) {
- print();
- }
-}
-
-fn print() void {
- const str = "Hello, World!\n";
- _ = write(1, @intFromPtr(str.ptr), ptr.len);
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-// link_libc=true
-//
-// Hello, World!
-//
test/cases/conditional_branches.1.zig
@@ -1,25 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- foo(true);
-}
-
-fn foo(x: bool) void {
- if (x) {
- print();
- print();
- } else {
- print();
- }
-}
-
-fn print() void {
- const str = "Hello, World!\n";
- _ = write(1, @intFromPtr(str.ptr), ptr.len);
-}
-
-// run
-//
-// Hello, World!
-// Hello, World!
-//
test/cases/conditions.0.zig
@@ -1,11 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- if (i > @as(u8, 4)) {
- i += 10;
- }
- return i - 15;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/conditions.1.zig
@@ -1,12 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- if (i < @as(u8, 4)) {
- i += 10;
- } else {
- i = 2;
- }
- return i - 2;
-}
-
-// run
-//
test/cases/conditions.2.zig
@@ -1,12 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 5;
- if (i < @as(u8, 4)) {
- i += 10;
- } else if (i == @as(u8, 5)) {
- i = 20;
- }
- return i - 20;
-}
-
-// run
-//
test/cases/conditions.3.zig
@@ -1,16 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 11;
- if (i < @as(u8, 4)) {
- i += 10;
- } else {
- if (i > @as(u8, 10)) {
- i += 20;
- } else {
- i = 20;
- }
- }
- return i - 31;
-}
-
-// run
-//
test/cases/conditions.4.zig
@@ -1,15 +0,0 @@
-pub fn main() void {
- assert(foo(true) != @as(i32, 30));
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-fn foo(ok: bool) i32 {
- const x = if (ok) @as(i32, 20) else @as(i32, 10);
- return x;
-}
-
-// run
-//
test/cases/conditions.5.zig
@@ -1,21 +0,0 @@
-pub fn main() void {
- assert(foo(false) == @as(i32, 20));
- assert(foo(true) == @as(i32, 30));
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-fn foo(ok: bool) i32 {
- const val: i32 = blk: {
- var x: i32 = 1;
- _ = &x;
- if (!ok) break :blk x + @as(i32, 9);
- break :blk x + @as(i32, 19);
- };
- return val + 10;
-}
-
-// run
-//
test/cases/double_ampersand.0.zig
@@ -1,6 +0,0 @@
-pub const a = if (true && false) 1 else 2;
-
-// error
-// output_mode=Exe
-//
-// :1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/cases/double_ampersand.1.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const a = true;
- const b = false;
- _ = a & &b;
-}
-
-// error
-//
-// :4:11: error: incompatible types: 'bool' and '*const bool'
-// :4:9: note: type 'bool' here
-// :4:13: note: type '*const bool' here
test/cases/double_ampersand.2.zig
@@ -1,7 +0,0 @@
-pub fn main() void {
- const b: u8 = 1;
- _ = &&b;
-}
-
-// run
-//
test/cases/enum_values.0.zig
@@ -1,18 +0,0 @@
-const Number = enum { One, Two, Three };
-
-pub fn main() void {
- var number1 = Number.One;
- var number2: Number = .Two;
- if (false) {
- &number1;
- &number2;
- }
- const number3: Number = @enumFromInt(2);
- if (@intFromEnum(number3) != 2) {
- unreachable;
- }
- return;
-}
-
-// run
-//
test/cases/enum_values.1.zig
@@ -1,25 +0,0 @@
-const Number = enum { One, Two, Three };
-
-pub fn main() void {
- var number1 = Number.One;
- _ = &number1;
- var number2: Number = .Two;
- _ = &number2;
- const number3: Number = @enumFromInt(2);
- assert(number1 != number2);
- assert(number2 != number3);
- assert(@intFromEnum(number1) == 0);
- assert(@intFromEnum(number2) == 1);
- assert(@intFromEnum(number3) == 2);
- var x: Number = .Two;
- _ = &x;
- assert(number2 == x);
-
- return;
-}
-fn assert(val: bool) void {
- if (!val) unreachable;
-}
-
-// run
-//
test/cases/error_unions.0.zig
@@ -1,16 +0,0 @@
-pub fn main() void {
- var e1 = error.Foo;
- var e2 = error.Bar;
- _ = .{ &e1, &e2 };
- assert(e1 != e2);
- assert(e1 == error.Foo);
- assert(e2 == error.Bar);
-}
-
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/error_unions.1.zig
@@ -1,9 +0,0 @@
-pub fn main() u8 {
- var e: anyerror!u8 = 5;
- _ = &e;
- const i = e catch 10;
- return i - 5;
-}
-
-// run
-//
test/cases/error_unions.2.zig
@@ -1,9 +0,0 @@
-pub fn main() u8 {
- var e: anyerror!u8 = error.Foo;
- _ = &e;
- const i = e catch 10;
- return i - 10;
-}
-
-// run
-//
test/cases/error_unions.3.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var e = foo();
- _ = &e;
- const i = e catch 69;
- return i - 5;
-}
-
-fn foo() anyerror!u8 {
- return 5;
-}
-
-// run
-//
test/cases/error_unions.4.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var e = foo();
- _ = &e;
- const i = e catch 69;
- return i - 69;
-}
-
-fn foo() anyerror!u8 {
- return error.Bruh;
-}
-
-// run
-//
test/cases/error_unions.5.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var e = foo();
- _ = &e;
- const i = e catch 42;
- return i - 42;
-}
-
-fn foo() anyerror!u8 {
- return error.Dab;
-}
-
-// run
-//
test/cases/errors.0.zig
@@ -1,15 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- foo() catch print();
-}
-
-fn foo() anyerror!void {}
-
-fn print() void {
- _ = std.posix.write(1, "Hello, World!\n") catch {};
-}
-
-// run
-// target=x86_64-macos
-//
test/cases/errors.1.zig
@@ -1,18 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- foo() catch print();
-}
-
-fn foo() anyerror!void {
- return error.Test;
-}
-
-fn print() void {
- _ = std.posix.write(1, "Hello, World!\n") catch {};
-}
-
-// run
-//
-// Hello, World!
-//
test/cases/errors.2.zig
@@ -1,27 +0,0 @@
-pub fn main() void {
- foo() catch |err| {
- assert(err == error.Foo);
- assert(err != error.Bar);
- assert(err != error.Baz);
- };
- bar() catch |err| {
- assert(err != error.Foo);
- assert(err == error.Bar);
- assert(err != error.Baz);
- };
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-fn foo() anyerror!void {
- return error.Foo;
-}
-
-fn bar() anyerror!void {
- return error.Bar;
-}
-
-// run
-//
test/cases/errors.3.zig
@@ -1,12 +0,0 @@
-pub fn main() void {
- foo() catch unreachable;
-}
-
-fn foo() anyerror!void {
- try bar();
-}
-
-fn bar() anyerror!void {}
-
-// run
-//
test/cases/extern_variable_has_no_type.0.zig
@@ -1,10 +0,0 @@
-comptime {
- const x = foo + foo;
- _ = x;
-}
-extern var foo: i32;
-
-// error
-//
-// :2:19: error: unable to evaluate comptime expression
-// :2:15: note: operation is runtime due to this operand
test/cases/extern_variable_has_no_type.1.zig
@@ -1,8 +0,0 @@
-export fn entry() void {
- _ = foo;
-}
-extern var foo;
-
-// error
-//
-// :4:8: error: unable to infer variable type
test/cases/function_calls.0.zig
@@ -1,12 +0,0 @@
-pub fn main() void {
- foo();
- bar();
-}
-fn foo() void {
- bar();
- bar();
-}
-fn bar() void {}
-
-// run
-//
test/cases/function_calls.1.zig
@@ -1,15 +0,0 @@
-pub fn main() void {
- bar();
- foo();
- foo();
- bar();
- foo();
- bar();
-}
-fn foo() void {
- bar();
-}
-fn bar() void {}
-
-// run
-//
test/cases/function_calls.2.zig
@@ -1,14 +0,0 @@
-pub fn main() void {
- bar();
- foo();
- return;
-}
-fn foo() void {
- bar();
- bar();
- bar();
-}
-fn bar() void {}
-
-// run
-//
test/cases/function_calls.3.zig
@@ -1,10 +0,0 @@
-pub fn main() void {
- foo(10, 20);
-}
-fn foo(x: u8, y: u8) void {
- _ = x;
- _ = y;
-}
-
-// run
-//
test/cases/hello_world_with_updates.0.zig
@@ -1,6 +0,0 @@
-// error
-// output_mode=Exe
-// target=x86_64-linux,x86_64-macos
-// link_libc=true
-//
-// :?:?: error: root source file struct 'tmp' has no member named 'main'
test/cases/hello_world_with_updates.1.zig
@@ -1,6 +0,0 @@
-pub export fn main() noreturn {}
-
-// error
-//
-// :1:22: error: function declared 'noreturn' implicitly returns
-// :1:32: note: control flow reaches end of body here
test/cases/hello_world_with_updates.2.zig
@@ -1,19 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-extern "c" fn exit(c_int) noreturn;
-
-pub export fn main() noreturn {
- print();
-
- exit(0);
-}
-
-fn print() void {
- const msg = @intFromPtr("Hello, World!\n");
- const len = 14;
- _ = write(1, msg, len);
-}
-
-// run
-//
-// Hello, World!
-//
test/cases/hello_world_with_updates.3.zig
@@ -1,16 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- print();
-}
-
-fn print() void {
- const msg = @intFromPtr("Hello, World!\n");
- const len = 14;
- _ = write(1, msg, len);
-}
-
-// run
-//
-// Hello, World!
-//
test/cases/hello_world_with_updates.4.zig
@@ -1,22 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- print();
- print();
- print();
- print();
-}
-
-fn print() void {
- const msg = @intFromPtr("Hello, World!\n");
- const len = 14;
- _ = write(1, msg, len);
-}
-
-// run
-//
-// Hello, World!
-// Hello, World!
-// Hello, World!
-// Hello, World!
-//
test/cases/hello_world_with_updates.5.zig
@@ -1,16 +0,0 @@
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- print();
-}
-
-fn print() void {
- const msg = @intFromPtr("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
- const len = 104;
- _ = write(1, msg, len);
-}
-
-// run
-//
-// What is up? This is a longer message that will force the data to be relocated in virtual address space.
-//
test/cases/hello_world_with_updates.6.zig
@@ -1,20 +0,0 @@
-const builtin = @import("builtin");
-
-extern "c" fn write(c_int, usize, usize) usize;
-
-pub fn main() void {
- print();
- print();
-}
-
-fn print() void {
- const msg = @intFromPtr("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
- const len = 104;
- _ = write(1, msg, len);
-}
-
-// run
-//
-// What is up? This is a longer message that will force the data to be relocated in virtual address space.
-// What is up? This is a longer message that will force the data to be relocated in virtual address space.
-//
test/cases/int_to_ptr.0.zig
@@ -1,8 +0,0 @@
-pub fn main() void {
- _ = @as(*u8, @ptrFromInt(0));
-}
-
-// error
-// output_mode=Exe
-//
-// :2:18: error: pointer type '*u8' does not allow address zero
test/cases/int_to_ptr.1.zig
@@ -1,7 +0,0 @@
-pub fn main() void {
- _ = @as(*u32, @ptrFromInt(2));
-}
-
-// error
-//
-// :2:19: error: pointer type '*u32' requires aligned address
test/cases/locals.0.zig
@@ -1,14 +0,0 @@
-pub fn main() void {
- var i: u8 = 5;
- var y: f32 = 42.0;
- var x: u8 = 10;
- if (false) {
- &y;
- &x / &i;
- }
- if (i != 5) unreachable;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/locals.1.zig
@@ -1,18 +0,0 @@
-pub fn main() void {
- var i: u8 = 5;
- var y: f32 = 42.0;
- _ = &y;
- var x: u8 = 10;
- _ = &x;
- foo(i, x);
- i = x;
- if (i != 10) unreachable;
-}
-fn foo(x: u8, y: u8) void {
- _ = y;
- var i: u8 = 10;
- i = x;
-}
-
-// run
-//
test/cases/lower_unnamed_consts_structs.0.zig
@@ -1,25 +0,0 @@
-const Foo = struct {
- a: u8,
- b: u32,
-
- fn first(self: *Foo) u8 {
- return self.a;
- }
-
- fn second(self: *Foo) u32 {
- return self.b;
- }
-};
-
-pub fn main() void {
- var foo = Foo{ .a = 1, .b = 5 };
- assert(foo.first() == 1);
- assert(foo.second() == 5);
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/lower_unnamed_consts_structs.1.zig
@@ -1,35 +0,0 @@
-const Foo = struct {
- a: u8,
- b: u32,
-
- fn first(self: *Foo) u8 {
- return self.a;
- }
-
- fn second(self: *Foo) u32 {
- return self.b;
- }
-};
-
-pub fn main() void {
- var foo = Foo{ .a = 1, .b = 5 };
- assert(foo.first() == 1);
- assert(foo.second() == 5);
-
- foo.a = 10;
- foo.b = 255;
-
- assert(foo.first() == 10);
- assert(foo.second() == 255);
-
- var foo2 = Foo{ .a = 15, .b = 255 };
- assert(foo2.first() == 15);
- assert(foo2.second() == 255);
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/lower_unnamed_consts_structs.2.zig
@@ -1,25 +0,0 @@
-const Foo = struct {
- a: u8,
- b: u32,
-
- fn first(self: *Foo) u8 {
- return self.a;
- }
-
- fn second(self: *Foo) u32 {
- return self.b;
- }
-};
-
-pub fn main() void {
- var foo2 = Foo{ .a = 15, .b = 255 };
- assert(foo2.first() == 15);
- assert(foo2.second() == 255);
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/merge_error_sets.0.zig
@@ -1,18 +0,0 @@
-pub fn main() void {
- const E = error{ A, B, D } || error{ A, B, C };
- E.A catch {};
- E.B catch {};
- E.C catch {};
- E.D catch {};
- const E2 = error{ X, Y } || @TypeOf(error.Z);
- E2.X catch {};
- E2.Y catch {};
- E2.Z catch {};
- assert(anyerror || error{Z} == anyerror);
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/merge_error_sets.1.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- const z = true || false;
- _ = z;
-}
-
-// error
-//
-// :2:15: error: expected error set type, found 'bool'
-// :2:20: note: '||' merges error sets; 'or' performs boolean OR
test/cases/multiplying_numbers_at_runtime_and_comptime.0.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- mul(3, 4);
-}
-
-fn mul(a: u32, b: u32) void {
- if (a * b != 12) unreachable;
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-//
test/cases/multiplying_numbers_at_runtime_and_comptime.1.zig
@@ -1,12 +0,0 @@
-pub fn main() void {
- if (x - 12 != 0) unreachable;
-}
-
-fn mul(a: u32, b: u32) u32 {
- return a * b;
-}
-
-const x = mul(3, 4);
-
-// run
-//
test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig
@@ -1,13 +0,0 @@
-pub fn main() void {
- var x: usize = 5;
- _ = &x;
- const y = mul(2, 3, x);
- if (y - 30 != 0) unreachable;
-}
-
-inline fn mul(a: usize, b: usize, c: usize) usize {
- return a * b * c;
-}
-
-// run
-//
test/cases/only_1_function_and_it_gets_updated.0.zig
@@ -1,7 +0,0 @@
-pub export fn _start() noreturn {
- while (true) {}
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-//
test/cases/only_1_function_and_it_gets_updated.1.zig
@@ -1,8 +0,0 @@
-pub export fn _start() noreturn {
- var dummy: u32 = 10;
- _ = &dummy;
- while (true) {}
-}
-
-// run
-//
test/cases/optional_payload.0.zig
@@ -1,19 +0,0 @@
-pub fn main() void {
- var x: u32 = undefined;
- const maybe_x = byPtr(&x);
- assert(maybe_x != null);
- maybe_x.?.* = 123;
- assert(x == 123);
-}
-
-fn byPtr(x: *u32) ?*u32 {
- return x;
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-//
test/cases/optional_payload.1.zig
@@ -1,17 +0,0 @@
-pub fn main() void {
- var x: u32 = undefined;
- const maybe_x = byPtr(&x);
- assert(maybe_x == null);
-}
-
-fn byPtr(x: *u32) ?*u32 {
- _ = x;
- return null;
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/optional_payload.2.zig
@@ -1,18 +0,0 @@
-pub fn main() void {
- var x: u8 = undefined;
- const maybe_x = byPtr(&x);
- assert(maybe_x != null);
- maybe_x.?.* = 255;
- assert(x == 255);
-}
-
-fn byPtr(x: *u8) ?*u8 {
- return x;
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/optional_payload.3.zig
@@ -1,18 +0,0 @@
-pub fn main() void {
- var x: i8 = undefined;
- const maybe_x = byPtr(&x);
- assert(maybe_x != null);
- maybe_x.?.* = -1;
- assert(x == -1);
-}
-
-fn byPtr(x: *i8) ?*i8 {
- return x;
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/optionals.0.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var x: ?u8 = 5;
- _ = &x;
- var y: u8 = 0;
- if (x) |val| {
- y = val;
- }
- return y - 5;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/optionals.1.zig
@@ -1,12 +0,0 @@
-pub fn main() u8 {
- var x: ?u8 = null;
- _ = &x;
- var y: u8 = 0;
- if (x) |val| {
- y = val;
- }
- return y;
-}
-
-// run
-//
test/cases/optionals.2.zig
@@ -1,8 +0,0 @@
-pub fn main() u8 {
- var x: ?u8 = 5;
- _ = &x;
- return x.? - 5;
-}
-
-// run
-//
test/cases/optionals.3.zig
@@ -1,9 +0,0 @@
-pub fn main() u8 {
- var x: u8 = 5;
- var y: ?u8 = x;
- _ = .{ &x, &y };
- return y.? - 5;
-}
-
-// run
-//
test/cases/optionals.4.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var val: ?u8 = 5;
- while (val) |*v| {
- v.* -= 1;
- if (v.* == 2) {
- val = null;
- }
- }
- return 0;
-}
-
-// run
-//
test/cases/orelse_at_comptime.0.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const i: ?u64 = 0;
- const result = i orelse 5;
- assert(result == 0);
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/orelse_at_comptime.1.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const i: ?u64 = null;
- const result = i orelse 5;
- assert(result == 5);
-}
-fn assert(b: bool) void {
- if (!b) unreachable;
-}
-
-// run
-//
test/cases/parameters_and_return_values.0.zig
@@ -1,20 +0,0 @@
-const std = @import("std");
-
-pub fn main() void {
- print(id(14));
-}
-
-fn id(x: u32) u32 {
- return x;
-}
-
-fn print(len: u32) void {
- const str = "Hello, World!\n";
- _ = std.posix.write(1, str[0..len]) catch {};
-}
-
-// run
-// target=x86_64-macos
-//
-// Hello, World!
-//
test/cases/parameters_and_return_values.1.zig
@@ -1,14 +0,0 @@
-pub fn main() void {
- assert(add(1, 2, 3, 4, 5, 6) == 21);
-}
-
-fn add(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32) u32 {
- return a + b + c + d + e + f;
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/pointers.0.zig
@@ -1,14 +0,0 @@
-pub fn main() u8 {
- var x: u8 = 0;
-
- foo(&x);
- return x - 2;
-}
-
-fn foo(x: *u8) void {
- x.* = 2;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/pointers.1.zig
@@ -1,18 +0,0 @@
-pub fn main() u8 {
- var x: u8 = 0;
-
- foo(&x);
- bar(&x);
- return x - 4;
-}
-
-fn foo(x: *u8) void {
- x.* = 2;
-}
-
-fn bar(x: *u8) void {
- x.* += 2;
-}
-
-// run
-//
test/cases/redundant_comptime.0.zig
@@ -1,7 +0,0 @@
-pub fn main() void {
- var a: comptime u32 = 0;
-}
-
-// error
-//
-// :2:12: error: redundant comptime keyword in already comptime scope
test/cases/redundant_comptime.1.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- comptime {
- var a: u32 = comptime 0;
- }
-}
-
-// error
-//
-// :3:22: error: redundant comptime keyword in already comptime scope
test/cases/spilling_registers.0.zig
@@ -1,38 +0,0 @@
-pub fn main() void {
- assert(add(3, 4) == 791);
-}
-
-fn add(a: u32, b: u32) u32 {
- const x: u32 = blk: {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- const j = i + d; // 110
- const k = i + j; // 210
- const l = k + c; // 217
- const m = l + d; // 227
- const n = m + e; // 241
- const o = n + f; // 265
- const p = o + g; // 303
- const q = p + h; // 365
- const r = q + i; // 465
- const s = r + j; // 575
- const t = s + k; // 785
- break :blk t;
- };
- const y = x + a; // 788
- const z = y + a; // 791
- return z;
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-// target=x86_64-linux,x86_64-macos
-//
test/cases/spilling_registers.1.zig
@@ -1,37 +0,0 @@
-pub fn main() void {
- assert(addMul(3, 4) == 357747496);
-}
-
-fn addMul(a: u32, b: u32) u32 {
- const x: u32 = blk: {
- const c = a + b; // 7
- const d = a + c; // 10
- const e = d + b; // 14
- const f = d + e; // 24
- const g = e + f; // 38
- const h = f + g; // 62
- const i = g + h; // 100
- const j = i + d; // 110
- const k = i + j; // 210
- const l = k + c; // 217
- const m = l * d; // 2170
- const n = m + e; // 2184
- const o = n * f; // 52416
- const p = o + g; // 52454
- const q = p * h; // 3252148
- const r = q + i; // 3252248
- const s = r * j; // 357747280
- const t = s + k; // 357747490
- break :blk t;
- };
- const y = x + a; // 357747493
- const z = y + a; // 357747496
- return z;
-}
-
-fn assert(ok: bool) void {
- if (!ok) unreachable;
-}
-
-// run
-//
test/cases/structs.0.zig
@@ -1,11 +0,0 @@
-const Example = struct { x: u8 };
-
-pub fn main() u8 {
- var example: Example = .{ .x = 5 };
- _ = &example;
- return example.x - 5;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/structs.1.zig
@@ -1,10 +0,0 @@
-const Example = struct { x: u8 };
-
-pub fn main() u8 {
- var example: Example = .{ .x = 5 };
- example.x = 10;
- return example.x - 10;
-}
-
-// run
-//
test/cases/structs.2.zig
@@ -1,10 +0,0 @@
-const Example = struct { x: u8, y: u8 };
-
-pub fn main() u8 {
- var example: Example = .{ .x = 5, .y = 10 };
- _ = &example;
- return example.y + example.x - 15;
-}
-
-// run
-//
test/cases/structs.3.zig
@@ -1,13 +0,0 @@
-const Example = struct { x: u8, y: u8 };
-
-pub fn main() u8 {
- var example: Example = .{ .x = 5, .y = 10 };
- var example2: Example = .{ .x = 10, .y = 20 };
- _ = &example2;
-
- example = example2;
- return example.y + example.x - 30;
-}
-
-// run
-//
test/cases/structs.4.zig
@@ -1,11 +0,0 @@
-const Example = struct { x: u8, y: u8 };
-
-pub fn main() u8 {
- var example: Example = .{ .x = 5, .y = 10 };
-
- example = .{ .x = 10, .y = 20 };
- return example.y + example.x - 30;
-}
-
-// run
-//
test/cases/switch.0.zig
@@ -1,16 +0,0 @@
-pub fn main() u8 {
- var val: u8 = 1;
- _ = &val;
- const a: u8 = switch (val) {
- 0, 1 => 2,
- 2 => 3,
- 3 => 4,
- else => 5,
- };
-
- return a - 2;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/switch.1.zig
@@ -1,16 +0,0 @@
-pub fn main() u8 {
- var val: u8 = 2;
- _ = &val;
- var a: u8 = switch (val) {
- 0, 1 => 2,
- 2 => 3,
- 3 => 4,
- else => 5,
- };
- _ = &a;
-
- return a - 3;
-}
-
-// run
-//
test/cases/switch.2.zig
@@ -1,15 +0,0 @@
-pub fn main() u8 {
- var val: u8 = 10;
- _ = &val;
- const a: u8 = switch (val) {
- 0, 1 => 2,
- 2 => 3,
- 3 => 4,
- else => 5,
- };
-
- return a - 5;
-}
-
-// run
-//
test/cases/switch.3.zig
@@ -1,16 +0,0 @@
-const MyEnum = enum { One, Two, Three };
-
-pub fn main() u8 {
- var val: MyEnum = .Two;
- _ = &val;
- const a: u8 = switch (val) {
- .One => 1,
- .Two => 2,
- .Three => 3,
- };
-
- return a - 2;
-}
-
-// run
-//
test/cases/type_of.0.zig
@@ -1,13 +0,0 @@
-pub fn main() void {
- var x: usize = 0;
- _ = &x;
- const z = @TypeOf(x, @as(u128, 5));
- assert(z == u128);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/type_of.1.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- const z = @TypeOf(true);
- assert(z == bool);
-}
-
-pub fn assert(ok: bool) void {
- if (!ok) unreachable; // assertion failure
-}
-
-// run
-//
test/cases/type_of.2.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- _ = @TypeOf(true, 1);
-}
-
-// error
-//
-// :2:9: error: incompatible types: 'bool' and 'comptime_int'
-// :2:17: note: type 'bool' here
-// :2:23: note: type 'comptime_int' here
test/cases/unused_labels.0.zig
@@ -1,8 +0,0 @@
-comptime {
- foo: {}
-}
-
-// error
-// output_mode=Exe
-//
-// :2:5: error: unused block label
test/cases/unused_labels.1.zig
@@ -1,7 +0,0 @@
-comptime {
- foo: while (true) {}
-}
-
-// error
-//
-// :2:5: error: unused while loop label
test/cases/unused_labels.2.zig
@@ -1,7 +0,0 @@
-comptime {
- foo: for ("foo") |_| {}
-}
-
-// error
-//
-// :2:5: error: unused for loop label
test/cases/unused_labels.3.zig
@@ -1,10 +0,0 @@
-comptime {
- blk: {
- blk: {}
- }
-}
-
-// error
-//
-// :2:11: error: redefinition of label 'blk'
-// :2:5: note: previous definition here
test/cases/variable_shadowing.0.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- var i: u32 = 10;
- var i: u32 = 10;
-}
-
-// error
-// backend=stage2
-// target=x86_64-linux,x86_64-macos
-//
-// :3:9: error: redeclaration of local variable 'i'
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.1.zig
@@ -1,9 +0,0 @@
-var testing: i64 = 10;
-pub fn main() void {
- var testing: i64 = 20;
-}
-
-// error
-//
-// :3:9: error: local variable shadows declaration of 'testing'
-// :1:1: note: declared here
test/cases/variable_shadowing.10.zig
@@ -1,9 +0,0 @@
-fn foo() !void {
- var i: anyerror!usize = 1;
- _ = i catch |i| return i;
-}
-
-// error
-//
-// :3:18: error: redeclaration of local variable 'i'
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.2.zig
@@ -1,13 +0,0 @@
-fn a() type {
- return struct {
- pub fn b() void {
- const c = 6;
- const c = 69;
- }
- };
-}
-
-// error
-//
-// :5:19: error: redeclaration of local constant 'c'
-// :4:19: note: previous declaration here
test/cases/variable_shadowing.3.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i = 0;
- for ("n", 0..) |_, i| {}
-}
-
-// error
-//
-// :3:24: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.4.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i = 0;
- for ("n") |i| {}
-}
-
-// error
-//
-// :3:16: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.5.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i = 0;
- while ("n") |i| {}
-}
-
-// error
-//
-// :3:18: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.6.zig
@@ -1,11 +0,0 @@
-pub fn main() void {
- var i = 0;
- while ("n") |bruh| {
- _ = bruh;
- } else |i| {}
-}
-
-// error
-//
-// :5:13: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.7.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i = 0;
- if (true) |i| {}
-}
-
-// error
-//
-// :3:16: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.8.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i = 0;
- if (true) |i| {} else |e| {}
-}
-
-// error
-//
-// :3:16: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/variable_shadowing.9.zig
@@ -1,9 +0,0 @@
-pub fn main() void {
- var i = 0;
- if (true) |_| {} else |i| {}
-}
-
-// error
-//
-// :3:28: error: capture 'i' shadows local variable from outer scope
-// :2:9: note: previous declaration here
test/cases/while_loops.0.zig
@@ -1,12 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 0;
- while (i < @as(u8, 5)) {
- i += 1;
- }
-
- return i - 5;
-}
-
-// run
-// target=wasm32-wasi
-//
test/cases/while_loops.1.zig
@@ -1,12 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 0;
- while (i < @as(u8, 10)) {
- var x: u8 = 1;
- _ = &x;
- i += x;
- }
- return i - 10;
-}
-
-// run
-//
test/cases/while_loops.2.zig
@@ -1,13 +0,0 @@
-pub fn main() u8 {
- var i: u8 = 0;
- while (i < @as(u8, 10)) {
- var x: u8 = 1;
- _ = &x;
- i += x;
- if (i == @as(u8, 5)) break;
- }
- return i - 5;
-}
-
-// run
-//
test/incremental/change_fn_type
@@ -0,0 +1,35 @@
+#target=x86_64-linux-selfhosted
+#target=x86_64-linux-cbe
+#target=x86_64-windows-cbe
+#update=initial version
+#file=main.zig
+pub fn main() !void {
+ try foo(123);
+}
+fn foo(x: u8) !void {
+ return std.io.getStdOut().writer().print("{d}\n", .{x});
+}
+const std = @import("std");
+#expect_stdout="123\n"
+
+#update=change function type
+#file=main.zig
+pub fn main() !void {
+ try foo(123);
+}
+fn foo(x: i64) !void {
+ return std.io.getStdOut().writer().print("{d}\n", .{x});
+}
+const std = @import("std");
+#expect_stdout="123\n"
+
+#update=change function argument
+#file=main.zig
+pub fn main() !void {
+ try foo(-42);
+}
+fn foo(x: i64) !void {
+ return std.io.getStdOut().writer().print("{d}\n", .{x});
+}
+const std = @import("std");
+#expect_stdout="-42\n"
test/incremental/change_struct_same_fields
@@ -0,0 +1,50 @@
+#target=x86_64-linux-selfhosted
+#target=x86_64-linux-cbe
+#target=x86_64-windows-cbe
+#update=initial version
+#file=main.zig
+const S = extern struct { x: u8, y: u8 };
+pub fn main() !void {
+ const val: S = .{ .x = 100, .y = 200 };
+ try foo(&val);
+}
+fn foo(val: *const S) !void {
+ try std.io.getStdOut().writer().print(
+ "{d} {d}\n",
+ .{ val.x, val.y },
+ );
+}
+const std = @import("std");
+#expect_stdout="100 200\n"
+
+#update=change struct layout
+#file=main.zig
+const S = extern struct { x: u32, y: u32 };
+pub fn main() !void {
+ const val: S = .{ .x = 100, .y = 200 };
+ try foo(&val);
+}
+fn foo(val: *const S) !void {
+ try std.io.getStdOut().writer().print(
+ "{d} {d}\n",
+ .{ val.x, val.y },
+ );
+}
+const std = @import("std");
+#expect_stdout="100 200\n"
+
+#update=change values
+#file=main.zig
+const S = extern struct { x: u32, y: u32 };
+pub fn main() !void {
+ const val: S = .{ .x = 1234, .y = 5678 };
+ try foo(&val);
+}
+fn foo(val: *const S) !void {
+ try std.io.getStdOut().writer().print(
+ "{d} {d}\n",
+ .{ val.x, val.y },
+ );
+}
+const std = @import("std");
+#expect_stdout="1234 5678\n"
test/incremental/compile_error_then_log
@@ -0,0 +1,21 @@
+#target=x86_64-linux-selfhosted
+#target=x86_64-linux-cbe
+#target=x86_64-windows-cbe
+#update=initial version with compile error
+#file=main.zig
+comptime {
+ @compileError("this is an error");
+}
+comptime {
+ @compileLog("this is a log");
+}
+#expect_error=ignored
+#update=remove the compile error
+#file=main.zig
+comptime {
+ //@compileError("this is an error");
+}
+comptime {
+ @compileLog("this is a log");
+}
+#expect_error=ignored
test/incremental/function_becomes_inline
@@ -0,0 +1,35 @@
+//#target=x86_64-linux-selfhosted
+#target=x86_64-linux-cbe
+#target=x86_64-windows-cbe
+#update=non-inline version
+#file=main.zig
+pub fn main() !void {
+ try foo();
+}
+fn foo() !void {
+ try std.io.getStdOut().writer().writeAll("Hello, World!\n");
+}
+const std = @import("std");
+#expect_stdout="Hello, World!\n"
+
+#update=make function inline
+#file=main.zig
+pub fn main() !void {
+ try foo();
+}
+inline fn foo() !void {
+ try std.io.getStdOut().writer().writeAll("Hello, World!\n");
+}
+const std = @import("std");
+#expect_stdout="Hello, World!\n"
+
+#update=change string
+#file=main.zig
+pub fn main() !void {
+ try foo();
+}
+inline fn foo() !void {
+ try std.io.getStdOut().writer().writeAll("Hello, `inline` World!\n");
+}
+const std = @import("std");
+#expect_stdout="Hello, `inline` World!\n"
test/incremental/recursive_function_becomes_non_recursive
@@ -0,0 +1,28 @@
+//#target=x86_64-linux-selfhosted
+#target=x86_64-linux-cbe
+#target=x86_64-windows-cbe
+#update=initial version
+#file=main.zig
+pub fn main() !void {
+ try foo(false);
+}
+fn foo(recurse: bool) !void {
+ const stdout = std.io.getStdOut().writer();
+ if (recurse) return foo(true);
+ try stdout.writeAll("non-recursive path\n");
+}
+const std = @import("std");
+#expect_stdout="non-recursive path\n"
+
+#update=eliminate recursion and change argument
+#file=main.zig
+pub fn main() !void {
+ try foo(true);
+}
+fn foo(recurse: bool) !void {
+ const stdout = std.io.getStdOut().writer();
+ if (recurse) return stdout.writeAll("x==1\n");
+ try stdout.writeAll("non-recursive path\n");
+}
+const std = @import("std");
+#expect_stdout="x==1\n"