authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-27 15:37:54+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-04-28 18:35:01+02:00
log97b781955eca7c3fc6ee2713f8b5e355645fff58
tree36bef811176a694d1071b4957c622d42ffd97a52
parent133708d9396defc46630adc6acd24a493277b7d5

test: fix incorrect default target spec; port all incremental tests


102 files changed, 1360 insertions(+), 1 deletions(-)

src/test.zig+1-1
......@@ -178,7 +178,7 @@ const TestManifestConfigDefaults = struct {
178178 // getting more and more complete
179179 // Linux
180180 inline for (&[_][]const u8{ "x86_64", "arm", "aarch64" }) |arch| {
181 defaults = defaults ++ arch ++ "-linux-" ++ ",";
181 defaults = defaults ++ arch ++ "-linux" ++ ",";
182182 }
183183 // macOS
184184 inline for (&[_][]const u8{ "x86_64", "aarch64" }) |arch| {
test/incremental/access_slice_element_by_index_slice_elem_val.zig created+17
......@@ -0,0 +1,17 @@
1var array = [_]usize{ 0, 42, 123, 34 };
2var slice: []const usize = &array;
3
4pub fn main() void {
5 assert(slice[0] == 0);
6 assert(slice[1] == 42);
7 assert(slice[2] == 123);
8 assert(slice[3] == 34);
9}
10
11fn assert(ok: bool) void {
12 if (!ok) unreachable;
13}
14
15// run
16// target=x86_64-linux,x86_64-macos
17//
test/incremental/ambiguous_reference.zig created+13
......@@ -0,0 +1,13 @@
1const T = struct {
2 const T = struct {
3 fn f() void {
4 _ = T;
5 }
6 };
7};
8
9// error
10//
11// :4:17: error: ambiguous reference
12// :2:5: note: declared here
13// :1:1: note: also declared here
test/incremental/bad_inferred_variable_type.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var x = null;
3 _ = x;
4}
5
6// error
7// output_mode=Exe
8//
9// :2:9: error: variable of type '@TypeOf(null)' must be const or comptime
test/incremental/break_continue.0.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 while (true) {
3 break;
4 }
5}
6
7// run
8// target=x86_64-linux,x86_64-macos,aarch64-linux,aarch64-macos
9//
test/incremental/break_continue.1.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 foo: while (true) {
3 break :foo;
4 }
5}
6
7// run
8//
test/incremental/break_continue.2.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u64 = 0;
3 while (true) : (i += 1) {
4 if (i == 4) return;
5 continue;
6 }
7}
8
9// run
10//
test/incremental/break_continue.3.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u64 = 0;
3 foo: while (true) : (i += 1) {
4 if (i == 4) return;
5 continue :foo;
6 }
7}
8
9// run
10//
test/incremental/catch_at_comptime.0.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: anyerror!u64 = 0;
3 const caught = i catch 5;
4 assert(caught == 0);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/catch_at_comptime.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: anyerror!u64 = error.B;
3 const caught = i catch 5;
4 assert(caught == 5);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/catch_at_comptime.2.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const a: anyerror!comptime_int = 42;
3 const b: *const comptime_int = &(a catch unreachable);
4 assert(b.* == 42);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/catch_at_comptime.3.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 const a: anyerror!u32 = error.B;
3 _ = &(a catch |err| assert(err == error.B));
4}
5fn assert(b: bool) void {
6 if (!b) unreachable;
7}
8
9// run
10//
test/incremental/catch_at_comptime.4.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 const a: anyerror!u32 = error.Bar;
3 a catch |err| assert(err == error.Bar);
4}
5fn assert(b: bool) void {
6 if (!b) unreachable;
7}
8
9// run
10//
test/incremental/compile_error.zig created+7
......@@ -0,0 +1,7 @@
1export fn foo() void {
2 @compileError("this is an error");
3}
4
5// error
6//
7// :2:5: error: this is an error
test/incremental/compile_error_in_inline_fn_call_fixed.0.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 var x: usize = 3;
3 const y = add(10, 2, x);
4 if (y - 6 != 0) unreachable;
5}
6
7inline fn add(a: usize, b: usize, c: usize) usize {
8 if (a == 10) @compileError("bad");
9 return a + b + c;
10}
11
12// error
13// output_mode=Exe
14//
15// :8:18: error: bad
16// :3:18: note: called from here
test/incremental/compile_error_in_inline_fn_call_fixed.1.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() void {
2 var x: usize = 3;
3 const y = add(1, 2, x);
4 if (y - 6 != 0) unreachable;
5}
6
7inline fn add(a: usize, b: usize, c: usize) usize {
8 if (a == 10) @compileError("bad");
9 return a + b + c;
10}
11
12// run
13//
test/incremental/compile_log.0.zig created+17
......@@ -0,0 +1,17 @@
1export fn _start() noreturn {
2 const b = true;
3 var f: u32 = 1;
4 @compileLog(b, 20, f, x);
5 @compileLog(1000);
6 var bruh: usize = true;
7 _ = bruh;
8 unreachable;
9}
10export fn other() void {
11 @compileLog(1234);
12}
13fn x() void {}
14
15// error
16//
17// :6:23: error: expected usize, found bool
test/incremental/compile_log.1.zig created+16
......@@ -0,0 +1,16 @@
1export fn _start() noreturn {
2 const b = true;
3 var f: u32 = 1;
4 @compileLog(b, 20, f, x);
5 @compileLog(1000);
6 unreachable;
7}
8export fn other() void {
9 @compileLog(1234);
10}
11fn x() void {}
12
13// error
14//
15// :9:5: error: found compile log statement
16// :4:5: note: also here
test/incremental/comptime_var.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 var a: u32 = 0;
3 comptime var b: u32 = 0;
4 if (a == 0) b = 3;
5}
6
7// error
8// output_mode=Exe
9// target=x86_64-linux,x86_64-macos
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/incremental/comptime_var.1.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() void {
2 var a: u32 = 0;
3 comptime var b: u32 = 0;
4 switch (a) {
5 0 => {},
6 else => b = 3,
7 }
8}
9
10// error
11//
12// :6:21: error: store to comptime variable depends on runtime condition
13// :4:13: note: runtime condition here
test/incremental/comptime_var.2.zig created+34
......@@ -0,0 +1,34 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 comptime var len: u32 = 5;
7 print(len);
8 len += 9;
9 print(len);
10}
11
12fn print(len: usize) void {
13 switch (builtin.os.tag) {
14 .linux => {
15 asm volatile ("syscall"
16 :
17 : [number] "{rax}" (1),
18 [arg1] "{rdi}" (1),
19 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
20 [arg3] "{rdx}" (len),
21 : "rcx", "r11", "memory"
22 );
23 },
24 .macos => {
25 _ = write(1, @ptrToInt("Hello, World!\n"), len);
26 },
27 else => unreachable,
28 }
29}
30
31// run
32//
33// HelloHello, World!
34//
test/incremental/comptime_var.3.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var x: i32 = 1;
3 x += 1;
4 if (x != 1) unreachable;
5}
6pub fn main() void {}
7
8// error
9//
10// :4:17: error: unable to resolve comptime value
test/incremental/comptime_var.4.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 comptime var i: u64 = 0;
3 while (i < 5) : (i += 1) {}
4}
5
6// error
7//
8// :3:24: error: cannot store to comptime variable in non-inline loop
9// :3:5: note: non-inline loop here
test/incremental/comptime_var.5.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 var a: u32 = 0;
3 if (a == 0) {
4 comptime var b: u32 = 0;
5 b = 1;
6 }
7}
8comptime {
9 var x: i32 = 1;
10 x += 1;
11 if (x != 2) unreachable;
12}
13
14// run
15//
test/incremental/comptime_var.6.zig created+32
......@@ -0,0 +1,32 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 comptime var i: u64 = 2;
7 inline while (i < 6) : (i += 1) {
8 print(i);
9 }
10}
11fn print(len: usize) void {
12 switch (builtin.os.tag) {
13 .linux => {
14 asm volatile ("syscall"
15 :
16 : [number] "{rax}" (1),
17 [arg1] "{rdi}" (1),
18 [arg2] "{rsi}" (@ptrToInt("Hello")),
19 [arg3] "{rdx}" (len),
20 : "rcx", "r11", "memory"
21 );
22 },
23 .macos => {
24 _ = write(1, @ptrToInt("Hello"), len);
25 },
26 else => unreachable,
27 }
28}
29
30// run
31//
32// HeHelHellHello
test/incremental/double_ampersand.0.zig created+6
......@@ -0,0 +1,6 @@
1pub const a = if (true && false) 1 else 2;
2
3// error
4// output_mode=Exe
5//
6// :1:24: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/incremental/double_ampersand.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const a = true;
3 const b = false;
4 _ = a & &b;
5}
6
7// error
8//
9// :4:11: error: incompatible types: 'bool' and '*const bool'
10// :4:9: note: type 'bool' here
11// :4:13: note: type '*const bool' here
test/incremental/double_ampersand.2.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() void {
2 const b: u8 = 1;
3 _ = &&b;
4}
5
6// run
7//
test/incremental/extern_variable_has_no_type.0.zig created+9
......@@ -0,0 +1,9 @@
1comptime {
2 const x = foo + foo;
3 _ = x;
4}
5extern var foo: i32;
6
7// error
8//
9// :2:15: error: unable to resolve comptime value
test/incremental/extern_variable_has_no_type.1.zig created+8
......@@ -0,0 +1,8 @@
1export fn entry() void {
2 _ = foo;
3}
4extern var foo;
5
6// error
7//
8// :4:8: error: unable to infer variable type
test/incremental/function_redeclaration.zig created+14
......@@ -0,0 +1,14 @@
1// dummy comment
2fn entry() void {}
3fn entry() void {}
4
5fn foo() void {
6 var foo = 1234;
7}
8
9// error
10//
11// :3:1: error: redeclaration of 'entry'
12// :2:1: note: other declaration here
13// :6:9: error: local shadows declaration of 'foo'
14// :5:1: note: declared here
test/incremental/global_variable_redeclaration.zig created+8
......@@ -0,0 +1,8 @@
1// dummy comment
2var foo = false;
3var foo = true;
4
5// error
6//
7// :3:1: error: redeclaration of 'foo'
8// :2:1: note: other declaration here
test/incremental/hello_world_with_updates_x86_64_linux.0.zig created+5
......@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=x86_64-linux
4//
5// :109:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/hello_world_with_updates_x86_64_linux.1.zig created+5
......@@ -0,0 +1,5 @@
1pub export fn _start() noreturn {}
2
3// error
4//
5// :1:34: error: expected noreturn, found void
test/incremental/hello_world_with_updates_x86_64_linux.2.zig created+32
......@@ -0,0 +1,32 @@
1pub export fn _start() noreturn {
2 print();
3
4 exit();
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
13 [arg3] "{rdx}" (14),
14 : "rcx", "r11", "memory"
15 );
16 return;
17}
18
19fn exit() noreturn {
20 asm volatile ("syscall"
21 :
22 : [number] "{rax}" (231),
23 [arg1] "{rdi}" (0),
24 : "rcx", "r11", "memory"
25 );
26 unreachable;
27}
28
29// run
30//
31// Hello, World!
32//
test/incremental/hello_world_with_updates_x86_64_linux.3.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("syscall"
7 :
8 : [number] "{rax}" (1),
9 [arg1] "{rdi}" (1),
10 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
11 [arg3] "{rdx}" (14),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18//
19// Hello, World!
20//
test/incremental/hello_world_with_updates_x86_64_linux.4.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("syscall"
7 :
8 : [number] "{rax}" (1),
9 [arg1] "{rdi}" (1),
10 [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
11 [arg3] "{rdx}" (104),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18//
19// What is up? This is a longer message that will force the data to be relocated in virtual address space.
20//
test/incremental/hello_world_with_updates_x86_64_linux.5.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("syscall"
8 :
9 : [number] "{rax}" (1),
10 [arg1] "{rdi}" (1),
11 [arg2] "{rsi}" (@ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n")),
12 [arg3] "{rdx}" (104),
13 : "rcx", "r11", "memory"
14 );
15 return;
16}
17
18// run
19//
20// What is up? This is a longer message that will force the data to be relocated in virtual address space.
21// What is up? This is a longer message that will force the data to be relocated in virtual address space.
22//
test/incremental/hello_world_with_updates_x86_64_macos.0.zig created+5
......@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=x86_64-macos
4//
5// :109:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/hello_world_with_updates_x86_64_macos.1.zig created+5
......@@ -0,0 +1,5 @@
1pub export fn main() noreturn {}
2
3// error
4//
5// :1:32: error: expected noreturn, found void
test/incremental/hello_world_with_updates_x86_64_macos.2.zig created+19
......@@ -0,0 +1,19 @@
1extern "c" fn write(usize, usize, usize) usize;
2extern "c" fn exit(usize) noreturn;
3
4pub export fn main() noreturn {
5 print();
6
7 exit(0);
8}
9
10fn print() void {
11 const msg = @ptrToInt("Hello, World!\n");
12 const len = 14;
13 _ = write(1, msg, len);
14}
15
16// run
17//
18// Hello, World!
19//
test/incremental/hello_world_with_updates_x86_64_macos.3.zig created+16
......@@ -0,0 +1,16 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5}
6
7fn print() void {
8 const msg = @ptrToInt("Hello, World!\n");
9 const len = 14;
10 _ = write(1, msg, len);
11}
12
13// run
14//
15// Hello, World!
16//
test/incremental/hello_world_with_updates_x86_64_macos.4.zig created+22
......@@ -0,0 +1,22 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5 print();
6 print();
7 print();
8}
9
10fn print() void {
11 const msg = @ptrToInt("Hello, World!\n");
12 const len = 14;
13 _ = write(1, msg, len);
14}
15
16// run
17//
18// Hello, World!
19// Hello, World!
20// Hello, World!
21// Hello, World!
22//
test/incremental/hello_world_with_updates_x86_64_macos.5.zig created+16
......@@ -0,0 +1,16 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5}
6
7fn print() void {
8 const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
9 const len = 104;
10 _ = write(1, msg, len);
11}
12
13// run
14//
15// What is up? This is a longer message that will force the data to be relocated in virtual address space.
16//
test/incremental/hello_world_with_updates_x86_64_macos.6.zig created+18
......@@ -0,0 +1,18 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 print();
5 print();
6}
7
8fn print() void {
9 const msg = @ptrToInt("What is up? This is a longer message that will force the data to be relocated in virtual address space.\n");
10 const len = 104;
11 _ = write(1, msg, len);
12}
13
14// run
15//
16// What is up? This is a longer message that will force the data to be relocated in virtual address space.
17// What is up? This is a longer message that will force the data to be relocated in virtual address space.
18//
test/incremental/inline_assembly_x86_64_linux.0.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 const number = 1234;
3 const x = asm volatile ("syscall"
4 : [o] "{rax}" (-> number),
5 : [number] "{rax}" (231),
6 [arg1] "{rdi}" (60),
7 : "rcx", "r11", "memory"
8 );
9 _ = x;
10}
11
12// error
13// output_mode=Exe
14// target=x86_64-linux
15//
16// :4:27: error: expected type, found comptime_int
test/incremental/inline_assembly_x86_64_linux.1.zig created+15
......@@ -0,0 +1,15 @@
1const S = struct {
2 comptime {
3 asm volatile (
4 \\zig_moment:
5 \\syscall
6 );
7 }
8};
9pub fn main() void {
10 _ = S;
11}
12
13// error
14//
15// :3:13: error: volatile is meaningless on global assembly
test/incremental/inline_assembly_x86_64_linux.2.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 var bruh: u32 = 1;
3 asm (""
4 :
5 : [bruh] "{rax}" (4)
6 : "memory"
7 );
8}
9
10// error
11//
12// :3:5: error: assembly expression with no output must be marked volatile
test/incremental/inline_assembly_x86_64_linux.3.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {}
2comptime {
3 asm (""
4 :
5 : [bruh] "{rax}" (4)
6 : "memory"
7 );
8}
9
10// error
11//
12// :3:5: error: global assembly cannot have inputs, outputs, or clobbers
test/incremental/inner_func_accessing_outer_var.zig created+15
......@@ -0,0 +1,15 @@
1pub fn f() void {
2 var bar: bool = true;
3 const S = struct {
4 fn baz() bool {
5 return bar;
6 }
7 };
8 _ = S;
9}
10
11// error
12//
13// :5:20: error: mutable 'bar' not accessible from here
14// :2:9: note: declared mutable here
15// :3:15: note: crosses namespace boundary here
test/incremental/int_to_ptr.0.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 _ = @intToPtr(*u8, 0);
3}
4
5// error
6// output_mode=Exe
7//
8// :2:24: error: pointer type '*u8' does not allow address zero
test/incremental/int_to_ptr.1.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() void {
2 _ = @intToPtr(*u32, 2);
3}
4
5// error
6//
7// :2:25: error: pointer type '*u32' requires aligned address
test/incremental/issue_10138_callee_preserved_regs_working_x86_64_linux.zig created+31
......@@ -0,0 +1,31 @@
1pub fn main() void {
2 const fd = open();
3 _ = write(fd, "a", 1);
4 _ = close(fd);
5}
6
7fn open() usize {
8 return 42;
9}
10
11fn write(fd: usize, a: [*]const u8, len: usize) usize {
12 return syscall4(.WRITE, fd, @ptrToInt(a), len);
13}
14
15fn syscall4(n: enum { WRITE }, a: usize, b: usize, c: usize) usize {
16 _ = n;
17 _ = a;
18 _ = b;
19 _ = c;
20 return 23;
21}
22
23fn close(fd: usize) usize {
24 if (fd != 42)
25 unreachable;
26 return 0;
27}
28
29// run
30// target=x86_64-linux
31//
test/incremental/issue_7187_miscompilation_with_bool_return_type.zig created+18
......@@ -0,0 +1,18 @@
1pub fn main() void {
2 var x: usize = 1;
3 var y: bool = getFalse();
4 _ = y;
5
6 assert(x == 1);
7}
8
9fn getFalse() bool {
10 return false;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18//
test/incremental/load_store_via_pointer_deref.0.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 var x: u32 = undefined;
3 set(&x);
4 assert(x == 123);
5}
6
7fn set(x: *u32) void {
8 x.* = 123;
9}
10
11fn assert(ok: bool) void {
12 if (!ok) unreachable;
13}
14
15// run
16//
test/incremental/load_store_via_pointer_deref.1.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 var x: u16 = undefined;
3 set(&x);
4 assert(x == 123);
5}
6
7fn set(x: *u16) void {
8 x.* = 123;
9}
10
11fn assert(ok: bool) void {
12 if (!ok) unreachable;
13}
14
15// run
16//
test/incremental/load_store_via_pointer_deref.2.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 var x: u8 = undefined;
3 set(&x);
4 assert(x == 123);
5}
6
7fn set(x: *u8) void {
8 x.* = 123;
9}
10
11fn assert(ok: bool) void {
12 if (!ok) unreachable;
13}
14
15// run
16//
test/incremental/lower_unnamed_consts_structs.0.zig created+25
......@@ -0,0 +1,25 @@
1const Foo = struct {
2 a: u8,
3 b: u32,
4
5 fn first(self: *Foo) u8 {
6 return self.a;
7 }
8
9 fn second(self: *Foo) u32 {
10 return self.b;
11 }
12};
13
14pub fn main() void {
15 var foo = Foo{ .a = 1, .b = 5 };
16 assert(foo.first() == 1);
17 assert(foo.second() == 5);
18}
19
20fn assert(ok: bool) void {
21 if (!ok) unreachable;
22}
23
24// run
25//
test/incremental/lower_unnamed_consts_structs.1.zig created+35
......@@ -0,0 +1,35 @@
1const Foo = struct {
2 a: u8,
3 b: u32,
4
5 fn first(self: *Foo) u8 {
6 return self.a;
7 }
8
9 fn second(self: *Foo) u32 {
10 return self.b;
11 }
12};
13
14pub fn main() void {
15 var foo = Foo{ .a = 1, .b = 5 };
16 assert(foo.first() == 1);
17 assert(foo.second() == 5);
18
19 foo.a = 10;
20 foo.b = 255;
21
22 assert(foo.first() == 10);
23 assert(foo.second() == 255);
24
25 var foo2 = Foo{ .a = 15, .b = 255 };
26 assert(foo2.first() == 15);
27 assert(foo2.second() == 255);
28}
29
30fn assert(ok: bool) void {
31 if (!ok) unreachable;
32}
33
34// run
35//
test/incremental/lower_unnamed_consts_structs.2.zig created+25
......@@ -0,0 +1,25 @@
1const Foo = struct {
2 a: u8,
3 b: u32,
4
5 fn first(self: *Foo) u8 {
6 return self.a;
7 }
8
9 fn second(self: *Foo) u32 {
10 return self.b;
11 }
12};
13
14pub fn main() void {
15 var foo2 = Foo{ .a = 15, .b = 255 };
16 assert(foo2.first() == 15);
17 assert(foo2.second() == 255);
18}
19
20fn assert(ok: bool) void {
21 if (!ok) unreachable;
22}
23
24// run
25//
test/incremental/merge_error_sets.0.zig created+18
......@@ -0,0 +1,18 @@
1pub fn main() void {
2 const E = error{ A, B, D } || error{ A, B, C };
3 E.A catch {};
4 E.B catch {};
5 E.C catch {};
6 E.D catch {};
7 const E2 = error{ X, Y } || @TypeOf(error.Z);
8 E2.X catch {};
9 E2.Y catch {};
10 E2.Z catch {};
11 assert(anyerror || error{Z} == anyerror);
12}
13fn assert(b: bool) void {
14 if (!b) unreachable;
15}
16
17// run
18//
test/incremental/merge_error_sets.1.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 const z = true || false;
3 _ = z;
4}
5
6// error
7//
8// :2:15: error: expected error set type, found 'bool'
9// :2:20: note: '||' merges error sets; 'or' performs boolean OR
test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.0.zig created+13
......@@ -0,0 +1,13 @@
1pub export fn _start() noreturn {
2 asm volatile ("syscall"
3 :
4 : [number] "{rax}" (60), // exit
5 [arg1] "{rdi}" (0),
6 : "rcx", "r11", "memory"
7 );
8 unreachable;
9}
10
11// run
12// target=x86_64-linux
13//
test/incremental/only_1_function_and_it_gets_updated_x86_64_linux.1.zig created+12
......@@ -0,0 +1,12 @@
1pub export fn _start() noreturn {
2 asm volatile ("syscall"
3 :
4 : [number] "{rax}" (231), // exit_group
5 [arg1] "{rdi}" (0),
6 : "rcx", "r11", "memory"
7 );
8 unreachable;
9}
10
11// run
12//
test/incremental/optional_payload.0.zig created+19
......@@ -0,0 +1,19 @@
1pub fn main() void {
2 var x: u32 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x != null);
5 maybe_x.?.* = 123;
6 assert(x == 123);
7}
8
9fn byPtr(x: *u32) ?*u32 {
10 return x;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18// target=x86_64-linux,x86_64-macos
19//
test/incremental/optional_payload.1.zig created+17
......@@ -0,0 +1,17 @@
1pub fn main() void {
2 var x: u32 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x == null);
5}
6
7fn byPtr(x: *u32) ?*u32 {
8 _ = x;
9 return null;
10}
11
12fn assert(ok: bool) void {
13 if (!ok) unreachable;
14}
15
16// run
17//
test/incremental/optional_payload.2.zig created+18
......@@ -0,0 +1,18 @@
1pub fn main() void {
2 var x: u8 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x != null);
5 maybe_x.?.* = 255;
6 assert(x == 255);
7}
8
9fn byPtr(x: *u8) ?*u8 {
10 return x;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18//
test/incremental/optional_payload.3.zig created+18
......@@ -0,0 +1,18 @@
1pub fn main() void {
2 var x: i8 = undefined;
3 const maybe_x = byPtr(&x);
4 assert(maybe_x != null);
5 maybe_x.?.* = -1;
6 assert(x == -1);
7}
8
9fn byPtr(x: *i8) ?*i8 {
10 return x;
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18//
test/incremental/orelse_at_comptime.0.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: ?u64 = 0;
3 const result = i orelse 5;
4 assert(result == 0);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/orelse_at_comptime.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const i: ?u64 = null;
3 const result = i orelse 5;
4 assert(result == 5);
5}
6fn assert(b: bool) void {
7 if (!b) unreachable;
8}
9
10// run
11//
test/incremental/passing_u0_to_function.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 doNothing(0);
3}
4fn doNothing(arg: u0) void {
5 _ = arg;
6}
7
8// run
9//
test/incremental/recursive_inline_function.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 const y = fibonacci(7);
3 if (y - 21 != 0) unreachable;
4}
5
6inline fn fibonacci(n: usize) usize {
7 if (n <= 2) return n;
8 return fibonacci(n - 2) + fibonacci(n - 1);
9}
10
11// run
12//
test/incremental/recursive_inline_function.1.zig created+16
......@@ -0,0 +1,16 @@
1// This additionally tests that the compile error reports the correct source location.
2// Without storing source locations relative to the owner decl, the compile error
3// here would be off by 2 bytes (from the "7" -> "999").
4pub fn main() void {
5 const y = fibonacci(999);
6 if (y - 21 != 0) unreachable;
7}
8
9inline fn fibonacci(n: usize) usize {
10 if (n <= 2) return n;
11 return fibonacci(n - 2) + fibonacci(n - 1);
12}
13
14// error
15//
16// :11:21: error: evaluation exceeded 1000 backwards branches
test/incremental/redundant_comptime.0.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() void {
2 var a: comptime u32 = 0;
3}
4
5// error
6//
7// :2:12: error: redundant comptime keyword in already comptime scope
test/incremental/redundant_comptime.1.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 comptime {
3 var a: u32 = comptime 0;
4 }
5}
6
7// error
8//
9// :3:22: error: redundant comptime keyword in already comptime scope
test/incremental/returns_in_try.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() !void {
2 try a();
3 try b();
4}
5
6pub fn a() !void {
7 defer try b();
8}
9pub fn b() !void {
10 defer return a();
11}
12
13// error
14//
15// :7:11: error: 'try' not allowed inside defer expression
16// :10:11: error: cannot return from defer expression
test/incremental/runtime_bitwise_and.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 var i: u32 = 10;
3 var j: u32 = 11;
4 assert(i & 1 == 0);
5 assert(j & 1 == 1);
6 var m1: u32 = 0b1111;
7 var m2: u32 = 0b0000;
8 assert(m1 & 0b1010 == 0b1010);
9 assert(m2 & 0b1010 == 0b0000);
10}
11fn assert(b: bool) void {
12 if (!b) unreachable;
13}
14
15// run
16//
test/incremental/runtime_bitwise_or.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 var i: u32 = 10;
3 var j: u32 = 11;
4 assert(i | 1 == 11);
5 assert(j | 1 == 11);
6 var m1: u32 = 0b1111;
7 var m2: u32 = 0b0000;
8 assert(m1 | 0b1010 == 0b1111);
9 assert(m2 | 0b1010 == 0b1010);
10}
11fn assert(b: bool) void {
12 if (!b) unreachable;
13}
14
15// run
16//
test/incremental/saving_vars_of_different_abi_size_to_stack.0.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 assert(callMe(2) == 24);
3}
4
5fn callMe(a: u8) u8 {
6 var b: u8 = a + 10;
7 const c = 2 * b;
8 return c;
9}
10
11pub fn assert(ok: bool) void {
12 if (!ok) unreachable; // assertion failure
13}
14
15// run
16//
test/incremental/saving_vars_of_different_abi_size_to_stack.1.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 assert(callMe(2) == 24);
3}
4
5fn callMe(a: u16) u16 {
6 var b: u16 = a + 10;
7 const c = 2 * b;
8 return c;
9}
10
11pub fn assert(ok: bool) void {
12 if (!ok) unreachable; // assertion failure
13}
14
15// run
16//
test/incremental/saving_vars_of_different_abi_size_to_stack.2.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() void {
2 assert(callMe(2) == 24);
3}
4
5fn callMe(a: u32) u32 {
6 var b: u32 = a + 10;
7 const c = 2 * b;
8 return c;
9}
10
11pub fn assert(ok: bool) void {
12 if (!ok) unreachable; // assertion failure
13}
14
15// run
16//
test/incremental/setting_an_address_space_on_a_local_variable.zig created+8
......@@ -0,0 +1,8 @@
1export fn entry() i32 {
2 var foo: i32 addrspace(".general") = 1234;
3 return foo;
4}
5
6// error
7//
8// :2:28: error: cannot set address space of local variable 'foo'
test/incremental/try_in_comptime_in_struct_in_test.zig created+13
......@@ -0,0 +1,13 @@
1test "@unionInit on union w/ tag but no fields" {
2 const S = struct {
3 comptime {
4 try expect(false);
5 }
6 };
7 _ = S;
8}
9
10// error
11// is_test=1
12//
13// :4:13: error: 'try' outside function scope
test/incremental/type_of.0.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() void {
2 var x: usize = 0;
3 _ = x;
4 const z = @TypeOf(x, @as(u128, 5));
5 assert(z == u128);
6}
7
8pub fn assert(ok: bool) void {
9 if (!ok) unreachable; // assertion failure
10}
11
12// run
13//
test/incremental/type_of.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 const z = @TypeOf(true);
3 assert(z == bool);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/type_of.2.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 _ = @TypeOf(true, 1);
3}
4
5// error
6//
7// :2:9: error: incompatible types: 'bool' and 'comptime_int'
8// :2:17: note: type 'bool' here
9// :2:23: note: type 'comptime_int' here
test/incremental/unused_labels.0.zig created+8
......@@ -0,0 +1,8 @@
1comptime {
2 foo: {}
3}
4
5// error
6// output_mode=Exe
7//
8// :2:5: error: unused block label
test/incremental/unused_labels.1.zig created+7
......@@ -0,0 +1,7 @@
1comptime {
2 foo: while (true) {}
3}
4
5// error
6//
7// :2:5: error: unused while loop label
test/incremental/unused_labels.2.zig created+7
......@@ -0,0 +1,7 @@
1comptime {
2 foo: for ("foo") |_| {}
3}
4
5// error
6//
7// :2:5: error: unused for loop label
test/incremental/unused_labels.3.zig created+8
......@@ -0,0 +1,8 @@
1comptime {
2 blk: {blk: {}}
3}
4
5// error
6//
7// :2:11: error: redefinition of label 'blk'
8// :2:5: note: previous definition here
test/incremental/unwrap_error_union_simple_errors.0.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 maybeErr() catch unreachable;
3}
4
5fn maybeErr() !void {
6 return;
7}
8
9// run
10//
test/incremental/unwrap_error_union_simple_errors.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 maybeErr() catch return;
3 unreachable;
4}
5
6fn maybeErr() !void {
7 return error.NoWay;
8}
9
10// run
11//
test/incremental/variable_shadowing.0.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i: u32 = 10;
3 var i: u32 = 10;
4}
5
6// error
7//
8// :3:9: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/variable_shadowing.1.zig created+9
......@@ -0,0 +1,9 @@
1var testing: i64 = 10;
2pub fn main() void {
3 var testing: i64 = 20;
4}
5
6// error
7//
8// :3:9: error: local shadows declaration of 'testing'
9// :1:1: note: declared here
test/incremental/variable_shadowing.2.zig created+13
......@@ -0,0 +1,13 @@
1fn a() type {
2 return struct {
3 pub fn b() void {
4 const c = 6;
5 const c = 69;
6 }
7 };
8}
9
10// error
11//
12// :5:19: error: redeclaration of local constant 'c'
13// :4:19: note: previous declaration here
test/incremental/variable_shadowing.3.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i = 0;
3 for ("n") |_, i| {
4 }
5}
6
7// error
8//
9// :3:19: error: redeclaration of local variable 'i'
10// :2:9: note: previous declaration here
test/incremental/variable_shadowing.4.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i = 0;
3 for ("n") |i| {
4 }
5}
6
7// error
8//
9// :3:16: error: redeclaration of local variable 'i'
10// :2:9: note: previous declaration here
test/incremental/variable_shadowing.5.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i = 0;
3 while ("n") |i| {
4 }
5}
6
7// error
8//
9// :3:18: error: redeclaration of local variable 'i'
10// :2:9: note: previous declaration here
test/incremental/variable_shadowing.6.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() void {
2 var i = 0;
3 while ("n") |bruh| {
4 _ = bruh;
5 } else |i| {
6
7 }
8}
9
10// error
11//
12// :5:13: error: redeclaration of local variable 'i'
13// :2:9: note: previous declaration here
test/incremental/variable_shadowing.7.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i = 0;
3 if (true) |i| {}
4}
5
6// error
7//
8// :3:16: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/variable_shadowing.8.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i = 0;
3 if (true) |i| {} else |e| {}
4}
5
6// error
7//
8// :3:16: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here
test/incremental/variable_shadowing.9.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i = 0;
3 if (true) |_| {} else |i| {}
4}
5
6// error
7//
8// :3:28: error: redeclaration of local variable 'i'
9// :2:9: note: previous declaration here