authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-05-04 23:51:16+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-05-04 23:51:16+02:00
log3624e1ef485c3575cb0c57a312386f49daf7ad37
tree4d940b2b245e885448d8072f61fbc88074f57d1f
parent9d79b740bc981da9f336d5c72d1abe7d81e6ad9f

test: move compile errors and incremental tests into common dir


1902 files changed, 13850 insertions(+), 13863 deletions(-)

ci/zinc/linux_test.sh+1-1
......@@ -45,7 +45,7 @@ cd $WORKSPACE
4545
4646# Look for non-conforming code formatting.
4747# Formatting errors can be fixed by running `zig fmt` on the files printed here.
48$ZIG fmt --check . --exclude test/compile_errors/ --exclude test/incremental/
48$ZIG fmt --check . --exclude test/cases/
4949
5050# Build stage2 standalone so that we can test stage2 against stage2 compiler-rt.
5151$ZIG build -p stage2 -Dstatic-llvm -Dtarget=native-native-musl --search-prefix "$DEPS_LOCAL"
src/test.zig+1-14
......@@ -36,20 +36,7 @@ test {
3636
3737 {
3838 const dir_path = try std.fs.path.join(arena, &.{
39 std.fs.path.dirname(@src().file).?, "..", "test", "compile_errors",
40 });
41
42 var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
43 defer dir.close();
44
45 // TODO make this incremental once the bug is solved that it triggers
46 // See: https://github.com/ziglang/zig/issues/11344
47 ctx.addTestCasesFromDir(dir);
48 }
49
50 {
51 const dir_path = try std.fs.path.join(arena, &.{
52 std.fs.path.dirname(@src().file).?, "..", "test", "incremental",
39 std.fs.path.dirname(@src().file).?, "..", "test", "cases",
5340 });
5441
5542 var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
test/cases/aarch64-linux/conditional_branches.0.zig created+26
......@@ -0,0 +1,26 @@
1pub fn main() void {
2 foo(123);
3}
4
5fn foo(x: u64) void {
6 if (x > 42) {
7 print();
8 }
9}
10
11fn print() void {
12 asm volatile ("svc #0"
13 :
14 : [number] "{x8}" (64),
15 [arg1] "{x0}" (1),
16 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
17 [arg3] "{x2}" ("Hello, World!\n".len),
18 : "memory", "cc"
19 );
20}
21
22// run
23// target=aarch64-linux
24//
25// Hello, World!
26//
test/cases/aarch64-linux/conditional_branches.1.zig created+25
......@@ -0,0 +1,25 @@
1pub fn main() void {
2 foo(true);
3}
4
5fn foo(x: bool) void {
6 if (x) {
7 print();
8 }
9}
10
11fn print() void {
12 asm volatile ("svc #0"
13 :
14 : [number] "{x8}" (64),
15 [arg1] "{x0}" (1),
16 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
17 [arg3] "{x2}" ("Hello, World!\n".len),
18 : "memory", "cc"
19 );
20}
21
22// run
23//
24// Hello, World!
25//
test/cases/aarch64-linux/hello_world_with_updates.0.zig created+31
......@@ -0,0 +1,31 @@
1pub export fn _start() noreturn {
2 print();
3 exit(0);
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{x8}" (64),
10 [arg1] "{x0}" (1),
11 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{x2}" ("Hello, World!\n".len),
13 : "memory", "cc"
14 );
15}
16
17fn exit(ret: usize) noreturn {
18 asm volatile ("svc #0"
19 :
20 : [number] "{x8}" (93),
21 [arg1] "{x0}" (ret),
22 : "memory", "cc"
23 );
24 unreachable;
25}
26
27// run
28// target=aarch64-linux
29//
30// Hello, World!
31//
test/cases/aarch64-linux/hello_world_with_updates.1.zig created+36
......@@ -0,0 +1,36 @@
1pub export fn _start() noreturn {
2 print();
3 print();
4 print();
5 print();
6 exit(0);
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{x8}" (64),
13 [arg1] "{x0}" (1),
14 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{x2}" ("Hello, World!\n".len),
16 : "memory", "cc"
17 );
18}
19
20fn exit(ret: usize) noreturn {
21 asm volatile ("svc #0"
22 :
23 : [number] "{x8}" (93),
24 [arg1] "{x0}" (ret),
25 : "memory", "cc"
26 );
27 unreachable;
28}
29
30// run
31//
32// Hello, World!
33// Hello, World!
34// Hello, World!
35// Hello, World!
36//
test/cases/aarch64-linux/hello_world_with_updates.2.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{x8}" (64),
10 [arg1] "{x0}" (1),
11 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{x2}" ("Hello, World!\n".len),
13 : "memory", "cc"
14 );
15}
16
17// run
18//
19// Hello, World!
20// Hello, World!
21//
test/cases/aarch64-macos/hello_world_with_updates.0.zig created+5
......@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=aarch64-macos
4//
5// :107:9: error: struct 'tmp.tmp' has no member named 'main'
test/cases/aarch64-macos/hello_world_with_updates.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/cases/aarch64-macos/hello_world_with_updates.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/cases/aarch64-macos/hello_world_with_updates.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/cases/aarch64-macos/hello_world_with_updates.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/cases/aarch64-macos/hello_world_with_updates.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/cases/aarch64-macos/hello_world_with_updates.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/cases/adding_numbers_at_runtime_and_comptime.0.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 if (a + b != 7) unreachable;
7}
8
9// run
10//
test/cases/adding_numbers_at_runtime_and_comptime.1.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 if (x - 7 != 0) unreachable;
3}
4
5fn add(a: u32, b: u32) u32 {
6 return a + b;
7}
8
9const x = add(3, 4);
10
11// run
12//
test/cases/adding_numbers_at_runtime_and_comptime.2.zig created+12
......@@ -0,0 +1,12 @@
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 return a + b + c;
9}
10
11// run
12//
test/cases/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/cases/arm-linux/arithmetic_operations.0.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 print(2, 4);
3 print(1, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a + b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19// target=arm-linux
20//
21// 12345612345678
test/cases/arm-linux/arithmetic_operations.1.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(10, 5);
3 print(4, 3);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a - b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 123451
test/cases/arm-linux/arithmetic_operations.2.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(8, 9);
3 print(3, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a & b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 12345678123
test/cases/arm-linux/arithmetic_operations.3.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(4, 2);
3 print(3, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a | b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 1234561234567
test/cases/arm-linux/arithmetic_operations.4.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 print(42, 42);
3 print(3, 5);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a ^ b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 123456
test/cases/arm-linux/arithmetic_operations.5.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 var x: u32 = 1;
3 assert(x << 1 == 2);
4
5 x <<= 1;
6 assert(x << 2 == 8);
7 assert(x << 3 == 16);
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/cases/arm-linux/arithmetic_operations.6.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 var a: u32 = 1024;
3 assert(a >> 1 == 512);
4
5 a >>= 1;
6 assert(a >> 2 == 128);
7 assert(a >> 3 == 64);
8 assert(a >> 4 == 32);
9 assert(a >> 5 == 16);
10 assert(a >> 6 == 8);
11 assert(a >> 7 == 4);
12 assert(a >> 8 == 2);
13 assert(a >> 9 == 1);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/cases/arm-linux/errors.0.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 foo() catch print();
3}
4
5fn foo() anyerror!void {}
6
7fn print() void {
8 asm volatile ("svc #0"
9 :
10 : [number] "{r7}" (4),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
13 [arg3] "{r2}" ("Hello, World!\n".len),
14 : "memory"
15 );
16 return;
17}
18
19// run
20// target=arm-linux
21//
test/cases/arm-linux/errors.1.zig created+24
......@@ -0,0 +1,24 @@
1pub fn main() void {
2 foo() catch print();
3}
4
5fn foo() anyerror!void {
6 return error.Test;
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{r7}" (4),
13 [arg1] "{r0}" (1),
14 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{r2}" ("Hello, World!\n".len),
16 : "memory"
17 );
18 return;
19}
20
21// run
22//
23// Hello, World!
24//
test/cases/arm-linux/errors.2.zig created+27
......@@ -0,0 +1,27 @@
1pub fn main() void {
2 foo() catch |err| {
3 assert(err == error.Foo);
4 assert(err != error.Bar);
5 assert(err != error.Baz);
6 };
7 bar() catch |err| {
8 assert(err != error.Foo);
9 assert(err == error.Bar);
10 assert(err != error.Baz);
11 };
12}
13
14fn assert(ok: bool) void {
15 if (!ok) unreachable;
16}
17
18fn foo() anyerror!void {
19 return error.Foo;
20}
21
22fn bar() anyerror!void {
23 return error.Bar;
24}
25
26// run
27//
test/cases/arm-linux/errors.3.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 foo() catch unreachable;
3}
4
5fn foo() anyerror!void {
6 try bar();
7}
8
9fn bar() anyerror!void {}
10
11// run
12//
test/cases/arm-linux/function_pointers.zig created+44
......@@ -0,0 +1,44 @@
1const PrintFn = *const fn () void;
2
3pub fn main() void {
4 var printFn: PrintFn = stopSayingThat;
5 var i: u32 = 0;
6 while (i < 4) : (i += 1) printFn();
7
8 printFn = moveEveryZig;
9 printFn();
10}
11
12fn stopSayingThat() void {
13 asm volatile ("svc #0"
14 :
15 : [number] "{r7}" (4),
16 [arg1] "{r0}" (1),
17 [arg2] "{r1}" (@ptrToInt("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n")),
18 [arg3] "{r2}" ("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n".len),
19 : "memory"
20 );
21 return;
22}
23
24fn moveEveryZig() void {
25 asm volatile ("svc #0"
26 :
27 : [number] "{r7}" (4),
28 [arg1] "{r0}" (1),
29 [arg2] "{r1}" (@ptrToInt("All your codebase are belong to us\n")),
30 [arg3] "{r2}" ("All your codebase are belong to us\n".len),
31 : "memory"
32 );
33 return;
34}
35
36// run
37// target=arm-linux
38//
39// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
40// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
41// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
42// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
43// All your codebase are belong to us
44//
test/cases/arm-linux/hello_world_with_updates.0.zig created+32
......@@ -0,0 +1,32 @@
1pub export fn _start() noreturn {
2 print();
3 exit();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg1] "{r0}" (1),
11 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{r2}" (14),
13 : "memory"
14 );
15 return;
16}
17
18fn exit() noreturn {
19 asm volatile ("svc #0"
20 :
21 : [number] "{r7}" (1),
22 [arg1] "{r0}" (0),
23 : "memory"
24 );
25 unreachable;
26}
27
28// run
29// target=arm-linux
30//
31// Hello, World!
32//
test/cases/arm-linux/hello_world_with_updates.1.zig created+37
......@@ -0,0 +1,37 @@
1pub export fn _start() noreturn {
2 print();
3 print();
4 print();
5 print();
6 exit();
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{r7}" (4),
13 [arg1] "{r0}" (1),
14 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{r2}" (14),
16 : "memory"
17 );
18 return;
19}
20
21fn exit() noreturn {
22 asm volatile ("svc #0"
23 :
24 : [number] "{r7}" (1),
25 [arg1] "{r0}" (0),
26 : "memory"
27 );
28 unreachable;
29}
30
31// run
32//
33// Hello, World!
34// Hello, World!
35// Hello, World!
36// Hello, World!
37//
test/cases/arm-linux/hello_world_with_updates.2.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg1] "{r0}" (1),
11 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{r2}" (14),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// Hello, World!
21// Hello, World!
22//
test/cases/arm-linux/parameters_and_return_values.0.zig created+28
......@@ -0,0 +1,28 @@
1pub fn main() void {
2 print(id(14));
3}
4
5fn id(x: u32) u32 {
6 return x;
7}
8
9// TODO: The parameters to the asm statement in print() had to
10// be in a specific order because otherwise the write to r0
11// would overwrite the len parameter which resides in r0
12fn print(len: u32) void {
13 asm volatile ("svc #0"
14 :
15 : [number] "{r7}" (4),
16 [arg3] "{r2}" (len),
17 [arg1] "{r0}" (1),
18 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
19 : "memory"
20 );
21 return;
22}
23
24// run
25// target=arm-linux
26//
27// Hello, World!
28//
test/cases/arm-linux/parameters_and_return_values.1.zig created+14
......@@ -0,0 +1,14 @@
1pub fn main() void {
2 assert(add(1, 2, 3, 4, 5, 6) == 21);
3}
4
5fn add(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32) u32 {
6 return a + b + c + d + e + f;
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14//
test/cases/arm-linux/print_u32s.zig created+40
......@@ -0,0 +1,40 @@
1pub fn main() void {
2 printNumberHex(0x00000000);
3 printNumberHex(0xaaaaaaaa);
4 printNumberHex(0xdeadbeef);
5 printNumberHex(0x31415926);
6}
7
8fn printNumberHex(x: u32) void {
9 var i: u5 = 28;
10 while (true) : (i -= 4) {
11 const digit = (x >> i) & 0xf;
12 asm volatile ("svc #0"
13 :
14 : [number] "{r7}" (4),
15 [arg1] "{r0}" (1),
16 [arg2] "{r1}" (@ptrToInt("0123456789abcdef") + digit),
17 [arg3] "{r2}" (1),
18 : "memory"
19 );
20
21 if (i == 0) break;
22 }
23 asm volatile ("svc #0"
24 :
25 : [number] "{r7}" (4),
26 [arg1] "{r0}" (1),
27 [arg2] "{r1}" (@ptrToInt("\n")),
28 [arg3] "{r2}" (1),
29 : "memory"
30 );
31}
32
33// run
34// target=arm-linux
35//
36// 00000000
37// aaaaaaaa
38// deadbeef
39// 31415926
40//
test/cases/arm-linux/spilling_registers.0.zig created+38
......@@ -0,0 +1,38 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l + d; // 227
18 const n = m + e; // 241
19 const o = n + f; // 265
20 const p = o + g; // 303
21 const q = p + h; // 365
22 const r = q + i; // 465
23 const s = r + j; // 575
24 const t = s + k; // 785
25 break :blk t;
26 };
27 const y = x + a; // 788
28 const z = y + a; // 791
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37// target=arm-linux
38//
test/cases/arm-linux/spilling_registers.1.zig created+37
......@@ -0,0 +1,37 @@
1pub fn main() void {
2 assert(addMul(3, 4) == 357747496);
3}
4
5fn addMul(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l * d; // 2170
18 const n = m + e; // 2184
19 const o = n * f; // 52416
20 const p = o + g; // 52454
21 const q = p * h; // 3252148
22 const r = q + i; // 3252248
23 const s = r * j; // 357747280
24 const t = s + k; // 357747490
25 break :blk t;
26 };
27 const y = x + a; // 357747493
28 const z = y + a; // 357747496
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37//
test/cases/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/cases/binary_operands.0.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i: u8 = 5;
3 i += 20;
4 if (i != 25) unreachable;
5}
6
7// run
8// target=wasm32-wasi
9//
test/cases/binary_operands.1.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i32 = 2147483647;
3 if (i +% 1 != -2147483648) unreachable;
4 return;
5}
6
7// run
8//
test/cases/binary_operands.10.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() void {
2 var i: u32 = 5;
3 i *= 7;
4 var result: u32 = foo(i, 10);
5 if (result != 350) unreachable;
6 return;
7}
8fn foo(x: u32, y: u32) u32 {
9 return x * y;
10}
11
12// run
13//
test/cases/binary_operands.11.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var i: i32 = 2147483647;
3 const result = i *% 2;
4 if (result != -2) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.12.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: u3 = 3;
3 if (i *% 3 != 1) unreachable;
4 return;
5}
6
7// run
8//
test/cases/binary_operands.13.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i4 = 3;
3 if (i *% 3 != 1) unreachable;
4 return;
5}
6
7// run
8//
test/cases/binary_operands.14.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() void {
2 var i: u32 = 352;
3 i /= 7; // i = 50
4 var result: u32 = foo(i, 7);
5 if (result != 7) unreachable;
6 return;
7}
8fn foo(x: u32, y: u32) u32 {
9 return x / y;
10}
11
12// run
13//
test/cases/binary_operands.15.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i &= 6;
4 return i - 4;
5}
6
7// run
8//
test/cases/binary_operands.16.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i |= 6;
4 return i - 7;
5}
6
7// run
8//
test/cases/binary_operands.17.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i ^= 6;
4 return i - 3;
5}
6
7// run
8//
test/cases/binary_operands.18.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b or false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.19.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b or false;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.2.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i4 = 7;
3 if (i +% 1 != 0) unreachable;
4 return;
5}
6
7// run
8//
test/cases/binary_operands.20.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b or true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.21.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b or true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.22.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b and false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.23.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b and false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.24.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b and true;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.25.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b and true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/cases/binary_operands.3.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() u8 {
2 var i: u8 = 255;
3 return i +% 1;
4}
5
6// run
7//
test/cases/binary_operands.4.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i += 20;
4 var result: u8 = foo(i, 10);
5 return result - 35;
6}
7fn foo(x: u8, y: u8) u8 {
8 return x + y;
9}
10
11// run
12//
test/cases/binary_operands.5.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var i: u8 = 20;
3 i -= 5;
4 return i - 15;
5}
6
7// run
8//
test/cases/binary_operands.6.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i32 = -2147483648;
3 if (i -% 1 != 2147483647) unreachable;
4 return;
5}
6
7// run
8//
test/cases/binary_operands.7.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() void {
2 var i: i7 = -64;
3 if (i -% 1 != 63) unreachable;
4 return;
5}
6
7// run
8//
test/cases/binary_operands.8.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() void {
2 var i: u4 = 0;
3 if (i -% 1 != 15) unreachable;
4}
5
6// run
7//
test/cases/binary_operands.9.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i -= 3;
4 var result: u8 = foo(i, 10);
5 return result - 8;
6}
7fn foo(x: u8, y: u8) u8 {
8 return y - x;
9}
10
11// run
12//
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/compile_errors/stage1/exe/main_missing_name.zig created+8
......@@ -0,0 +1,8 @@
1pub fn (main) void {}
2
3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
7//
8// tmp.zig:1:5: error: missing function name
test/cases/compile_errors/stage1/exe/missing_main_fn_in_executable.zig created+8
......@@ -0,0 +1,8 @@
1
2
3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
7//
8// error: root source file has no member called 'main'
test/cases/compile_errors/stage1/exe/private_main_fn.zig created+9
......@@ -0,0 +1,9 @@
1fn main() void {}
2
3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
7//
8// error: 'main' is private
9// tmp.zig:1:1: note: declared here
test/cases/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = struct {};
2export fn a() void {
3 const T = [*c]Foo;
4 var t: T = undefined;
5 _ = t;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'
test/cases/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig created+11
......@@ -0,0 +1,11 @@
1export fn a() void {
2 var x: *anyopaque = undefined;
3 var y: [*c]anyopaque = x;
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:16: error: C pointers cannot point to opaque types
test/cases/compile_errors/stage1/obj/Frame_of_generic_function.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 var frame: @Frame(func) = undefined;
3 _ = frame;
4}
5fn func(comptime T: type) void {
6 var x: T = undefined;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:16: error: @Frame() of generic function
test/cases/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig created+16
......@@ -0,0 +1,16 @@
1export fn f1(x: u32) u32 {
2 const y = -%x;
3 return -y;
4}
5const V = @import("std").meta.Vector;
6export fn f2(x: V(4, u32)) V(4, u32) {
7 const y = -%x;
8 return -y;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:3:12: error: negation of type 'u32'
16// tmp.zig:8:12: error: negation of type 'u32'
test/cases/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig created+10
......@@ -0,0 +1,10 @@
1fn foo() void {
2 var sequence = "repeat".*** 10;
3 _ = sequence;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?
test/cases/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig created+16
......@@ -0,0 +1,16 @@
1const std = @import("std");
2const builtin = @import("builtin");
3pub const io_mode = .evented;
4pub fn main() !void {
5 if (builtin.os.tag == .windows) {
6 _ = try (std.net.StreamServer.init(.{})).accept();
7 } else {
8 @compileError("Unsupported OS");
9 }
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// error: Unsupported OS
test/cases/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig created+11
......@@ -0,0 +1,11 @@
1const Foo = error{A};
2comptime {
3 const z = Foo.Bar;
4 _ = z;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:18: error: no error named 'Bar' in 'Foo'
test/cases/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig created+21
......@@ -0,0 +1,21 @@
1fn outer(y: u32) fn (u32) u32 {
2 const st = struct {
3 fn get(z: u32) u32 {
4 return z + y;
5 }
6 };
7 return st.get;
8}
9export fn entry() void {
10 var func = outer(10);
11 var x = func(3);
12 _ = x;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:4:24: error: 'y' not accessible from inner function
20// tmp.zig:3:28: note: crossed function definition here
21// tmp.zig:1:10: note: declared here
test/cases/compile_errors/stage1/obj/add_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a += a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/add_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a + a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig created+12
......@@ -0,0 +1,12 @@
1const y = add(65530, 10);
2fn add(a: u16, b: u16) u16 {
3 return a + b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/cases/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a +%= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a +% a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/addition_with_non_numbers.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = struct {
2 field: i32,
3};
4const x = Foo {.field = 1} + Foo {.field = 2};
5
6export fn entry() usize { return @sizeOf(@TypeOf(x)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'
test/cases/compile_errors/stage1/obj/address_of_number_literal.zig created+10
......@@ -0,0 +1,10 @@
1const x = 3;
2const y = &x;
3fn foo() *const i32 { return y; }
4export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'
test/cases/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 @alignCast(4, @as(u32, 3));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:19: error: expected pointer or slice, found 'u32'
test/cases/compile_errors/stage1/obj/align_n_expr_function_pointers_is_a_compile_error.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() align(1) void {
2 return;
3}
4
5// error
6// backend=stage1
7// target=wasm32-freestanding-none
8//
9// tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64
test/cases/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 var s: struct {} align(4) = undefined;
3 _ = s;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned
test/cases/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig created+14
......@@ -0,0 +1,14 @@
1const Number = enum {
2 a,
3 b align(i32),
4};
5export fn entry1() void {
6 var x: Number = undefined;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:7: error: expected ',' after field
test/cases/compile_errors/stage1/obj/ambiguous_decl_reference.zig created+21
......@@ -0,0 +1,21 @@
1fn foo() void {}
2fn bar() void {
3 const S = struct {
4 fn baz() void {
5 foo();
6 }
7 fn foo() void {}
8 };
9 S.baz();
10}
11export fn entry() void {
12 bar();
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:5:13: error: ambiguous reference
20// tmp.zig:7:9: note: declared here
21// tmp.zig:1:1: note: also declared here
test/cases/compile_errors/stage1/obj/and_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: bool = undefined;
3 _ = a and a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/array_access_of_non_array.zig created+15
......@@ -0,0 +1,15 @@
1export fn f() void {
2 var bad : bool = undefined;
3 bad[0] = bad[0];
4}
5export fn g() void {
6 var bad : bool = undefined;
7 _ = bad[0];
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:8: error: array access of non-array type 'bool'
15// tmp.zig:7:12: error: array access of non-array type 'bool'
test/cases/compile_errors/stage1/obj/array_access_of_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 var b: u8[40] = undefined;
3 _ = b;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: array access of non-array type 'type'
test/cases/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 i[i] = i[i];
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: use of undeclared identifier 'i'
test/cases/compile_errors/stage1/obj/array_access_with_non_integer_index.zig created+17
......@@ -0,0 +1,17 @@
1export fn f() void {
2 var array = "aoeu";
3 var bad = false;
4 array[bad] = array[bad];
5}
6export fn g() void {
7 var array = "aoeu";
8 var bad = false;
9 _ = array[bad];
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:11: error: expected type 'usize', found 'bool'
17// tmp.zig:9:15: error: expected type 'usize', found 'bool'
test/cases/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig created+11
......@@ -0,0 +1,11 @@
1const src = "aoeu";
2const derp: usize = 1234;
3const a = derp ++ "foo";
4
5export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:11: error: expected array, found 'usize'
test/cases/compile_errors/stage1/obj/array_in_c_exported_function.zig created+14
......@@ -0,0 +1,14 @@
1export fn zig_array(x: [10]u8) void {
2 try std.testing.expect(std.mem.eql(u8, &x, "1234567890"));
3}
4const std = @import("std");
5export fn zig_return_array() [10]u8 {
6 return "1234567890".*;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
14// tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/asm_at_compile_time.zig created+17
......@@ -0,0 +1,17 @@
1comptime {
2 doSomeAsm();
3}
4
5fn doSomeAsm() void {
6 asm volatile (
7 \\.globl aoeu;
8 \\.type aoeu, @function;
9 \\.set aoeu, derp;
10 );
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:5: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var a = b;
3 _ = a;
4}
5fn b() callconv(.Inline) void { }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var
12// tmp.zig:5:1: note: declared here
test/cases/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig created+9
......@@ -0,0 +1,9 @@
1const a: *u8 = null;
2
3export fn entry() usize { return @sizeOf(@TypeOf(a)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'
test/cases/compile_errors/stage1/obj/assign_through_constant_pointer.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 var cstr = "Hat";
3 cstr[0] = 'W';
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:13: error: cannot assign to constant
test/cases/compile_errors/stage1/obj/assign_through_constant_slice.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 var cstr: []const u8 = "Hat";
3 cstr[0] = 'W';
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:13: error: cannot assign to constant
test/cases/compile_errors/stage1/obj/assign_to_constant_field.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = struct {
2 field: i32,
3};
4export fn derp() void {
5 const f = Foo {.field = 1234,};
6 f.field = 0;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:15: error: cannot assign to constant
test/cases/compile_errors/stage1/obj/assign_to_constant_variable.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 const a = 3;
3 a = 4;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: cannot assign to constant
test/cases/compile_errors/stage1/obj/assign_to_invalid_dereference.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 'a'.* = 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'
test/cases/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 var vga_mem: u16 = 0xB8000;
3 _ = vga_mem;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'
test/cases/compile_errors/stage1/obj/assign_unreachable.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 const a = return;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: unreachable code
10// tmp.zig:2:15: note: control flow is diverted here
test/cases/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig created+21
......@@ -0,0 +1,21 @@
1fn maybe(is: bool) ?u8 {
2 if (is) return @as(u8, 10) else return null;
3}
4const U = union {
5 Ye: u8,
6};
7const S = struct {
8 num: u8,
9};
10export fn entry() void {
11 var u = U{ .Ye = maybe(false) };
12 var s = S{ .num = maybe(false) };
13 _ = u;
14 _ = s;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'
test/cases/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet
test/cases/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig created+17
......@@ -0,0 +1,17 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 other();
6}
7fn other() void {
8 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:1: error: unable to determine async function frame of 'amain'
17// tmp.zig:5:10: note: analysis of function 'other' depends on the frame
test/cases/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x: u32 = 0;
3 @atomicStore(u32, &x, 1, .Acquire);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel
test/cases/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig created+11
......@@ -0,0 +1,11 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn f() void {
3 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:81: error: failure atomic ordering must be no stricter than success
test/cases/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig created+11
......@@ -0,0 +1,11 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn f() void {
3 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter
test/cases/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 @fence(.Monotonic);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:12: error: atomic ordering must be Acquire or stricter
test/cases/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x = false;
3 _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg
test/cases/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 const E = enum(u8) {
3 a,
4 b,
5 c,
6 d,
7 };
8 var x: E = .a;
9 _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg
test/cases/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x: f32 = 0;
3 _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub
test/cases/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 switch (error.Hi) {
3 .Hi => {},
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'
test/cases/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig created+14
......@@ -0,0 +1,14 @@
1fn SimpleList(comptime L: usize) type {
2 var T = u8;
3 return struct {
4 array: [L]T,
5 };
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:19: error: mutable 'T' not accessible from here
13// tmp.zig:2:9: note: declared mutable here
14// tmp.zig:3:12: note: crosses namespace boundary here
test/cases/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig created+10
......@@ -0,0 +1,10 @@
1const builtin = @import("std").builtin;
2comptime {
3 _ = @Type(.{ .Float = .{ .bits = 17 } });
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:16: error: 17-bit float unsupported
test/cases/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig created+14
......@@ -0,0 +1,14 @@
1fn foo() anyerror!u32 {
2 return 1;
3}
4
5export fn entry() void {
6 const x = -foo();
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:15: error: negation of type 'anyerror!u32'
test/cases/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig created+17
......@@ -0,0 +1,17 @@
1extern fn foo(ptr: fn(*void) callconv(.C) void) void;
2
3export fn entry() void {
4 foo(bar);
5}
6
7fn bar(x: *void) callconv(.C) void { _ = x; }
8export fn entry2() void {
9 bar(&{});
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
17// tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/attempted_double_ampersand.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry(a: bool, b: bool) i32 {
2 if (a && b) {
3 return 1234;
4 }
5 return 5678;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/cases/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry(a: bool, b: bool) i32 {
2 if (a || b) {
3 return 1234;
4 }
5 return 5678;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:9: error: expected error set type, found 'bool'
13// tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR
test/cases/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x: [*]const bool = true;
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'
test/cases/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry(byte: u8) void {
2 const w: i32 = 1234;
3 var x: *const i32 = &w;
4 var y: *[1]i32 = x;
5 y[0] += 1;
6 _ = byte;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'
14// tmp.zig:4:22: note: cast discards const qualifier
test/cases/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 const u: u32 = 42;
3 const x: []u32 = &u;
4 _ = x;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:23: error: expected type '[]u32', found '*const u32'
test/cases/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 const ptr = @intToPtr(*align(1) i32, 0x1);
3 const aligned = @alignCast(4, ptr);
4 _ = aligned;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes
test/cases/compile_errors/stage1/obj/bad_alignment_in_asynccall.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var ptr: fn () callconv(.Async) void = func;
3 var bytes: [64]u8 = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});
5}
6fn func() callconv(.Async) void {}
7
8// error
9// backend=stage1
10// target=aarch64-linux-none
11//
12// tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'
test/cases/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig created+11
......@@ -0,0 +1,11 @@
1export fn a() void {
2 var x: [10]u8 = undefined;
3 var y: []align(16) u8 = &x;
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'
test/cases/compile_errors/stage1/obj/bad_alignment_type.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry1() void {
2 var x: []align(true) i32 = undefined;
3 _ = x;
4}
5export fn entry2() void {
6 var x: *align(@as(f64, 12.34)) i32 = undefined;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:20: error: expected type 'u29', found 'bool'
15// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'
test/cases/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig created+17
......@@ -0,0 +1,17 @@
1export fn entry() void {
2 const BlockKind = u32;
3
4 const Block = struct {
5 kind: BlockKind,
6 };
7
8 bogus;
9
10 _ = Block;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:8:5: error: use of undeclared identifier 'bogus'
test/cases/compile_errors/stage1/obj/bad_import.zig created+7
......@@ -0,0 +1,7 @@
1const bogus = @import("bogus-does-not-exist.zig",);
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound
test/cases/compile_errors/stage1/obj/bad_usage_of_call.zig created+30
......@@ -0,0 +1,30 @@
1export fn entry1() void {
2 @call(.{}, foo, {});
3}
4export fn entry2() void {
5 comptime @call(.{ .modifier = .never_inline }, foo, .{});
6}
7export fn entry3() void {
8 comptime @call(.{ .modifier = .never_tail }, foo, .{});
9}
10export fn entry4() void {
11 @call(.{ .modifier = .never_inline }, bar, .{});
12}
13export fn entry5(c: bool) void {
14 var baz = if (c) baz1 else baz2;
15 @call(.{ .modifier = .compile_time }, baz, .{});
16}
17fn foo() void {}
18fn bar() callconv(.Inline) void {}
19fn baz1() void {}
20fn baz2() void {}
21
22// error
23// backend=stage1
24// target=native
25//
26// tmp.zig:2:21: error: expected tuple or struct, found 'void'
27// tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time
28// tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time
29// tmp.zig:11:5: error: no-inline call of inline function
30// tmp.zig:15:5: error: the specified modifier requires a comptime-known function
test/cases/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a &= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/bin_and_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a & a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/bin_not_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = ~a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a |= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/bin_or_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a | a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a ^= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a ^ a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/binary_not_on_number_literal.zig created+11
......@@ -0,0 +1,11 @@
1const TINY_QUANTUM_SHIFT = 4;
2const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
3var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
4
5export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'
test/cases/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry(byte: u8) void {
2 var oops = @bitCast(u7, byte);
3 _ = oops;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/cases/compile_errors/stage1/obj/bitCast_to_enum_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const y = @bitCast(enum(u32) { a, b }, @as(u32, 3));
3 _ = y;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:24: error: cannot cast a value of type 'y'
test/cases/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
3 _ = foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4
test/cases/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = &@as(u8, 1) << 10;
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'
test/cases/compile_errors/stage1/obj/bogus_compile_var.zig created+8
......@@ -0,0 +1,8 @@
1const x = @import("builtin").bogus;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'
test/cases/compile_errors/stage1/obj/bogus_method_call_on_slice.zig created+11
......@@ -0,0 +1,11 @@
1var self = "aoeu";
2fn f(m: []const u8) void {
3 m.copy(u8, self[0..], m);
4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:6: error: no member named 'copy' in '[]const u8'
test/cases/compile_errors/stage1/obj/bool_not_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: bool = undefined;
3 _ = !a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/branch_on_undefined_value.zig created+9
......@@ -0,0 +1,9 @@
1const x = if (undefined) true else false;
2
3export fn entry() usize { return @sizeOf(@TypeOf(x)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:15: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/cImport_with_bogus_include.zig created+9
......@@ -0,0 +1,9 @@
1const c = @cImport(@cInclude("bogus.h"));
2export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:11: error: C import failed
9// .h:1:10: note: 'bogus.h' file not found
test/cases/compile_errors/stage1/obj/call_assigned_to_constant.zig created+24
......@@ -0,0 +1,24 @@
1const Foo = struct {
2 x: i32,
3};
4fn foo() Foo {
5 return .{ .x = 42 };
6}
7fn bar(val: anytype) Foo {
8 return .{ .x = val };
9}
10export fn entry() void {
11 const baz: Foo = undefined;
12 baz = foo();
13}
14export fn entry1() void {
15 const baz: Foo = undefined;
16 baz = bar(42);
17}
18
19// error
20// backend=stage1
21// target=native
22//
23// tmp.zig:12:14: error: cannot assign to constant
24// tmp.zig:16:14: error: cannot assign to constant
test/cases/compile_errors/stage1/obj/call_with_new_stack_on_unsupported_target.zig created+11
......@@ -0,0 +1,11 @@
1var buf: [10]u8 align(16) = undefined;
2export fn entry() void {
3 @call(.{ .stack = &buf }, foo, .{});
4}
5fn foo() void {}
6
7// error
8// backend=stage1
9// target=wasm32-wasi-none
10//
11// tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack
test/cases/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export fn entry3() callconv(.AAPCSVFP) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64
10// tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64
11// tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64
test/cases/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig created+7
......@@ -0,0 +1,7 @@
1export fn entry() callconv(.Interrupt) void {}
2
3// error
4// backend=stage1
5// target=aarch64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
test/cases/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig created+7
......@@ -0,0 +1,7 @@
1export fn entry() callconv(.Signal) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64
test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig created+23
......@@ -0,0 +1,23 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export fn entry3() void {
13 var a: F3 = undefined;
14 _ = a;
15}
16
17// error
18// backend=stage1
19// target=x86_64-linux-none
20//
21// tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64
22// tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64
23// tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64
test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry1() callconv(.Stdcall) void {}
2export fn entry2() callconv(.Fastcall) void {}
3export fn entry3() callconv(.Thiscall) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64
10// tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64
11// tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64
test/cases/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig created+7
......@@ -0,0 +1,7 @@
1export fn entry() callconv(.Vectorcall) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64
test/cases/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig created+14
......@@ -0,0 +1,14 @@
1var foos = [_]fn(anytype) void { foo1, foo2 };
2
3fn foo1(arg: anytype) void {_ = arg;}
4fn foo2(arg: anytype) void {_ = arg;}
5
6pub fn main() !void {
7 foos[0](true);
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:9: error: calling a generic function requires compile-time known function value
test/cases/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Naked) void { }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: unable to call function with naked calling convention
11// tmp.zig:4:1: note: declared here
test/cases/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 foo("hello".*,);
3}
4pub extern fn foo(format: *const u8, ...) void;
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'
test/cases/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig created+13
......@@ -0,0 +1,13 @@
1export fn foo() void {
2 while (true) {
3 defer {
4 break;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:13: error: cannot break out of defer expression
test/cases/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig created+13
......@@ -0,0 +1,13 @@
1export fn foo() void {
2 while (true) {
3 defer {
4 continue;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:13: error: cannot continue out of defer expression
test/cases/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig created+21
......@@ -0,0 +1,21 @@
1const Union = union(enum) {
2 A: usize,
3 B: isize,
4};
5comptime {
6 var u = Union{ .A = 8 };
7 switch (u) {
8 .A, .B => |e| {
9 _ = e;
10 unreachable;
11 },
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:8:20: error: capture group with incompatible types
20// tmp.zig:8:9: note: type 'usize' here
21// tmp.zig:8:13: note: type 'isize' here
test/cases/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = enum {
2 a,
3 b,
4};
5export fn entry() void {
6 const x: Foo = .c;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:20: error: enum 'Foo' has no field named 'c'
15// tmp.zig:1:13: note: 'Foo' declared here
test/cases/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig created+16
......@@ -0,0 +1,16 @@
1const SmallErrorSet = error{A};
2export fn entry() void {
3 var x: SmallErrorSet!i32 = foo();
4 _ = x;
5}
6fn foo() anyerror!i32 {
7 return error.B;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'
15// tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'
16// tmp.zig:3:35: note: cannot cast global error set into smaller set
test/cases/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig created+15
......@@ -0,0 +1,15 @@
1const SmallErrorSet = error{A};
2export fn entry() void {
3 var x: SmallErrorSet = foo();
4 _ = x;
5}
6fn foo() anyerror {
7 return error.B;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'
15// tmp.zig:3:31: note: cannot cast global error set into smaller set
test/cases/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = @as(usize, -10);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'
test/cases/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig created+17
......@@ -0,0 +1,17 @@
1comptime {
2 const value: i32 = -1;
3 const unsigned = @intCast(u32, value);
4 _ = unsigned;
5}
6export fn entry1() void {
7 const value: i32 = -1;
8 const unsigned: u32 = value;
9 _ = unsigned;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:22: error: attempt to cast negative value to unsigned integer
17// tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'
test/cases/compile_errors/stage1/obj/cast_unreachable.zig created+11
......@@ -0,0 +1,11 @@
1fn f() i32 {
2 return @as(i32, return 1);
3}
4export fn entry() void { _ = f(); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:12: error: unreachable code
11// tmp.zig:2:21: note: control flow is diverted here
test/cases/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig created+21
......@@ -0,0 +1,21 @@
1const BitField = packed struct {
2 a: u3,
3 b: u3,
4 c: u2,
5};
6
7fn foo(bit_field: *const BitField) u3 {
8 return bar(&bit_field.b);
9}
10
11fn bar(x: *const u3) u3 {
12 return x.*;
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'
test/cases/compile_errors/stage1/obj/catch_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: anyerror!bool = undefined;
3 _ = a catch false;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/chained_comparison_operators.zig created+9
......@@ -0,0 +1,9 @@
1export fn a(value: u32) bool {
2 return 1 < value < 1000;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: comparison operators cannot be chained
test/cases/compile_errors/stage1/obj/cmpxchg_with_float.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x: f32 = 0;
3 _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'
test/cases/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig created+10
......@@ -0,0 +1,10 @@
1fn func() bogus {}
2fn func() bogus {}
3export fn entry() usize { return @sizeOf(@TypeOf(func)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:1: error: redeclaration of 'func'
10// tmp.zig:1:1: note: other declaration here
test/cases/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig created+35
......@@ -0,0 +1,35 @@
1export fn inconsistentChildType() void {
2 var x: ?i32 = undefined;
3 const y: comptime_int = 10;
4 _ = (x == y);
5}
6
7export fn optionalToOptional() void {
8 var x: ?i32 = undefined;
9 var y: ?i32 = undefined;
10 _ = (x == y);
11}
12
13export fn optionalVector() void {
14 var x: ?@Vector(10, i32) = undefined;
15 var y: @Vector(10, i32) = undefined;
16 _ = (x == y);
17}
18
19export fn invalidChildType() void {
20 var x: ?[3]i32 = undefined;
21 var y: [3]i32 = undefined;
22 _ = (x == y);
23}
24
25// error
26// backend=stage1
27// target=native
28//
29// :4:12: error: cannot compare types '?i32' and 'comptime_int'
30// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'
31// :10:12: error: cannot compare types '?i32' and '?i32'
32// :10:12: note: optional to optional comparison is only supported for optional pointer types
33// :16:12: error: TODO add comparison of optional vector
34// :22:12: error: cannot compare types '?[3]i32' and '[3]i32'
35// :22:12: note: operator not supported for type '[3]i32'
test/cases/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x: i32 = 1;
3 _ = &x == null;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: comparison of '*i32' with null
test/cases/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 if (2 == undefined) {}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:11: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig created+47
......@@ -0,0 +1,47 @@
1// operator ==
2comptime {
3 var a: i64 = undefined;
4 var x: i32 = 0;
5 if (a == a) x += 1;
6}
7// operator !=
8comptime {
9 var a: i64 = undefined;
10 var x: i32 = 0;
11 if (a != a) x += 1;
12}
13// operator >
14comptime {
15 var a: i64 = undefined;
16 var x: i32 = 0;
17 if (a > a) x += 1;
18}
19// operator <
20comptime {
21 var a: i64 = undefined;
22 var x: i32 = 0;
23 if (a < a) x += 1;
24}
25// operator >=
26comptime {
27 var a: i64 = undefined;
28 var x: i32 = 0;
29 if (a >= a) x += 1;
30}
31// operator <=
32comptime {
33 var a: i64 = undefined;
34 var x: i32 = 0;
35 if (a <= a) x += 1;
36}
37
38// error
39// backend=stage1
40// target=native
41//
42// tmp.zig:5:11: error: use of undefined value here causes undefined behavior
43// tmp.zig:11:11: error: use of undefined value here causes undefined behavior
44// tmp.zig:17:11: error: use of undefined value here causes undefined behavior
45// tmp.zig:23:11: error: use of undefined value here causes undefined behavior
46// tmp.zig:29:11: error: use of undefined value here causes undefined behavior
47// tmp.zig:35:11: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var number_or_error: anyerror!i32 = error.SomethingAwful;
3 _ = number_or_error == error.SomethingAwful;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'
test/cases/compile_errors/stage1/obj/compile-time_division_by_zero.zig created+12
......@@ -0,0 +1,12 @@
1comptime {
2 const a: i32 = 1;
3 const b: i32 = 0;
4 const c = a / b;
5 _ = c;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:17: error: division by zero
test/cases/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig created+12
......@@ -0,0 +1,12 @@
1comptime {
2 const a: i32 = 1;
3 const b: i32 = 0;
4 const c = a % b;
5 _ = c;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:17: error: division by zero
test/cases/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig created+14
......@@ -0,0 +1,14 @@
1const foo = @compileError("aoeu",);
2
3const bar = baz + foo;
4const baz = 1;
5
6export fn entry() i32 {
7 return bar;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:1:13: error: aoeu
test/cases/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig created+17
......@@ -0,0 +1,17 @@
1const Bar = union(enum(u32)) {
2 X: i32 = 1
3};
4
5fn testCompileLog(x: Bar) void {
6 @compileLog(x);
7}
8
9pub fn main () void {
10 comptime testCompileLog(Bar{.X = 123});
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:5: error: found compile log statement
test/cases/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig created+16
......@@ -0,0 +1,16 @@
1const Foo = struct {
2 a: i32 = crap,
3 b: i32,
4};
5export fn entry() void {
6 var x = Foo{
7 .b = 5,
8 };
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:2:14: error: use of undeclared identifier 'crap'
test/cases/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig created+14
......@@ -0,0 +1,14 @@
1const Car = struct {
2 foo: *SymbolThatDoesNotExist,
3 pub fn init() !Car {}
4};
5export fn entry() void {
6 const car = Car.init();
7 _ = car;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'
test/cases/compile_errors/stage1/obj/compile_log.zig created+16
......@@ -0,0 +1,16 @@
1export fn foo() void {
2 comptime bar(12, "hi",);
3}
4fn bar(a: i32, b: []const u8) void {
5 @compileLog("begin",);
6 @compileLog("a", a, "b", b);
7 @compileLog("end",);
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:5: error: found compile log statement
15// tmp.zig:6:5: error: found compile log statement
16// tmp.zig:7:5: error: found compile log statement
test/cases/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 @compileLog(@ptrCast(*const anyopaque, &entry));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: found compile log statement
test/cases/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig created+14
......@@ -0,0 +1,14 @@
1fn Foo(comptime T: type) type {
2 @compileLog(@typeName(T));
3 return T;
4}
5export fn entry() void {
6 _ = Foo(i32);
7 _ = @typeName(Foo(i32));
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:5: error: found compile log statement
test/cases/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 inner(1);
3 inner(2);
4}
5fn inner(comptime n: usize) void {
6 comptime var i = 0;
7 inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:39: error: found compile log statement
test/cases/compile_errors/stage1/obj/compile_time_division_by_zero.zig created+12
......@@ -0,0 +1,12 @@
1const y = foo(0);
2fn foo(x: u32) u32 {
3 return 1 / x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: division by zero
test/cases/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig created+17
......@@ -0,0 +1,17 @@
1const Letter = enum { A, B, C };
2const Value = union(Letter) {
3 A: i32,
4 B,
5 C,
6};
7export fn entry() void {
8 var x: Value = Letter.A;
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'
17// tmp.zig:3:5: note: field 'A' declared here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 const ints = [_]u8{ 1, 2 };
3 inline for (ints) |_| {
4 bad() catch continue;
5 }
6}
7fn bad() !void {
8 return error.Bad;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:4:21: error: comptime control flow inside runtime block
16// tmp.zig:4:15: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 var p: usize = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p == 11) continue;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:22: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 var p: anyerror!i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p) |_| continue else |_| {}
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:20: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 var p: ?i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p) |_| continue;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:20: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig created+18
......@@ -0,0 +1,18 @@
1export fn entry() void {
2 var p: i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 switch (p) {
6 11 => continue,
7 else => {},
8 }
9 q = false;
10 }
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:19: error: comptime control flow inside runtime block
18// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 var p: usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p == 11) continue :outer;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:25: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig created+17
......@@ -0,0 +1,17 @@
1export fn entry() void {
2 var p: anyerror!usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p) |_| {
6 continue :outer;
7 } else |_| {}
8 q = false;
9 }
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:13: error: comptime control flow inside runtime block
17// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 var p: ?usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p) |_| continue :outer;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:23: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/cases/compile_errors/stage1/obj/comptime_float_in_asm_input.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3.17) : "");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float
test/cases/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 const x: f64 = 16777217;
3 const y: f32 = x;
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information
test/cases/compile_errors/stage1/obj/comptime_int_in_asm_input.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3) : "");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int
test/cases/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig created+12
......@@ -0,0 +1,12 @@
1fn foo() void {
2 const node: struct {} = undefined;
3 const vla_ptr = @ptrCast([*]const u8, &node);
4 _ = vla_ptr;
5}
6comptime { foo(); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation
test/cases/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig created+67
......@@ -0,0 +1,67 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..3 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..3 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..3 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..3 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..3 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..3 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..3 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel does not match memory at target index
62// :12:29: error: slice-sentinel does not match memory at target index
63// :20:29: error: slice-sentinel does not match memory at target index
64// :28:29: error: slice-sentinel does not match memory at target index
65// :36:29: error: slice-sentinel does not match memory at target index
66// :44:29: error: slice-sentinel does not match memory at target index
67// :52:29: error: slice-sentinel does not match memory at target index
test/cases/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig created+67
......@@ -0,0 +1,67 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..3 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..3 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..3 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..3 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..3 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..3 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..3 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel does not match memory at target index
62// :12:29: error: slice-sentinel does not match memory at target index
63// :20:29: error: slice-sentinel does not match memory at target index
64// :28:29: error: slice-sentinel does not match memory at target index
65// :36:29: error: slice-sentinel does not match memory at target index
66// :44:29: error: slice-sentinel does not match memory at target index
67// :52:29: error: slice-sentinel does not match memory at target index
test/cases/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig created+67
......@@ -0,0 +1,67 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..14 :255];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..14 :255];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..14 :255];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..14 :255];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..14 :255];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..14 :255];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..14 :255];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel does not match target-sentinel
62// :12:29: error: slice-sentinel does not match target-sentinel
63// :20:29: error: slice-sentinel does not match target-sentinel
64// :28:29: error: slice-sentinel does not match target-sentinel
65// :36:29: error: slice-sentinel does not match target-sentinel
66// :44:29: error: slice-sentinel does not match target-sentinel
67// :52:29: error: slice-sentinel does not match target-sentinel
test/cases/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig created+67
......@@ -0,0 +1,67 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..15 :1];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..15 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..15 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..15 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..15 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..15 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..15 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: out of bounds slice
62// :12:29: error: out of bounds slice
63// :20:29: error: out of bounds slice
64// :28:29: error: out of bounds slice
65// :36:29: error: out of bounds slice
66// :44:29: error: out of bounds slice
67// :52:29: error: out of bounds slice
test/cases/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig created+67
......@@ -0,0 +1,67 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..14 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..14 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..14 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..14 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..14 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..14 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..14 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel is out of bounds
62// :12:29: error: slice-sentinel is out of bounds
63// :20:29: error: slice-sentinel is out of bounds
64// :28:29: error: slice-sentinel is out of bounds
65// :36:29: error: slice-sentinel is out of bounds
66// :44:29: error: slice-sentinel is out of bounds
67// :52:29: error: slice-sentinel is out of bounds
test/cases/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 var a: []u8 = undefined;
3 var b = a[0..10];
4 _ = b;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:14: error: slice of undefined
test/cases/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const slice = @as([*]i32, undefined)[0..1];
3 _ = slice;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:41: error: non-zero length slice of undefined pointer
test/cases/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = struct {
2 comptime b: i32,
3};
4export fn entry() void {
5 var f: Foo = undefined;
6 _ = f;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: comptime field without default initialization value
test/cases/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig created+19
......@@ -0,0 +1,19 @@
1export fn a() void {
2 const f = async func();
3 resume f;
4}
5export fn b() void {
6 const f = async func();
7 var x: anyframe = &f;
8 _ = x;
9}
10fn func() void {
11 suspend {}
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'
19// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'
test/cases/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 (const a = 0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:6: error: expected expression, found 'const'
test/cases/compile_errors/stage1/obj/container_init_with_non-type.zig created+10
......@@ -0,0 +1,10 @@
1const zero: i32 = 0;
2const a = zero{1};
3
4export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:11: error: expected type 'type', found 'i32'
test/cases/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig created+15
......@@ -0,0 +1,15 @@
1export fn foo() void {
2 comptime var i = 0;
3 while (i < 5) : (i += 1) {
4 bar();
5 }
6}
7
8fn bar() void { }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime
15// tmp.zig:3:24: note: compile-time variable assigned here
test/cases/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig created+8
......@@ -0,0 +1,8 @@
1fn a() i32 {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:12: error: expected type 'i32', found 'void'
test/cases/compile_errors/stage1/obj/declaration_between_fields.zig created+24
......@@ -0,0 +1,24 @@
1const S = struct {
2 const foo = 2;
3 const bar = 2;
4 const baz = 2;
5 a: struct {
6 a: u32,
7 b: u32,
8 },
9 const foo1 = 2;
10 const bar1 = 2;
11 const baz1 = 2;
12 b: usize,
13};
14comptime {
15 _ = S;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:9:5: error: declarations are not allowed between container fields
23// tmp.zig:5:5: note: field before declarations here
24// tmp.zig:12:5: note: field after declarations here
test/cases/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig created+12
......@@ -0,0 +1,12 @@
1const u8 = u16;
2export fn entry() void {
3 const a: u8 = 300;
4 _ = a;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:7: error: name shadows primitive 'u8'
12// tmp.zig:1:7: note: consider using @"u8" to disambiguate
test/cases/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig created+12
......@@ -0,0 +1,12 @@
1export fn a() void {
2 x += 1;
3}
4export fn b() void {
5 x += 1;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:5: error: use of undeclared identifier 'x'
test/cases/compile_errors/stage1/obj/deref_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: *u8 = undefined;
3 _ = a.*;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: attempt to dereference undefined value
test/cases/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var a: []u8 = undefined;
3 _ = a.*.len;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'
test/cases/compile_errors/stage1/obj/dereference_an_array.zig created+14
......@@ -0,0 +1,14 @@
1var s_buffer: [10]u8 = undefined;
2pub fn pass(in: []u8) []u8 {
3 var out = &s_buffer;
4 out.*.* = in[0];
5 return out.*[0..1];
6}
7
8export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'
test/cases/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(x: [*]i32) i32 {
2 return x.*;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'
test/cases/compile_errors/stage1/obj/direct_struct_loop.zig created+8
......@@ -0,0 +1,8 @@
1const A = struct { a : A, };
2export fn entry() usize { return @sizeOf(A); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:11: error: struct 'A' depends on itself
test/cases/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig created+29
......@@ -0,0 +1,29 @@
1const O = opaque {};
2const Foo = struct {
3 o: O,
4};
5const Bar = union {
6 One: i32,
7 Two: O,
8};
9export fn a() void {
10 var foo: Foo = undefined;
11 _ = foo;
12}
13export fn b() void {
14 var bar: Bar = undefined;
15 _ = bar;
16}
17export fn c() void {
18 var baz: *opaque {} = undefined;
19 const qux = .{baz.*};
20 _ = qux;
21}
22
23// error
24// backend=stage1
25// target=native
26//
27// tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs
28// tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions
29// tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs
test/cases/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig created+12
......@@ -0,0 +1,12 @@
1extern fn puts(s: [*:0]const u8) c_int;
2pub fn main() void {
3 const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
4 const no_zero_ptr: [*]const u8 = &no_zero_array;
5 _ = puts(no_zero_ptr);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'
test/cases/compile_errors/stage1/obj/discarding_error_value.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = foo();
3}
4fn foo() !void {
5 return error.OutOfMemory;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`
test/cases/compile_errors/stage1/obj/div_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a /= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/div_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a / a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/division_by_zero.zig created+18
......@@ -0,0 +1,18 @@
1const lit_int_x = 1 / 0;
2const lit_float_x = 1.0 / 0.0;
3const int_x = @as(u32, 1) / @as(u32, 0);
4const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5
6export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
7export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
9export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:21: error: division by zero
16// tmp.zig:2:25: error: division by zero
17// tmp.zig:3:27: error: division by zero
18// tmp.zig:4:31: error: division by zero
test/cases/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 var a: u32 = 1;
3 var ptr: *align(@alignOf(u32)) anyopaque = &a;
4 var b: *u32 = @ptrCast(*u32, ptr);
5 var ptr2: *anyopaque = &b;
6 _ = ptr2;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'
test/cases/compile_errors/stage1/obj/double_optional_on_main_return_value.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() ??void {
2}
3
4// error
5// backend=stage1
6// target=native
7//
8// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/cases/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig created+23
......@@ -0,0 +1,23 @@
1comptime {
2 const x = switch (true) {
3 true => false,
4 false => true,
5 true => false,
6 };
7 _ = x;
8}
9comptime {
10 const x = switch (true) {
11 false => true,
12 true => false,
13 false => true,
14 };
15 _ = x;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:5:9: error: duplicate switch value
23// tmp.zig:13:9: error: duplicate switch value
test/cases/compile_errors/stage1/obj/duplicate_enum_field.zig created+16
......@@ -0,0 +1,16 @@
1const Foo = enum {
2 Bar,
3 Bar,
4};
5
6export fn entry() void {
7 const a: Foo = undefined;
8 _ = a;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:3:5: error: duplicate enum field: 'Bar'
16// tmp.zig:2:5: note: other field here
test/cases/compile_errors/stage1/obj/duplicate_error_in_switch.zig created+22
......@@ -0,0 +1,22 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 error.Bar => {},
5 error.Foo => {},
6 else => {},
7 };
8}
9fn foo(x: i32) !void {
10 switch (x) {
11 0 ... 10 => return error.Foo,
12 11 ... 20 => return error.Bar,
13 else => {},
14 }
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'
22// tmp.zig:3:14: note: other value here
test/cases/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = error {
2 Bar,
3 Bar,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: duplicate error set field 'Bar'
15// tmp.zig:2:5: note: previous declaration here
test/cases/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig created+20
......@@ -0,0 +1,20 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 const a = A {
8 .z = 1,
9 .y = 2,
10 .x = 3,
11 .z = 4,
12 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:11:9: error: duplicate field
test/cases/compile_errors/stage1/obj/duplicate_struct_field.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = struct {
2 Bar: i32,
3 Bar: usize,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: duplicate struct field: 'Bar'
15// tmp.zig:2:5: note: other field here
test/cases/compile_errors/stage1/obj/duplicate_union_field.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = union {
2 Bar: i32,
3 Bar: usize,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: duplicate union field: 'Bar'
15// tmp.zig:2:5: note: other field here
test/cases/compile_errors/stage1/obj/embedFile_with_bogus_file.zig created+9
......@@ -0,0 +1,9 @@
1const resource = @embedFile("bogus.txt",);
2
3export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:29: error: unable to find '
test/cases/compile_errors/stage1/obj/empty_for_loop_body.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 for(undefined) |x|;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:23: error: expected block or assignment, found ';'
test/cases/compile_errors/stage1/obj/empty_if_body.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 if(true);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:13: error: expected block or assignment, found ';'
test/cases/compile_errors/stage1/obj/empty_switch_on_an_integer.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x: u32 = 0;
3 switch(x) {}
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: switch must handle all possibilities
test/cases/compile_errors/stage1/obj/empty_while_loop_body.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 while(true);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:16: error: expected block or assignment, found ';'
test/cases/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig created+12
......@@ -0,0 +1,12 @@
1const seventh_fib_number = fibonacci(7);
2fn fibonacci(x: i32) i32 {
3 return fibonacci(x - 1) + fibonacci(x - 2);
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches
test/cases/compile_errors/stage1/obj/enum_field_value_references_enum.zig created+15
......@@ -0,0 +1,15 @@
1pub const Foo = enum(c_int) {
2 A = Foo.B,
3 C = D,
4};
5export fn entry() void {
6 var s: Foo = Foo.E;
7 _ = s;
8}
9const D = 1;
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:17: error: enum 'Foo' depends on itself
test/cases/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = enum(u32) {
2 A = 10,
3 B = 11,
4};
5export fn entry() void {
6 var x = @intToEnum(Foo, 0);
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0
15// tmp.zig:1:13: note: 'Foo' declared here
test/cases/compile_errors/stage1/obj/enum_value_already_taken.zig created+18
......@@ -0,0 +1,18 @@
1const MultipleChoice = enum(u32) {
2 A = 20,
3 B = 40,
4 C = 60,
5 D = 1000,
6 E = 60,
7};
8export fn entry() void {
9 var x = MultipleChoice.C;
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:5: error: enum tag value 60 already taken
18// tmp.zig:4:5: note: other occurrence here
test/cases/compile_errors/stage1/obj/enum_with_0_fields.zig created+7
......@@ -0,0 +1,7 @@
1const Foo = enum {};
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:13: error: enum declarations must have at least one tag
test/cases/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 _ = @Type(@typeInfo(enum { foo, const bar = 1; }));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type
test/cases/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig created+16
......@@ -0,0 +1,16 @@
1const Set1 = error{A, C};
2const Set2 = error{B, D};
3export fn entry() void {
4 foo(Set1.A);
5}
6fn foo(x: Set1) void {
7 if (x == Set2.B) {
8
9 }
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors
test/cases/compile_errors/stage1/obj/error_not_handled_in_switch.zig created+20
......@@ -0,0 +1,20 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 };
5}
6fn foo(x: i32) !void {
7 switch (x) {
8 0 ... 10 => return error.Foo,
9 11 ... 20 => return error.Bar,
10 21 ... 30 => return error.Baz,
11 else => {},
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:26: error: error.Baz not handled in switch
20// tmp.zig:2:26: error: error.Bar not handled in switch
test/cases/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig created+12
......@@ -0,0 +1,12 @@
1fn do_the_thing(func: fn (arg: i32) void) void { _ = func; }
2fn bar(arg: bool) void { _ = arg; }
3export fn entry() void {
4 do_the_thing(bar);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void
12// tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'
test/cases/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 const z = i32!i32;
3 var x: z = undefined;
4 _ = x;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:15: error: expected error set type, found type 'i32'
test/cases/compile_errors/stage1/obj/error_when_evaluating_return_type.zig created+17
......@@ -0,0 +1,17 @@
1const Foo = struct {
2 map: @as(i32, i32),
3
4 fn init() Foo {
5 return undefined;
6 }
7};
8export fn entry() void {
9 var rule_set = try Foo.init();
10 _ = rule_set;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:2:19: error: expected type 'i32', found 'type'
test/cases/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry1() void {
2 const T = u65536;
3 _ = T;
4}
5export fn entry2() void {
6 var x: i65536 = 1;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535
15// tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535
test/cases/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() i32 {
2 return @as(i32, 12.34);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'
test/cases/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig created+13
......@@ -0,0 +1,13 @@
1const Set1 = error {A, B};
2const Set2 = error {A, C};
3comptime {
4 var x = Set1.B;
5 var y = @errSetCast(Set2, x);
6 _ = y;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:13: error: error.B not a member of error set 'Set2'
test/cases/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig created+18
......@@ -0,0 +1,18 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export fn entry() void {
9 var y = @as(f32, 3);
10 var x = @intToEnum(Small, y);
11 _ = x;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:10:31: error: expected integer type, found 'f32'
test/cases/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo(comptime x: i32, y: i32) i32{
2 return x + y;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/export_generic_function.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo(num: anytype) i32 {
2 _ = num;
3 return 0;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/exported_async_function.zig created+7
......@@ -0,0 +1,7 @@
1export fn foo() callconv(.Async) void {}
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:1: error: exported function cannot be async
test/cases/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig created+15
......@@ -0,0 +1,15 @@
1const E = enum { one, two };
2comptime {
3 @export(E, .{ .name = "E" });
4}
5const e: E = .two;
6comptime {
7 @export(e, .{ .name = "e" });
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:13: error: exported enum without explicit integer tag type
15// tmp.zig:7:13: error: exported enum value without explicit integer tag type
test/cases/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig created+12
......@@ -0,0 +1,12 @@
1const fns = [_](fn(i32)i32) { a, b, c };
2pub fn a(x: i32) i32 {return x + 0;}
3pub fn b(x: i32) i32 {return x + 1;}
4export fn c(x: i32) i32 {return x + 2;}
5
6export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
test/cases/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig created+11
......@@ -0,0 +1,11 @@
1extern fn foo(comptime x: i32, y: i32) i32;
2fn f() i32 {
3 return foo(1, 2);
4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig created+43
......@@ -0,0 +1,43 @@
1pub const E = enum {
2@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",
3@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",
4@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",
5@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",
6@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",
7@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",
8@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78",
9@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89",
10@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100",
11@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109",
12@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118",
13@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127",
14@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136",
15@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145",
16@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154",
17@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163",
18@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172",
19@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181",
20@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190",
21@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199",
22@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208",
23@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217",
24@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226",
25@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235",
26@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244",
27@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253",
28@"254",@"255"
29};
30pub const S = extern struct {
31 e: E,
32};
33export fn entry() void {
34 if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type");
35 const s: S = undefined;
36 _ = s;
37}
38
39// error
40// backend=stage1
41// target=native
42//
43// tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'
test/cases/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig created+14
......@@ -0,0 +1,14 @@
1pub const E = enum(u31) { A, B, C };
2pub const S = extern struct {
3 e: E,
4};
5export fn entry() void {
6 const s: S = undefined;
7 _ = s;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'
test/cases/compile_errors/stage1/obj/extern_union_field_missing_type.zig created+13
......@@ -0,0 +1,13 @@
1const Letter = extern union {
2 A,
3};
4export fn entry() void {
5 var a = Letter { .A = {} };
6 _ = a;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: union field missing type
test/cases/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig created+20
......@@ -0,0 +1,20 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = extern union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10};
11export fn entry() void {
12 var a = Payload { .A = 1234 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:6:30: error: extern union does not support enum tag type
test/cases/compile_errors/stage1/obj/extern_variable_has_no_type.zig created+10
......@@ -0,0 +1,10 @@
1extern var foo;
2pub export fn entry() void {
3 foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:8: error: unable to infer variable type
test/cases/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = extern struct {
2 derp: i32,
3};
4export fn foo(a: *i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:33: error: struct 'Foo' has no field 'a'
test/cases/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig created+17
......@@ -0,0 +1,17 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
8 const field_ptr = @intToPtr(*i32, 0x1234);
9 const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
10 _ = another_foo_ptr;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:55: error: pointer value not based on parent struct
test/cases/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig created+16
......@@ -0,0 +1,16 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
8 const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
9 _ = another_foo_ptr;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'
test/cases/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = extern struct {
2 a: i32,
3};
4export fn foo(a: i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:38: error: expected pointer, found 'i32'
test/cases/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig created+10
......@@ -0,0 +1,10 @@
1const Foo = i32;
2export fn foo(a: *i32) *Foo {
3 return @fieldParentPtr(Foo, "a", a);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:28: error: expected struct type, found 'i32'
test/cases/compile_errors/stage1/obj/field_access_of_opaque_type.zig created+16
......@@ -0,0 +1,16 @@
1const MyType = opaque {};
2
3export fn entry() bool {
4 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));
6}
7
8fn bar(x: *MyType) bool {
9 return x.blah;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'
test/cases/compile_errors/stage1/obj/field_access_of_slices.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 var slice: []i32 = undefined;
3 const info = @TypeOf(slice).unknown;
4 _ = info;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:32: error: type 'type' does not support field access
test/cases/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = extern struct {
2 a: i32,
3};
4
5export fn entry(foo: [*]Foo) void {
6 foo.a += 1;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:8: error: type '[*]Foo' does not support field access
test/cases/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig created+12
......@@ -0,0 +1,12 @@
1const Letter = enum {
2 A: void,
3 B,
4 C,
5};
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:8: error: enum fields do not have types
12// tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union
test/cases/compile_errors/stage1/obj/floatToInt_comptime_safety.zig created+17
......@@ -0,0 +1,17 @@
1comptime {
2 _ = @floatToInt(i8, @as(f32, -129.1));
3}
4comptime {
5 _ = @floatToInt(u8, @as(f32, -1.1));
6}
7comptime {
8 _ = @floatToInt(u8, @as(f32, 256.1));
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'
16// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'
17// tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'
test/cases/compile_errors/stage1/obj/float_literal_too_large_error.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 const a = 0x1.0p18495;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: float literal out of range of any type
test/cases/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 const a = 0x1.0p-19000;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: float literal out of range of any type
test/cases/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig created+18
......@@ -0,0 +1,18 @@
1fn returns() usize {
2 return 2;
3}
4export fn f1() void {
5 for ("hello") |_| returns();
6}
7export fn f2() void {
8 var x: anyerror!i32 = error.Bad;
9 for ("hello") |_| returns() else unreachable;
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:5:30: error: expression value is ignored
18// tmp.zig:9:30: error: expression value is ignored
test/cases/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig created+11
......@@ -0,0 +1,11 @@
1var handle_undef: anyframe = undefined;
2var handle_dummy: anyframe = @frame();
3export fn entry() bool {
4 return handle_undef == handle_dummy;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:30: error: @frame() called outside of function definition
test/cases/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 func();
3}
4fn func() void {
5 _ = @frame();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
13// tmp.zig:5:9: note: @frame() causes function to be async
test/cases/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig created+8
......@@ -0,0 +1,8 @@
1extern fn foo() align(3) void;
2export fn entry() void { return foo(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:23: error: alignment value 3 is not a power of 2
test/cases/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 var arr: [4]f32 = undefined;
3 arr = concat();
4}
5fn concat() [16]f32 {
6 return [1]f32{0}**16;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'
test/cases/compile_errors/stage1/obj/function_parameter_is_opaque.zig created+29
......@@ -0,0 +1,29 @@
1const FooType = opaque {};
2export fn entry1() void {
3 const someFuncPtr: fn (FooType) void = undefined;
4 _ = someFuncPtr;
5}
6
7export fn entry2() void {
8 const someFuncPtr: fn (@TypeOf(null)) void = undefined;
9 _ = someFuncPtr;
10}
11
12fn foo(p: FooType) void {_ = p;}
13export fn entry3() void {
14 _ = foo;
15}
16
17fn bar(p: @TypeOf(null)) void {_ = p;}
18export fn entry4() void {
19 _ = bar;
20}
21
22// error
23// backend=stage1
24// target=native
25//
26// tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed
27// tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed
28// tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed
29// tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed
test/cases/compile_errors/stage1/obj/function_prototype_with_no_body.zig created+10
......@@ -0,0 +1,10 @@
1fn foo() void;
2export fn entry() void {
3 foo();
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:1: error: non-extern function has no body
test/cases/compile_errors/stage1/obj/function_returning_opaque_type.zig created+19
......@@ -0,0 +1,19 @@
1const FooType = opaque {};
2export fn bar() !FooType {
3 return error.InvalidValue;
4}
5export fn bav() !@TypeOf(null) {
6 return error.InvalidValue;
7}
8export fn baz() !@TypeOf(undefined) {
9 return error.InvalidValue;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:2:18: error: Opaque return type 'FooType' not allowed
17// tmp.zig:1:1: note: type declared here
18// tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed
19// tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed
test/cases/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig created+18
......@@ -0,0 +1,18 @@
1export fn entry() void {
2 foo();
3}
4fn foo() void {
5 bar();
6}
7fn bar() void {
8 suspend {}
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
16// tmp.zig:2:8: note: async function call here
17// tmp.zig:5:8: note: async function call here
18// tmp.zig:8:5: note: suspends here
test/cases/compile_errors/stage1/obj/function_with_invalid_return_type.zig created+7
......@@ -0,0 +1,7 @@
1export fn foo() boid {}
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:17: error: use of undeclared identifier 'boid'
test/cases/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig created+8
......@@ -0,0 +1,8 @@
1const Foo = enum { A, B, C };
2export fn entry(foo: Foo) void { _ = foo; }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = struct {
2 A: i32,
3 B: f32,
4 C: bool,
5};
6export fn entry(foo: Foo) void { _ = foo; }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = union {
2 A: i32,
3 B: f32,
4 C: bool,
5};
6export fn entry(foo: Foo) void { _ = foo; }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/cases/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig created+11
......@@ -0,0 +1,11 @@
1fn f(_: fn (anytype) void) void {}
2fn g(_: anytype) void {}
3export fn entry() void {
4 f(g);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime
test/cases/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig created+13
......@@ -0,0 +1,13 @@
1pub export fn entry() void {
2 var res: []i32 = undefined;
3 res = myAlloc(i32);
4}
5fn myAlloc(comptime arg: type) anyerror!arg{
6 unreachable;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32
test/cases/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig created+12
......@@ -0,0 +1,12 @@
1fn foo(comptime x: i32, y: i32) i32 { return x + y; }
2fn test1(a: i32, b: i32) i32 {
3 return foo(a, b);
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:16: error: runtime value cannot be passed to comptime arg
test/cases/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig created+25
......@@ -0,0 +1,25 @@
1const FooType = opaque {};
2fn generic(comptime T: type) !T {
3 return undefined;
4}
5export fn bar() void {
6 _ = generic(FooType);
7}
8export fn bav() void {
9 _ = generic(@TypeOf(null));
10}
11export fn baz() void {
12 _ = generic(@TypeOf(undefined));
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed
20// tmp.zig:2:1: note: function declared here
21// tmp.zig:1:1: note: type declared here
22// tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed
23// tmp.zig:2:1: note: function declared here
24// tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed
25// tmp.zig:2:1: note: function declared here
test/cases/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig created+15
......@@ -0,0 +1,15 @@
1fn Foo(comptime T: type) Foo(T) {
2 return struct{ x: T };
3}
4export fn entry() void {
5 const t = Foo(u32) {
6 .x = 1
7 };
8 _ = t;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches
test/cases/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig created+8
......@@ -0,0 +1,8 @@
1const some_data: [100]u8 align(3) = undefined;
2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:32: error: alignment value 3 is not a power of 2
test/cases/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig created+9
......@@ -0,0 +1,9 @@
1extern fn foo() i32;
2const x = foo();
3export fn entry() i32 { return x; }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:11: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/hasDecl_with_non-container.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 _ = @hasDecl(i32, "hi");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'
test/cases/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 if (0) {}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'
test/cases/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 bar() catch unreachable;
3}
4fn bar() anyerror!i32 { return 0; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:11: error: expression value is ignored
test/cases/compile_errors/stage1/obj/ignored_comptime_statement_value.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 comptime {1;}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expression value is ignored
test/cases/compile_errors/stage1/obj/ignored_comptime_value.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 comptime 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: expression value is ignored
test/cases/compile_errors/stage1/obj/ignored_deferred_function_call.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 defer bar();
3}
4fn bar() anyerror!i32 { return 0; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`
test/cases/compile_errors/stage1/obj/ignored_deferred_statement_value.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 defer {1;}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:12: error: expression value is ignored
test/cases/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig created+22
......@@ -0,0 +1,22 @@
1export fn a() void {
2 while (true) : (bad()) {}
3}
4export fn b() void {
5 var x: anyerror!i32 = 1234;
6 while (x) |_| : (bad()) {} else |_| {}
7}
8export fn c() void {
9 var x: ?i32 = 1234;
10 while (x) |_| : (bad()) {}
11}
12fn bad() anyerror!void {
13 return error.Bad;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`
21// tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`
22// tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`
test/cases/compile_errors/stage1/obj/ignored_return_value.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 bar();
3}
4fn bar() i32 { return 0; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:8: error: expression value is ignored
test/cases/compile_errors/stage1/obj/ignored_statement_value.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: expression value is ignored
test/cases/compile_errors/stage1/obj/illegal_comparison_of_types.zig created+20
......@@ -0,0 +1,20 @@
1fn bad_eql_1(a: []u8, b: []u8) bool {
2 return a == b;
3}
4const EnumWithData = union(enum) {
5 One: void,
6 Two: i32,
7};
8fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
9 return a.* == b.*;
10}
11
12export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
13export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:14: error: operator not allowed for type '[]u8'
20// tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'
test/cases/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig created+42
......@@ -0,0 +1,42 @@
1export fn a() void {
2 var x: [*c]u8 = undefined;
3 var y: *align(4) u8 = x;
4 _ = y;
5}
6export fn b() void {
7 var x: [*c]const u8 = undefined;
8 var y: *u8 = x;
9 _ = y;
10}
11export fn c() void {
12 var x: [*c]u8 = undefined;
13 var y: *u32 = x;
14 _ = y;
15}
16export fn d() void {
17 var y: *align(1) u32 = undefined;
18 var x: [*c]u32 = y;
19 _ = x;
20}
21export fn e() void {
22 var y: *const u8 = undefined;
23 var x: [*c]u8 = y;
24 _ = x;
25}
26export fn f() void {
27 var y: *u8 = undefined;
28 var x: [*c]u32 = y;
29 _ = x;
30}
31
32// error
33// backend=stage1
34// target=native
35//
36// tmp.zig:3:27: error: cast increases pointer alignment
37// tmp.zig:8:18: error: cast discards const qualifier
38// tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'
39// tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'
40// tmp.zig:18:22: error: cast increases pointer alignment
41// tmp.zig:23:21: error: cast discards const qualifier
42// tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'
test/cases/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 const buffer: [1]u8 = [_]u8{8};
3 const sliceA: []u8 = &buffer;
4 _ = sliceA;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'
12// tmp.zig:3:27: note: cast discards const qualifier
test/cases/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig created+11
......@@ -0,0 +1,11 @@
1var global_array: [10]i32 = undefined;
2fn foo(param: []i32) void {_ = param;}
3export fn entry() void {
4 foo(global_array);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'
test/cases/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig created+10
......@@ -0,0 +1,10 @@
1var x: f64 = 1.0;
2var y: f32 = x;
3
4export fn entry() usize { return @sizeOf(@TypeOf(y)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: expected type 'f32', found 'f64'
test/cases/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig created+16
......@@ -0,0 +1,16 @@
1const Set1 = error{A, B};
2const Set2 = error{A, C};
3export fn entry() void {
4 foo(Set1.B);
5}
6fn foo(set1: Set1) void {
7 var x: Set2 = set1;
8 _ = x;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:19: error: expected type 'Set2', found 'Set1'
16// tmp.zig:1:23: note: 'error.B' not a member of destination error set
test/cases/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig created+26
......@@ -0,0 +1,26 @@
1export fn entry() void {
2 var slice: []const u8 = "aoeu";
3 const opt_many_ptr: [*]const u8 = slice.ptr;
4 var ptr_opt_many_ptr = &opt_many_ptr;
5 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
6 ptr_opt_many_ptr = c_ptr;
7}
8export fn entry2() void {
9 var buf: [4]u8 = "aoeu".*;
10 var slice: []u8 = &buf;
11 var opt_many_ptr: [*]u8 = slice.ptr;
12 var ptr_opt_many_ptr = &opt_many_ptr;
13 var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
14 _ = c_ptr;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
22// tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
23// tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
24// tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
25// tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
26// tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'
test/cases/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 var c_ptr: [*c]u8 = 0;
3 var zig_ptr: *u8 = c_ptr;
4 _ = zig_ptr;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:24: error: null pointer casted to type '*u8'
test/cases/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig created+16
......@@ -0,0 +1,16 @@
1export fn a() void {
2 var ptr: [*c]u8 = (1 << 64) + 1;
3 _ = ptr;
4}
5export fn b() void {
6 var x: u65 = 0x1234;
7 var ptr: [*c]u8 = x;
8 _ = ptr;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'
16// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'
test/cases/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 var c_ptr: [*c]u8 = undefined;
3 var zig_ptr: *u8 = c_ptr;
4 _ = zig_ptr;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:24: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/implicit_dependency_on_libc.zig created+11
......@@ -0,0 +1,11 @@
1extern "c" fn exit(u8) void;
2export fn entry() void {
3 exit(0);
4}
5
6// error
7// backend=stage1
8// target=native-linux
9// is_test=1
10//
11// tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command
test/cases/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = {};
3 var good = {};
4 _ = {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:11: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 {}
3 var good = {};
4 ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:9: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = comptime {};
3 var good = {};
4 _ = comptime {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:20: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 comptime {}
3 var good = {};
4 comptime ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:18: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-defer.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 defer {}
3 var good = {};
4 defer ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:15: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = for(foo()) |_| {};
3 var good = {};
4 _ = for(foo()) |_| {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:26: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 for(foo()) |_| {}
3 var good = {};
4 for(foo()) |_| ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = if(true) {} else if(true) {} else {};
3 var good = {};
4 _ = if(true) {} else if(true) {} else {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:45: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 if(true) {} else if(true) {} else {}
3 var good = {};
4 if(true) ({}) else if(true) ({}) else ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:47: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = if(true) {} else if(true) {};
3 var good = {};
4 _ = if(true) {} else if(true) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:37: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 if(true) {} else if(true) {}
3 var good = {};
4 if(true) ({}) else if(true) ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:37: error: expected ';' or 'else' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = if(true) {} else {};
3 var good = {};
4 _ = if(true) {} else {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 if(true) {} else {}
3 var good = {};
4 if(true) ({}) else ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = if(true) {};
3 var good = {};
4 _ = if(true) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:20: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 if(true) {}
3 var good = {};
4 if(true) ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = if (foo()) |_| {};
3 var good = {};
4 _ = if (foo()) |_| {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:26: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 if (foo()) |_| {}
3 var good = {};
4 if (foo()) |_| ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = while(true):({}) {};
3 var good = {};
4 _ = while(true):({}) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 while(true):({}) {}
3 var good = {};
4 while(true):({}) ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:26: error: expected ';' or 'else' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = while(true) {};
3 var good = {};
4 _ = while(true) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:23: error: expected ';' after statement
test/cases/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 while(true) {}
3 var good = {};
4 while(true) 1
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/cases/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig created+17
......@@ -0,0 +1,17 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export fn entry() void {
9 var x: u2 = Small.Two;
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:22: error: expected type 'u2', found 'Small'
test/cases/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig created+19
......@@ -0,0 +1,19 @@
1const Foo = packed struct {
2 a: u8,
3 b: u32,
4};
5
6export fn entry() void {
7 var foo = Foo { .a = 1, .b = 10 };
8 bar(&foo.b);
9}
10
11fn bar(x: *u32) void {
12 x.* += 1;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'
test/cases/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig created+22
......@@ -0,0 +1,22 @@
1const Foo = packed struct {
2 a: u8,
3 b: u32,
4};
5
6export fn entry() void {
7 var foo = Foo { .a = 1, .b = 10 };
8 foo.b += 1;
9 bar(@as(*[1]u32, &foo.b)[0..]);
10}
11
12fn bar(x: []u32) void {
13 x[0] += 1;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:9:26: error: cast increases pointer alignment
21// tmp.zig:9:26: note: '*align(1) u32' has alignment 1
22// tmp.zig:9:26: note: '*[1]u32' has alignment 4
test/cases/compile_errors/stage1/obj/import_outside_package_path.zig created+9
......@@ -0,0 +1,9 @@
1comptime{
2 _ = @import("../a.zig");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: import of file outside package path: '../a.zig'
test/cases/compile_errors/stage1/obj/incompatible_sentinels.zig created+29
......@@ -0,0 +1,29 @@
1// Note: One of the error messages here is backwards. It would be nice to fix, but that's not
2// going to stop me from merging this branch which fixes a bunch of other stuff.
3export fn entry1(ptr: [*:255]u8) [*:0]u8 {
4 return ptr;
5}
6export fn entry2(ptr: [*]u8) [*:0]u8 {
7 return ptr;
8}
9export fn entry3() void {
10 var array: [2:0]u8 = [_:255]u8{ 1, 2 };
11 _ = array;
12}
13export fn entry4() void {
14 var array: [2:0]u8 = [_]u8{ 1, 2 };
15 _ = array;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:4:12: error: expected type '[*:0]u8', found '[*:255]u8'
23// tmp.zig:4:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel
24// tmp.zig:7:12: error: expected type '[*:0]u8', found '[*]u8'
25// tmp.zig:7:12: note: destination pointer requires a terminating '0' sentinel
26// tmp.zig:10:35: error: expected type '[2:255]u8', found '[2:0]u8'
27// tmp.zig:10:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel
28// tmp.zig:14:31: error: expected type '[2:0]u8', found '[2]u8'
29// tmp.zig:14:31: note: destination array requires a terminating '0' sentinel
test/cases/compile_errors/stage1/obj/incorrect_return_type.zig created+21
......@@ -0,0 +1,21 @@
1 pub export fn entry() void{
2 _ = foo();
3 }
4 const A = struct {
5 a: u32,
6 };
7 fn foo() A {
8 return bar();
9 }
10 const B = struct {
11 a: u32,
12 };
13 fn bar() B {
14 unreachable;
15 }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:8:16: error: expected type 'A', found 'B'
test/cases/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() u32 {
2 var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
3 const ptr = @ptrCast(*u32, &bytes[0]);
4 return ptr.*;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:17: error: cast increases pointer alignment
12// tmp.zig:3:38: note: '*u8' has alignment 1
13// tmp.zig:3:26: note: '*u32' has alignment 4
test/cases/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var slice: []u8 = undefined;
3 slice[0] = 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: index 0 outside slice of size 0
test/cases/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig created+11
......@@ -0,0 +1,11 @@
1const array = [_]u8{};
2export fn foo() void {
3 const pointer = &array[0];
4 _ = pointer;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:27: error: accessing a zero length array is not allowed
test/cases/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig created+12
......@@ -0,0 +1,12 @@
1const array = [_]u8{};
2export fn foo() void {
3 var index: usize = 0;
4 const pointer = &array[index];
5 _ = pointer;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:27: error: accessing a zero length array is not allowed
test/cases/compile_errors/stage1/obj/indexing_single-item_pointer.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(ptr: *i32) i32 {
2 return ptr[1];
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: index of single-item pointer
test/cases/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig created+36
......@@ -0,0 +1,36 @@
1var frame: ?anyframe = null;
2
3export fn a() void {
4 _ = async rangeSum(10);
5 while (frame) |f| resume f;
6}
7
8fn rangeSum(x: i32) i32 {
9 suspend {
10 frame = @frame();
11 }
12 frame = null;
13
14 if (x == 0) return 0;
15 var child = rangeSumIndirect(x - 1);
16 return child + 1;
17}
18
19fn rangeSumIndirect(x: i32) i32 {
20 suspend {
21 frame = @frame();
22 }
23 frame = null;
24
25 if (x == 0) return 0;
26 var child = rangeSum(x - 1);
27 return child + 1;
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
35// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here
36// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/cases/compile_errors/stage1/obj/indirect_struct_loop.zig created+10
......@@ -0,0 +1,10 @@
1const A = struct { b : B, };
2const B = struct { c : C, };
3const C = struct { a : A, };
4export fn entry() usize { return @sizeOf(A); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:11: error: struct 'A' depends on itself
test/cases/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 const x = [_]u8;
3 _ = x;
4}
5export fn entry2() void {
6 const S = struct { a: *const [_]u8 };
7 var a = .{ S{} };
8 _ = a;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:16: error: unable to infer array size
16// tmp.zig:6:35: error: unable to infer array size
test/cases/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig created+9
......@@ -0,0 +1,9 @@
1comptime {
2 const z: ?fn()!void = null;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:19: error: function prototype may not have inferred error set
test/cases/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = [_]u8{ .y = 2 };
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: initializing array with struct syntax
test/cases/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = struct {
2 x: Foo,
3};
4
5var foo: Foo = undefined;
6
7export fn entry() usize {
8 return @sizeOf(@TypeOf(foo.x));
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:13: error: struct 'Foo' depends on itself
test/cases/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var y = @intToPtr([*]align(4) u8, 5);
3 _ = y;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address
test/cases/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig created+15
......@@ -0,0 +1,15 @@
1const Set1 = error{
2 A,
3 B,
4};
5comptime {
6 var x: u16 = 3;
7 var y = @intToError(x);
8 _ = y;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:13: error: integer value 3 represents no error
test/cases/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig created+19
......@@ -0,0 +1,19 @@
1const Set1 = error{
2 A,
3 B,
4};
5const Set2 = error{
6 A,
7 C,
8};
9comptime {
10 var x = @errorToInt(Set1.B);
11 var y = @errSetCast(Set2, @intToError(x));
12 _ = y;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:11:13: error: error.B not a member of error set 'Set2'
test/cases/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig created+11
......@@ -0,0 +1,11 @@
1export fn foo() void {
2 var x: usize = 0x1000;
3 var y: *void = @intToPtr(*void, x);
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information
test/cases/compile_errors/stage1/obj/integer_cast_truncates_bits.zig created+31
......@@ -0,0 +1,31 @@
1export fn entry1() void {
2 const spartan_count: u16 = 300;
3 const byte = @intCast(u8, spartan_count);
4 _ = byte;
5}
6export fn entry2() void {
7 const spartan_count: u16 = 300;
8 const byte: u8 = spartan_count;
9 _ = byte;
10}
11export fn entry3() void {
12 var spartan_count: u16 = 300;
13 var byte: u8 = spartan_count;
14 _ = byte;
15}
16export fn entry4() void {
17 var signed: i8 = -1;
18 var unsigned: u64 = signed;
19 _ = unsigned;
20}
21
22// error
23// backend=stage1
24// target=native
25//
26// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits
27// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'
28// tmp.zig:13:20: error: expected type 'u8', found 'u16'
29// tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values
30// tmp.zig:18:25: error: expected type 'u64', found 'i8'
31// tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
test/cases/compile_errors/stage1/obj/integer_overflow_error.zig created+8
......@@ -0,0 +1,8 @@
1const x : u8 = 300;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'
test/cases/compile_errors/stage1/obj/integer_underflow_error.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// :2:78: error: operation caused overflow
test/cases/compile_errors/stage1/obj/invalid_break_expression.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 break;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: break expression outside loop
test/cases/compile_errors/stage1/obj/invalid_builtin_fn.zig created+9
......@@ -0,0 +1,9 @@
1fn f() @bogus(foo) {
2}
3export fn entry() void { _ = f(); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:8: error: invalid builtin function: '@bogus'
test/cases/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig created+17
......@@ -0,0 +1,17 @@
1const E = enum(usize) { One, Two };
2
3export fn entry() void {
4 foo(1);
5}
6
7fn foo(x: usize) void {
8 switch (x) {
9 E.One => {},
10 }
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:10: error: expected type 'usize', found 'E'
test/cases/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig created+10
......@@ -0,0 +1,10 @@
1fn foo() void {}
2const invalid = foo > foo;
3
4export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: operator not allowed for type 'fn() void'
test/cases/compile_errors/stage1/obj/invalid_continue_expression.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 continue;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: continue expression outside loop
test/cases/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig created+17
......@@ -0,0 +1,17 @@
1comptime {
2 var tile = Tile.Empty;
3 switch (tile.*) {
4 Tile.Empty => {},
5 Tile.Filled => {},
6 }
7}
8const Tile = enum {
9 Empty,
10 Filled,
11};
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'
test/cases/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 const a = '\u{}';
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:19: error: empty unicode escape sequence
test/cases/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0x1.0p1ab1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: 'a'
test/cases/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0x1.0p50F;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:29: note: invalid byte: 'F'
test/cases/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig created+7
......@@ -0,0 +1,7 @@
1comptime { var x = doesnt_exist.whatever; _ = x; }
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'
test/cases/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig created+19
......@@ -0,0 +1,19 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 const a = A {
8 .z = 4,
9 .y = 2,
10 .foo = 42,
11 };
12 _ = a;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:10:9: error: no member named 'foo' in struct 'A'
test/cases/compile_errors/stage1/obj/invalid_float_literal.zig created+13
......@@ -0,0 +1,13 @@
1const std = @import("std");
2
3pub fn main() void {
4 var bad_float :f32 = 0.0;
5 bad_float = bad_float + .20;
6 std.debug.assert(bad_float < 1.0);
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:29: error: expected expression, found '.'
test/cases/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const a = '\U1234';
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expected expression, found 'invalid bytes'
10// tmp.zig:2:18: note: invalid byte: '1'
test/cases/compile_errors/stage1/obj/invalid_maybe_type.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 if (true) |x| { _ = x; }
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: expected optional type, found 'bool'
test/cases/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig created+11
......@@ -0,0 +1,11 @@
1const builtin = @import("std").builtin;
2export fn entry() void {
3 const foo = builtin.Mode.x86;
4 _ = foo;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'
test/cases/compile_errors/stage1/obj/invalid_multiple_dereferences.zig created+19
......@@ -0,0 +1,19 @@
1export fn a() void {
2 var box = Box{ .field = 0 };
3 box.*.field = 1;
4}
5export fn b() void {
6 var box = Box{ .field = 0 };
7 var boxPtr = &box;
8 boxPtr.*.*.field = 1;
9}
10pub const Box = struct {
11 field: i32,
12};
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'
19// tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'
test/cases/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig created+10
......@@ -0,0 +1,10 @@
1const stroo = extern struct {
2 moo: ?[*c]u8,
3};
4export fn testf(fluff: *stroo) void { _ = fluff; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'
test/cases/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig created+13
......@@ -0,0 +1,13 @@
1extern fn ext() usize;
2var bytes: [ext()]u8 = undefined;
3export fn f() void {
4 for (bytes) |*b, i| {
5 b.* = @as(u8, i);
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:13: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/invalid_pointer_syntax.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo() void {
2 var guid: *:0 const u8 = undefined;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:16: error: expected type expression, found ':'
test/cases/compile_errors/stage1/obj/invalid_shift_amount_error.zig created+11
......@@ -0,0 +1,11 @@
1const x : u8 = 2;
2fn f() u16 {
3 return x << 8;
4}
5export fn entry() u16 { return f(); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'
test/cases/compile_errors/stage1/obj/invalid_struct_field.zig created+19
......@@ -0,0 +1,19 @@
1const A = struct { x : i32, };
2export fn f() void {
3 var a : A = undefined;
4 a.foo = 1;
5 const y = a.bar;
6 _ = y;
7}
8export fn g() void {
9 var a : A = undefined;
10 const y = a.bar;
11 _ = y;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:4:6: error: no member named 'foo' in struct 'A'
19// tmp.zig:10:16: error: no member named 'bar' in struct 'A'
test/cases/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 var frame = async func();
3 var result = await frame;
4 _ = result;
5}
6fn func() void {
7 suspend {}
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
15// tmp.zig:3:18: note: await here is a suspend point
test/cases/compile_errors/stage1/obj/invalid_type.zig created+8
......@@ -0,0 +1,8 @@
1fn a() bogus {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:8: error: use of undeclared identifier 'bogus'
test/cases/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig created+14
......@@ -0,0 +1,14 @@
1const Item = struct {
2 field: SomeNonexistentType,
3};
4var items: [100]Item = undefined;
5export fn entry() void {
6 const a = items[0];
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0._0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1.0__0e-1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:25: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1.0e-1__0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0_x0.0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: 'x'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0x_0.0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0x0.0_p1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:27: note: invalid byte: 'p'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0_.0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '.'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 0.0_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:25: note: invalid byte: ';'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1.0e_1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:25: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1.0e+_1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:26: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1.0e-_1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:26: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1.0e-1_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: f128 = 1__0.0e-1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '_'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: u128 = 0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:26: note: invalid byte: ';'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: u128 = 0b0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: u128 = 0o0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/cases/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig created+11
......@@ -0,0 +1,11 @@
1fn main() void {
2 var bad: u128 = 0x0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/cases/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = union {
2 Bar: u8,
3 Baz: void,
4};
5comptime {
6 var foo = Foo {.Baz = {}};
7 const bar_val = foo.Bar;
8 _ = bar_val;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set
test/cases/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var foo: u32 = @This(){};
3 _ = foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:27: error: type 'u32' does not support array initialization
test/cases/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig created+27
......@@ -0,0 +1,27 @@
1export fn foo1() void {
2 const a: *[1]u8 = undefined;
3 var b: []u8 = a;
4 _ = b;
5}
6export fn foo2() void {
7 comptime {
8 var a: *[1]u8 = undefined;
9 var b: []u8 = a;
10 _ = b;
11 }
12}
13export fn foo3() void {
14 comptime {
15 const a: *[1]u8 = undefined;
16 var b: []u8 = a;
17 _ = b;
18 }
19}
20
21// error
22// backend=stage1
23// target=native
24//
25// tmp.zig:3:19: error: use of undefined value here causes undefined behavior
26// tmp.zig:9:23: error: use of undefined value here causes undefined behavior
27// tmp.zig:16:23: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig created+17
......@@ -0,0 +1,17 @@
1export fn foo1() void {
2 var bytes = [_]u8{1, 2};
3 const word: u16 = @bitCast(u16, bytes[0..]);
4 _ = word;
5}
6export fn foo2() void {
7 var bytes: []const u8 = &[_]u8{1, 2};
8 const word: u16 = @bitCast(u16, bytes);
9 _ = word;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'
17// tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16
test/cases/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig created+11
......@@ -0,0 +1,11 @@
1export fn foo() [*:0]const u8 {
2 var buffer: [64]u8 = undefined;
3 return buffer[0..];
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// :3:18: error: expected type '[*:0]const u8', found '*[64]u8'
11// :3:18: note: destination pointer requires a terminating '0' sentinel
test/cases/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig created+16
......@@ -0,0 +1,16 @@
1fn ignore(comptime param: anytype) void {_ = param;}
2
3export fn foo() void {
4 const MyStruct = struct {
5 wrong_type: []u8 = "foo",
6 };
7
8 comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// :5:28: error: cannot cast pointer to array literal to slice type '[]u8'
16// :5:28: note: cast discards const qualifier
test/cases/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig created+11
......@@ -0,0 +1,11 @@
1export fn foo() void {
2 var u: ?*anyopaque = null;
3 var v: *anyopaque = undefined;
4 v = u;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'
test/cases/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig created+14
......@@ -0,0 +1,14 @@
1export fn foo_slice_len_increment_beyond_bounds() void {
2 comptime {
3 var buf_storage: [8]u8 = undefined;
4 var buf: []const u8 = buf_storage[0..];
5 buf.len += 1;
6 buf[8] = 42;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// :6:12: error: out of bounds slice
test/cases/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig created+7
......@@ -0,0 +1,7 @@
1pub const empty = return 1;
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:19: error: 'return' outside function scope
test/cases/compile_errors/stage1/obj/labeled_break_not_found.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 blah: while (true) {
3 while (true) {
4 break :outer;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:20: error: label not found: 'outer'
test/cases/compile_errors/stage1/obj/labeled_continue_not_found.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 var i: usize = 0;
3 blah: while (i < 10) : (i += 1) {
4 while (true) {
5 continue :outer;
6 }
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:23: error: label not found: 'outer'
test/cases/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig created+12
......@@ -0,0 +1,12 @@
1export fn foo() void {
2 comptime var T: type = undefined;
3 const S = struct { x: *T };
4 const I = @typeInfo(S);
5 _ = I;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// :3:28: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/libc_headers_note.zig created+12
......@@ -0,0 +1,12 @@
1const c = @cImport(@cInclude("stdio.h"));
2export fn entry() void {
3 _ = c.printf("hello, world!\n");
4}
5
6// error
7// backend=stage1
8// is_test=1
9// target=native-linux
10//
11// tmp.zig:1:11: error: C import failed
12// tmp.zig:1:11: note: libc headers not available; compilation does not link against libc
test/cases/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 const float: f32 = 5.99999999999994648725e-01;
3 const float_ptr = &float;
4 const int_ptr = @ptrCast(*const i64, float_ptr);
5 const int_val = int_ptr.*;
6 _ = int_val;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes
test/cases/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig created+17
......@@ -0,0 +1,17 @@
1export fn entry() void {
2 var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
3
4 var i: u32 = 0;
5 var x = loadv(&v[i]);
6 _ = x;
7}
8
9fn loadv(ptr: anytype) i32 {
10 return ptr.*;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/cases/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 var foo = true;
3 _ = foo;
4}
5fn foo() void {}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:9: error: local shadows declaration of 'foo'
12// tmp.zig:5:1: note: declared here
test/cases/compile_errors/stage1/obj/local_variable_redeclaration.zig created+11
......@@ -0,0 +1,11 @@
1export fn f() void {
2 const a : i32 = 0;
3 var a = 0;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: redeclaration of local constant 'a'
11// tmp.zig:2:11: note: previous declaration here
test/cases/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig created+11
......@@ -0,0 +1,11 @@
1fn f(a : i32) void {
2 const a = 0;
3}
4export fn entry() void { f(1); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:11: error: redeclaration of function parameter 'a'
11// tmp.zig:1:6: note: previous declaration here
test/cases/compile_errors/stage1/obj/local_variable_shadowing_global.zig created+14
......@@ -0,0 +1,14 @@
1const Foo = struct {};
2const Bar = struct {};
3
4export fn entry() void {
5 var Bar : i32 = undefined;
6 _ = Bar;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:9: error: local shadows declaration of 'Bar'
14// tmp.zig:2:1: note: declared here
test/cases/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig created+12
......@@ -0,0 +1,12 @@
1export fn foo() void {
2 const u8 = u16;
3 const a: u8 = 300;
4 _ = a;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:11: error: name shadows primitive 'u8'
12// tmp.zig:2:11: note: consider using @"u8" to disambiguate
test/cases/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main(args: [][]bogus) !void {_ = args;}
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:23: error: use of undeclared identifier 'bogus'
test/cases/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig created+21
......@@ -0,0 +1,21 @@
1const Foo = struct {
2 x: i32,
3
4 fn init(x: i32) Foo {
5 return Foo {
6 .x = x,
7 };
8 }
9};
10
11export fn f() void {
12 const derp = Foo.init(3);
13
14 derp.init();
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:14:5: error: expected type 'i32', found 'Foo'
test/cases/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig created+30
......@@ -0,0 +1,30 @@
1pub const List = struct {
2 len: usize,
3 allocator: *Allocator,
4
5 pub fn init(allocator: *Allocator) List {
6 return List {
7 .len = 0,
8 .allocator = allocator,
9 };
10 }
11};
12
13pub var global_allocator = Allocator {
14 .field = 1234,
15};
16
17pub const Allocator = struct {
18 field: i32,
19};
20
21export fn foo() void {
22 var x = List.init(&global_allocator);
23 x.init();
24}
25
26// error
27// backend=stage1
28// target=native
29//
30// tmp.zig:23:5: error: expected type '*Allocator', found '*List'
test/cases/compile_errors/stage1/obj/missing_boolean_switch_value.zig created+19
......@@ -0,0 +1,19 @@
1comptime {
2 const x = switch (true) {
3 true => false,
4 };
5 _ = x;
6}
7comptime {
8 const x = switch (true) {
9 false => true,
10 };
11 _ = x;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:2:15: error: switch must handle all possibilities
19// tmp.zig:8:15: error: switch must handle all possibilities
test/cases/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig created+18
......@@ -0,0 +1,18 @@
1const Geo3DTex2D = struct { vertices: [][2]f32 };
2pub fn getGeo3DTex2D() Geo3DTex2D {
3 return Geo3DTex2D{
4 .vertices = [_][2]f32{
5 [_]f32{ -0.5, -0.5},
6 },
7 };
8}
9export fn entry() void {
10 var geo_data = getGeo3DTex2D();
11 _ = geo_data;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'
test/cases/compile_errors/stage1/obj/missing_else_clause.zig created+16
......@@ -0,0 +1,16 @@
1fn f(b: bool) void {
2 const x : i32 = if (b) h: { break :h 1; };
3 _ = x;
4}
5fn g(b: bool) void {
6 const y = if (b) h: { break :h @as(i32, 1); };
7 _ = y;
8}
9export fn entry() void { f(true); g(true); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:21: error: expected type 'i32', found 'void'
16// tmp.zig:6:15: error: incompatible types: 'i32' and 'void'
test/cases/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig created+20
......@@ -0,0 +1,20 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 // we want the error on the '{' not the 'A' because
8 // the A could be a complicated expression
9 const a = A {
10 .z = 4,
11 .y = 2,
12 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:9:17: error: missing field: 'x'
test/cases/compile_errors/stage1/obj/missing_function_call_param.zig created+31
......@@ -0,0 +1,31 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4
5 fn member_a(foo: *const Foo) i32 {
6 return foo.a;
7 }
8 fn member_b(foo: *const Foo) i32 {
9 return foo.b;
10 }
11};
12
13const member_fn_type = @TypeOf(Foo.member_a);
14const members = [_]member_fn_type {
15 Foo.member_a,
16 Foo.member_b,
17};
18
19fn f(foo: *const Foo, index: usize) void {
20 const result = members[index]();
21 _ = foo;
22 _ = result;
23}
24
25export fn entry() usize { return @sizeOf(@TypeOf(f)); }
26
27// error
28// backend=stage1
29// target=native
30//
31// tmp.zig:20:34: error: expected 1 argument(s), found 0
test/cases/compile_errors/stage1/obj/missing_function_name.zig created+8
......@@ -0,0 +1,8 @@
1fn () void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:1: error: missing function name
test/cases/compile_errors/stage1/obj/missing_param_name.zig created+8
......@@ -0,0 +1,8 @@
1fn f(i32) void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:6: error: missing parameter name
test/cases/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig created+11
......@@ -0,0 +1,11 @@
1fn dump(anytype) void {}
2export fn entry() void {
3 var a: u8 = 9;
4 dump(a);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:9: error: missing parameter name
test/cases/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig created+12
......@@ -0,0 +1,12 @@
1fn foo() !void {
2 return anyerror.Foo;
3}
4export fn entry() void {
5 foo() catch 0;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'
test/cases/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig created+37
......@@ -0,0 +1,37 @@
1const JasonHM = u8;
2const JasonList = *JsonNode;
3
4const JsonOA = union(enum) {
5 JSONArray: JsonList,
6 JSONObject: JasonHM,
7};
8
9const JsonType = union(enum) {
10 JSONNull: void,
11 JSONInteger: isize,
12 JSONDouble: f64,
13 JSONBool: bool,
14 JSONString: []u8,
15 JSONArray: void,
16 JSONObject: void,
17};
18
19pub const JsonNode = struct {
20 kind: JsonType,
21 jobject: ?JsonOA,
22};
23
24fn foo() void {
25 var jll: JasonList = undefined;
26 jll.init(1234);
27 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
28 _ = jd;
29}
30
31export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
32
33// error
34// backend=stage1
35// target=native
36//
37// tmp.zig:5:16: error: use of undeclared identifier 'JsonList'
test/cases/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a %= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/mod_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a % a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig created+12
......@@ -0,0 +1,12 @@
1const y = mul(300, 6000);
2fn mul(a: u16, b: u16) u16 {
3 return a * b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/cases/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a *= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/mult_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a * a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a *%= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a *% a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/multiple_function_definitions.zig created+10
......@@ -0,0 +1,10 @@
1fn a() void {}
2fn a() void {}
3export fn entry() void { a(); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:1: error: redeclaration of 'a'
10// tmp.zig:1:1: note: other declaration here
test/cases/compile_errors/stage1/obj/negate_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = -a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = -%a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig created+12
......@@ -0,0 +1,12 @@
1const y = neg(-128);
2fn neg(x: i8) i8 {
3 return -x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:12: error: negation caused overflow
test/cases/compile_errors/stage1/obj/nested_error_set_mismatch.zig created+20
......@@ -0,0 +1,20 @@
1const NextError = error{NextError};
2const OtherError = error{OutOfMemory};
3
4export fn entry() void {
5 const a: ?NextError!i32 = foo();
6 _ = a;
7}
8
9fn foo() ?OtherError!i32 {
10 return null;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'
18// tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'
19// tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'
20// tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set
test/cases/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 foo(error.A);
3}
4fn foo(a: anyerror) void {
5 switch (a) {
6 error.A => {},
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:5: error: else prong required when switching on type 'anyerror'
test/cases/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig created+8
......@@ -0,0 +1,8 @@
1fn f(noalias x: i32) void { _ = x; }
2export fn entry() void { f(1234); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:6: error: noalias on non-pointer parameter
test/cases/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig created+15
......@@ -0,0 +1,15 @@
1export fn a() void {
2 var non_async_fn: fn () void = undefined;
3 non_async_fn = func;
4}
5fn func() void {
6 suspend {}
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:1: error: 'func' cannot be async
14// tmp.zig:3:20: note: required to be non-async here
15// tmp.zig:6:5: note: suspends here
test/cases/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig created+17
......@@ -0,0 +1,17 @@
1const Foo = struct {
2 x: i32,
3};
4const a = get_it();
5fn get_it() Foo {
6 global_side_effect = true;
7 return Foo {.x = 13};
8}
9var global_side_effect = false;
10
11export fn entry() usize { return @sizeOf(@TypeOf(a)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:26: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = struct {
2 x: i32,
3};
4const a = Foo {.x = get_it()};
5extern fn get_it() i32;
6
7export fn entry() usize { return @sizeOf(@TypeOf(a)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:21: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/non-const_switch_number_literal.zig created+17
......@@ -0,0 +1,17 @@
1export fn foo() void {
2 const x = switch (bar()) {
3 1, 2 => 1,
4 3, 4 => 2,
5 else => 3,
6 };
7 _ = x;
8}
9fn bar() i32 {
10 return 2;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'
test/cases/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig created+51
......@@ -0,0 +1,51 @@
1export fn entry1() void {
2 var m2 = &2;
3 _ = m2;
4}
5export fn entry2() void {
6 var a = undefined;
7 _ = a;
8}
9export fn entry3() void {
10 var b = 1;
11 _ = b;
12}
13export fn entry4() void {
14 var c = 1.0;
15 _ = c;
16}
17export fn entry5() void {
18 var d = null;
19 _ = d;
20}
21export fn entry6(opaque_: *Opaque) void {
22 var e = opaque_.*;
23 _ = e;
24}
25export fn entry7() void {
26 var f = i32;
27 _ = f;
28}
29export fn entry8() void {
30 var h = (Foo {}).bar;
31 _ = h;
32}
33const Opaque = opaque {};
34const Foo = struct {
35 fn bar(self: *const Foo) void {_ = self;}
36};
37
38// error
39// backend=stage1
40// target=native
41//
42// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime
43// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime
44// tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime
45// tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
46// tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime
47// tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
48// tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime
49// tmp.zig:22:4: error: variable of type 'Opaque' not allowed
50// tmp.zig:26:4: error: variable of type 'type' must be const or comptime
51// tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime
test/cases/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = union(u32) {
2 A: i32,
3};
4export fn entry() void {
5 const x = @typeInfo(Foo).Union.tag_type.?;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:19: error: expected enum tag type, found 'u32'
test/cases/compile_errors/stage1/obj/non-extern_function_with_var_args.zig created+10
......@@ -0,0 +1,10 @@
1fn foo(args: ...) void {}
2export fn entry() void {
3 foo();
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:14: error: expected type expression, found '...'
test/cases/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig created+14
......@@ -0,0 +1,14 @@
1const Foo = struct {
2 name: []const u8,
3 T: type,
4};
5export fn entry() void {
6 const xx: [2]Foo = undefined;
7 for (xx) |f| { _ = f;}
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known
test/cases/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = union(enum(f32)) {
2 A: i32,
3};
4export fn entry() void {
5 const x = @typeInfo(Foo).Union.tag_type.?;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:24: error: expected integer tag type, found 'f32'
test/cases/compile_errors/stage1/obj/non-pure_function_returns_type.zig created+24
......@@ -0,0 +1,24 @@
1var a: u32 = 0;
2pub fn List(comptime T: type) type {
3 a += 1;
4 return SmallList(T, 8);
5}
6
7pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
8 return struct {
9 items: []T,
10 length: usize,
11 prealloc_items: [STATIC_SIZE]T,
12 };
13}
14
15export fn function_with_return_type_type() void {
16 var list: List(i32) = undefined;
17 list.length = 10;
18}
19
20// error
21// backend=stage1
22// target=native
23//
24// tmp.zig:3:7: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var ptr = afunc;
3 var bytes: [100]u8 align(16) = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});
5}
6fn afunc() void { }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:32: error: expected async function, found 'fn() void'
test/cases/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig created+11
......@@ -0,0 +1,11 @@
1fn f() []u8 {
2 return s ++ "foo";
3}
4var s: [10]u8 = undefined;
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:12: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig created+14
......@@ -0,0 +1,14 @@
1const Foo = struct {
2 y: [get()]u8,
3};
4var global_var: usize = 1;
5fn get() usize { return global_var; }
6
7export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:25: error: cannot store runtime value in compile time variable
14// tmp.zig:2:12: note: called from here
test/cases/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig created+17
......@@ -0,0 +1,17 @@
1export fn foo() void {
2 const Errors = u8 || u16;
3 _ = Errors;
4}
5export fn bar() void {
6 const Errors = error{} || u16;
7 _ = Errors;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:20: error: expected error set type, found type 'u8'
15// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR
16// tmp.zig:6:31: error: expected error set type, found type 'u16'
17// tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR
test/cases/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = @floatToInt(i32, @as(i32, 54));
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:32: error: expected float type, found 'i32'
test/cases/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = @intToFloat(f32, 1.1);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:32: error: expected int type, found 'comptime_float'
test/cases/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(x: i32) usize {
2 return @ptrToInt(x);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: expected pointer, found 'i32'
test/cases/compile_errors/stage1/obj/normal_string_with_newline.zig created+9
......@@ -0,0 +1,9 @@
1const foo = "a
2b";
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:13: error: expected expression, found 'invalid bytes'
9// tmp.zig:1:15: note: invalid byte: '\n'
test/cases/compile_errors/stage1/obj/offsetOf-bad_field_name.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = struct {
2 derp: i32,
3};
4export fn foo() usize {
5 return @offsetOf(Foo, "a",);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:27: error: struct 'Foo' has no field 'a'
test/cases/compile_errors/stage1/obj/offsetOf-non_struct.zig created+10
......@@ -0,0 +1,10 @@
1const Foo = i32;
2export fn foo() usize {
3 return @offsetOf(Foo, "a",);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:22: error: expected struct type, found 'i32'
test/cases/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 const z = error.A > error.B;
3 _ = z;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:23: error: operator not allowed for errors
test/cases/compile_errors/stage1/obj/opaque_type_with_field.zig created+11
......@@ -0,0 +1,11 @@
1const Opaque = opaque { foo: i32 };
2export fn entry() void {
3 const foo: ?*Opaque = null;
4 _ = foo;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:25: error: opaque types cannot have fields
test/cases/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig created+14
......@@ -0,0 +1,14 @@
1const Foo = extern struct {
2 x: ?*const void,
3};
4const Bar = extern struct {
5 foo: Foo,
6 y: i32,
7};
8export fn entry(bar: *Bar) void {_ = bar;}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'
test/cases/compile_errors/stage1/obj/or_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: bool = undefined;
3 _ = a or a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/orelse_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: ?bool = undefined;
3 _ = a orelse false;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = @floatToInt(i8, 200);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'
test/cases/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig created+14
......@@ -0,0 +1,14 @@
1const Moo = enum(u8) {
2 Last = 255,
3 Over,
4};
5pub fn main() void {
6 var y = Moo.Last;
7 _ = y;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'
test/cases/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig created+20
......@@ -0,0 +1,20 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = packed union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10};
11export fn entry() void {
12 var a = Payload { .A = 1234 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:6:30: error: packed union does not support enum tag type
test/cases/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig created+18
......@@ -0,0 +1,18 @@
1const Foo = struct {
2 a: u32,
3 b: f32,
4};
5const Payload = packed union {
6 A: Foo,
7 B: bool,
8};
9export fn entry() void {
10 var a = Payload { .B = true };
11 _ = a;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation
test/cases/compile_errors/stage1/obj/panic_called_at_compile_time.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 comptime {
3 @panic("aoeu",);
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: encountered @panic at compile-time
test/cases/compile_errors/stage1/obj/parameter_redeclaration.zig created+10
......@@ -0,0 +1,10 @@
1fn f(a : i32, a : i32) void {
2}
3export fn entry() void { f(1, 2); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:15: error: redeclaration of function parameter 'a'
10// tmp.zig:1:6: note: previous declaration here
test/cases/compile_errors/stage1/obj/parameter_shadowing_global.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = struct {};
2fn f(Foo: i32) void {}
3export fn entry() void {
4 f(1234);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:6: error: local shadows declaration of 'Foo'
12// tmp.zig:1:1: note: declared here
test/cases/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig created+17
......@@ -0,0 +1,17 @@
1fn foo() bool {
2 const a = @as([]const u8, "a",);
3 const b = &a;
4 return ptrEql(b, b);
5}
6fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
7 _ = a; _ = b;
8 return true;
9}
10
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'
test/cases/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig created+12
......@@ -0,0 +1,12 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn entry() bool {
3 var x: i32 align(1) = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
5 return x == 5678;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'
test/cases/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
3}
4fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
5 if (ptr() != answer) unreachable;
6}
7fn alignedSmall() align(4) i32 { return 1234; }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'
test/cases/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig created+11
......@@ -0,0 +1,11 @@
1export fn func() void {
2 var strValue: [*c]u8 = undefined;
3 strValue = strValue orelse "";
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'
11// tmp.zig:3:32: note: cast discards const qualifier
test/cases/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig created+12
......@@ -0,0 +1,12 @@
1export fn foo() void {
2 var x: [10]u8 = undefined;
3 var y = &x;
4 var z = y + 1;
5 _ = z;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'
test/cases/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig created+24
......@@ -0,0 +1,24 @@
1comptime {
2 const c: [][]const u8 = &.{"hello", "world" };
3 _ = c;
4}
5comptime {
6 const c: *[2][]const u8 = &.{"hello", "world" };
7 _ = c;
8}
9const S = struct {a: u8 = 1, b: u32 = 2};
10comptime {
11 const c: *S = &.{};
12 _ = c;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'
20// tmp.zig:2:31: note: cast discards const qualifier
21// tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8'
22// tmp.zig:6:33: note: cast discards const qualifier
23// tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'
24// tmp.zig:11:21: note: cast discards const qualifier
test/cases/compile_errors/stage1/obj/pointer_to_noreturn.zig created+8
......@@ -0,0 +1,8 @@
1fn a() *noreturn {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:9: error: pointer to noreturn not allowed
test/cases/compile_errors/stage1/obj/popCount-non-integer.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(x: f32) u32 {
2 return @popCount(f32, x);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: expected integer type, found 'f32'
test/cases/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig created+24
......@@ -0,0 +1,24 @@
1export fn a() void {
2 var x: anyframe = undefined;
3 var y: anyframe->i32 = x;
4 _ = y;
5}
6export fn b() void {
7 var x: i32 = undefined;
8 var y: anyframe->i32 = x;
9 _ = y;
10}
11export fn c() void {
12 var x: @Frame(func) = undefined;
13 var y: anyframe->i32 = &x;
14 _ = y;
15}
16fn func() void {}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'
23// tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'
24// tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'
test/cases/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig created+11
......@@ -0,0 +1,11 @@
1const @"u8" = u16;
2export fn entry() void {
3 const a: u8 = 300;
4 _ = a;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'
test/cases/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() bool {
2 var x: u0 = 0;
3 const p = @ptrCast(?*u0, &x);
4 return p == null;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation
12// tmp.zig:3:31: note: '*u0' has no in-memory bits
13// tmp.zig:3:24: note: '?*u0' has in-memory bits
test/cases/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 const x: i32 = 1234;
3 const y = @ptrCast(*i32, &x);
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:15: error: cast discards const qualifier
test/cases/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var b = @intToPtr(*i32, 0);
3 _ = b;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:13: error: pointer type '*i32' does not allow address zero
test/cases/compile_errors/stage1/obj/ptrToInt_on_void.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() bool {
2 return @ptrToInt(&{}) == @ptrToInt(&{});
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:23: error: pointer to size 0 type has no address
test/cases/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(a: *i32) usize {
2 return @ptrCast(usize, a);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:21: error: expected pointer, found 'usize'
test/cases/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig created+19
......@@ -0,0 +1,19 @@
1export fn entry() void {
2 try foo(452) catch |err| switch (err) {
3 error.A ... error.B => {},
4 else => {},
5 };
6}
7fn foo(x: i32) !void {
8 switch (x) {
9 0 ... 10 => return error.Foo,
10 11 ... 20 => return error.Bar,
11 else => {},
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:3:17: error: operator not allowed for errors
test/cases/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig created+13
......@@ -0,0 +1,13 @@
1comptime {
2 const array: [4]u8 = "aoeu".*;
3 const sub_array = array[1..];
4 const int_ptr = @ptrCast(*const u24, sub_array);
5 const deref = int_ptr.*;
6 _ = deref;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes
test/cases/compile_errors/stage1/obj/recursive_inferred_error_set.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 foo() catch unreachable;
3}
4fn foo() !void {
5 try foo();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet
test/cases/compile_errors/stage1/obj/redefinition_of_enums.zig created+9
......@@ -0,0 +1,9 @@
1const A = enum {x};
2const A = enum {x};
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:1: error: redeclaration of 'A'
9// tmp.zig:1:1: note: other declaration here
test/cases/compile_errors/stage1/obj/redefinition_of_global_variables.zig created+9
......@@ -0,0 +1,9 @@
1var a : i32 = 1;
2var a : i32 = 2;
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:1: error: redeclaration of 'a'
9// tmp.zig:1:1: note: other declaration here
test/cases/compile_errors/stage1/obj/redefinition_of_struct.zig created+9
......@@ -0,0 +1,9 @@
1const A = struct { x : i32, };
2const A = struct { y : i32, };
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:1: error: redeclaration of 'A'
9// tmp.zig:1:1: note: other declaration here
test/cases/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 const Func = fn (type) void;
3 const f: Func = undefined;
4 f(i32);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig created+17
......@@ -0,0 +1,17 @@
1const UsbDeviceRequest = struct {
2 Type: u8,
3};
4
5export fn foo() void {
6 comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
7}
8
9fn assert(ok: bool) void {
10 if (!ok) unreachable;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:10:14: error: reached unreachable code
test/cases/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig created+21
......@@ -0,0 +1,21 @@
1const Foo = struct {
2 ptr: ?*usize,
3 uval: u32,
4};
5fn get_uval(x: u32) !u32 {
6 _ = x;
7 return error.NotFound;
8}
9export fn entry() void {
10 const afoo = Foo{
11 .ptr = null,
12 .uval = get_uval(42),
13 };
14 _ = afoo;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
test/cases/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig created+17
......@@ -0,0 +1,17 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = true,
6 .is_var_args = false,
7 .return_type = u0,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type
test/cases/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig created+17
......@@ -0,0 +1,17 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = false,
6 .is_var_args = true,
7 .return_type = u0,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:20: error: varargs functions must have C calling convention
test/cases/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig created+17
......@@ -0,0 +1,17 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = false,
6 .is_var_args = false,
7 .return_type = null,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type
test/cases/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig created+18
......@@ -0,0 +1,18 @@
1export fn entry() void {
2 _ = @Type(.{ .Pointer = .{
3 .size = .One,
4 .is_const = false,
5 .is_volatile = false,
6 .alignment = 1,
7 .address_space = .gs,
8 .child = u8,
9 .is_allowzero = false,
10 .sentinel = null,
11 }});
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic
test/cases/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig created+18
......@@ -0,0 +1,18 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = bool,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = false,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'
test/cases/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig created+18
......@@ -0,0 +1,18 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = undefined,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = false,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig created+18
......@@ -0,0 +1,18 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = true,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:1:20: error: enums must have 1 or more fields
test/cases/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig created+34
......@@ -0,0 +1,34 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u2,
5 .fields = &.{
6 .{ .name = "signed", .value = 0 },
7 .{ .name = "unsigned", .value = 1 },
8 .{ .name = "arst", .value = 2 },
9 },
10 .decls = &.{},
11 .is_exhaustive = true,
12 },
13});
14const Tagged = @Type(.{
15 .Union = .{
16 .layout = .Auto,
17 .tag_type = Tag,
18 .fields = &.{
19 .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
20 .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
21 },
22 .decls = &.{},
23 },
24});
25export fn entry() void {
26 var tagged = Tagged{ .signed = -1 };
27 tagged = .{ .unsigned = 1 };
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:14:23: error: enum field missing: 'arst'
test/cases/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig created+35
......@@ -0,0 +1,35 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,
5 .fields = &.{
6 .{ .name = "signed", .value = 0 },
7 .{ .name = "unsigned", .value = 1 },
8 },
9 .decls = &.{},
10 .is_exhaustive = true,
11 },
12});
13const Tagged = @Type(.{
14 .Union = .{
15 .layout = .Auto,
16 .tag_type = Tag,
17 .fields = &.{
18 .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
19 .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
20 .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
21 },
22 .decls = &.{},
23 },
24});
25export fn entry() void {
26 var tagged = Tagged{ .signed = -1 };
27 tagged = .{ .unsigned = 1 };
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:13:23: error: enum field not found: 'arst'
35// tmp.zig:1:20: note: enum declared here
test/cases/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig created+19
......@@ -0,0 +1,19 @@
1const Untagged = @Type(.{
2 .Union = .{
3 .layout = .Auto,
4 .tag_type = null,
5 .fields = &.{
6 .{ .name = "foo", .field_type = opaque {}, .alignment = 1 },
7 },
8 .decls = &.{},
9 },
10});
11export fn entry() void {
12 _ = Untagged{};
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions
test/cases/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig created+17
......@@ -0,0 +1,17 @@
1const Untagged = @Type(.{
2 .Union = .{
3 .layout = .Auto,
4 .tag_type = null,
5 .fields = &.{},
6 .decls = &.{},
7 },
8});
9export fn entry() void {
10 _ = Untagged{};
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:25: error: unions must have 1 or more fields
test/cases/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig created+10
......@@ -0,0 +1,10 @@
1const Foo = @Type(.{
2 .Struct = undefined,
3});
4comptime { _ = Foo; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/reify_type_with_Type.Int.zig created+13
......@@ -0,0 +1,13 @@
1const builtin = @import("std").builtin;
2export fn entry() void {
3 _ = @Type(builtin.Type.Int{
4 .signedness = .signed,
5 .bits = 8,
6 });
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'
test/cases/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig created+11
......@@ -0,0 +1,11 @@
1const builtin = @import("std").builtin;
2var globalTypeInfo : builtin.Type = undefined;
3export fn entry() void {
4 _ = @Type(globalTypeInfo);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:15: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/reify_type_with_undefined.zig created+20
......@@ -0,0 +1,20 @@
1comptime {
2 _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });
3}
4comptime {
5 _ = @Type(.{
6 .Struct = .{
7 .fields = undefined,
8 .decls = undefined,
9 .is_tuple = false,
10 .layout = .Auto,
11 },
12 });
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:16: error: use of undefined value here causes undefined behavior
20// tmp.zig:5:16: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig created+18
......@@ -0,0 +1,18 @@
1export fn entry() void {
2 var damn = Container{
3 .not_optional = getOptional(),
4 };
5 _ = damn;
6}
7pub fn getOptional() ?i32 {
8 return 0;
9}
10pub const Container = struct {
11 not_optional: i32,
12};
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/cases/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig created+18
......@@ -0,0 +1,18 @@
1export fn entry() void {
2 var damn = Container{
3 .not_optional = getOptional(i32),
4 };
5 _ = damn;
6}
7pub fn getOptional(comptime T: type) ?T {
8 return 0;
9}
10pub const Container = struct {
11 not_optional: i32,
12};
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/cases/compile_errors/stage1/obj/return_from_defer_expression.zig created+21
......@@ -0,0 +1,21 @@
1pub fn testTrickyDefer() !void {
2 defer canFail() catch {};
3
4 defer try canFail();
5
6 const a = maybeInt() orelse return;
7}
8
9fn canFail() anyerror!void { }
10
11pub fn maybeInt() ?i32 {
12 return 0;
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:4:11: error: 'try' not allowed inside defer expression
test/cases/compile_errors/stage1/obj/returning_error_from_void_async_function.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 return error.ShouldBeCompileError;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'
test/cases/compile_errors/stage1/obj/runtime-known_async_function_called.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() void {
5 var ptr = afunc;
6 _ = ptr();
7}
8fn afunc() callconv(.Async) void {}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required
test/cases/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var ptr = afunc;
3 _ = async ptr();
4}
5
6fn afunc() callconv(.Async) void { }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required
test/cases/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = struct {
2 Bar: u8,
3 Baz: type,
4};
5export fn f() void {
6 var x: u8 = 0;
7 const foo = Foo { .Bar = x, .Baz = u8 };
8 _ = foo;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:23: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig created+15
......@@ -0,0 +1,15 @@
1const Foo = union {
2 Bar: u8,
3 Baz: type,
4};
5export fn f() void {
6 var x: u8 = 0;
7 const foo = Foo { .Bar = x };
8 _ = foo;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:23: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig created+20
......@@ -0,0 +1,20 @@
1const Letter = enum { A, B, C };
2const Value = union(Letter) {
3 A: i32,
4 B,
5 C,
6};
7export fn entry() void {
8 foo(Letter.A);
9}
10fn foo(l: Letter) void {
11 var x: Value = l;
12 _ = x;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields
20// tmp.zig:3:5: note: field 'A' has type 'i32'
test/cases/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig created+17
......@@ -0,0 +1,17 @@
1const Struct = struct {
2 a: u32,
3};
4fn getIndex() usize {
5 return 2;
6}
7export fn entry() void {
8 const index = getIndex();
9 const field = @typeInfo(Struct).Struct.fields[index];
10 _ = field;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known
test/cases/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 _ = @as(f32, 1.0) +| @as(f32, 1.0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// error: invalid operands to binary expression: 'f32' and 'f32'
test/cases/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig created+12
......@@ -0,0 +1,12 @@
1export fn a() void {
2 comptime {
3 var x = @as(i32, 1);
4 x <<|= @as(i32, -2);
5 }
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// error: shift by negative value -2
test/cases/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 _ = @as(i32, 1) <<| @as(i32, -2);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// error: shift by negative value -2
test/cases/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Inline) void {
5 @setAlignStack(16);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: @setAlignStack in inline function
test/cases/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() callconv(.Naked) void {
2 @setAlignStack(16);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @setAlignStack in naked function
test/cases/compile_errors/stage1/obj/setAlignStack_outside_function.zig created+9
......@@ -0,0 +1,9 @@
1comptime {
2 @setAlignStack(16);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @setAlignStack outside function
test/cases/compile_errors/stage1/obj/setAlignStack_set_twice.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 @setAlignStack(16);
3 @setAlignStack(16);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: alignstack set twice
11// tmp.zig:2:5: note: first set here
test/cases/compile_errors/stage1/obj/setAlignStack_too_big.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 @setAlignStack(511 + 1);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256
test/cases/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig created+11
......@@ -0,0 +1,11 @@
1export fn foo() void {
2 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
3 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: float mode set twice for same scope
11// tmp.zig:2:5: note: first set here
test/cases/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig created+11
......@@ -0,0 +1,11 @@
1export fn foo() void {
2 @setRuntimeSafety(false);
3 @setRuntimeSafety(false);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: runtime safety set twice for same scope
11// tmp.zig:2:5: note: first set here
test/cases/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() i32 {
2 var foo: i32 linksection(".text2") = 1234;
3 return foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:30: error: cannot set section of local variable 'foo'
test/cases/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = 1 << &@as(u8, 10);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'
test/cases/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a = 1 >> -1;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:18: error: shift by negative value -1
test/cases/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a >>= 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/shift_left_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a << 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a >>= 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/shift_right_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a >> 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(x: u8, y: u8) u8 {
2 return x << y;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:17: error: expected type 'u3', found 'u8'
test/cases/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry(x: u8) u8 {
2 return 0x11 << x;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known
test/cases/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 const x = @shlExact(@as(u8, 0b01010101), 2);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: operation caused overflow
test/cases/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 const x = @shrExact(@as(u8, 0b10101010), 2);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: exact shift shifted out 1 bits
test/cases/compile_errors/stage1/obj/signed_integer_division.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a / b;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact
test/cases/compile_errors/stage1/obj/signed_integer_remainder_division.zig created+9
......@@ -0,0 +1,9 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a % b;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod
test/cases/compile_errors/stage1/obj/sizeOf_bad_type.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() usize {
2 return @sizeOf(@TypeOf(null));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:20: error: no size available for type '@Type(.Null)'
test/cases/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig created+11
......@@ -0,0 +1,11 @@
1export fn foo() void {
2 const bytes = [1]u8{ 0xfa } ** 16;
3 var value = @ptrCast(*const []const u8, &bytes).*;
4 _ = value;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted
test/cases/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = []u8{};
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/cases/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = []u8{1, 2};
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/cases/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
3 _ = y;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'
test/cases/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig created+12
......@@ -0,0 +1,12 @@
1fn foo() [:0]u8 {
2 var x: []u8 = undefined;
3 return x;
4}
5comptime { _ = foo; }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'
12// tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel
test/cases/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig created+10
......@@ -0,0 +1,10 @@
1var buf: *[1]u8 = undefined;
2export fn entry() void {
3 _ = buf[0..1];
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: non-zero length slice of undefined pointer
test/cases/compile_errors/stage1/obj/slicing_single-item_pointer.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry(ptr: *i32) void {
2 const slice = ptr[0..2];
3 _ = slice;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:22: error: slice of single-item pointer
test/cases/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig created+18
......@@ -0,0 +1,18 @@
1const Small = enum (u2) {
2 One,
3 Two,
4 Three,
5 Four,
6 Five,
7};
8
9export fn entry() void {
10 var x = Small.One;
11 _ = x;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'
test/cases/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig created+16
......@@ -0,0 +1,16 @@
1const Small = enum (f32) {
2 One,
3 Two,
4 Three,
5};
6
7export fn entry() void {
8 var x = Small.One;
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:1:21: error: expected integer, found 'f32'
test/cases/compile_errors/stage1/obj/src_outside_function.zig created+9
......@@ -0,0 +1,9 @@
1comptime {
2 @src();
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @src outside function
test/cases/compile_errors/stage1/obj/std.fmt_error_for_unused_arguments.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// ?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'
test/cases/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
3
4 var i: u32 = 0;
5 storev(&v[i], 42);
6}
7
8fn storev(ptr: anytype, val: i32) void {
9 ptr.* = val;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/cases/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig created+49
......@@ -0,0 +1,49 @@
1const Mode = @import("std").builtin.Mode;
2
3fn Free(comptime filename: []const u8) TestCase {
4 return TestCase {
5 .filename = filename,
6 .problem_type = ProblemType.Free,
7 };
8}
9
10fn LibC(comptime filename: []const u8) TestCase {
11 return TestCase {
12 .filename = filename,
13 .problem_type = ProblemType.LinkLibC,
14 };
15}
16
17const TestCase = struct {
18 filename: []const u8,
19 problem_type: ProblemType,
20};
21
22const ProblemType = enum {
23 Free,
24 LinkLibC,
25};
26
27export fn entry() void {
28 const tests = [_]TestCase {
29 Free("001"),
30 Free("002"),
31 LibC("078"),
32 Free("116"),
33 Free("117"),
34 };
35
36 for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
37 _ = mode;
38 inline for (tests) |test_case| {
39 const foo = test_case.filename ++ ".zig";
40 _ = foo;
41 }
42 }
43}
44
45// error
46// backend=stage1
47// target=native
48//
49// tmp.zig:38:29: error: cannot store runtime value in compile time variable
test/cases/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig created+19
......@@ -0,0 +1,19 @@
1const LhsExpr = struct {
2 rhsExpr: ?AstObject,
3};
4const AstObject = union {
5 lhsExpr: LhsExpr,
6};
7export fn entry() void {
8 const lhsExpr = LhsExpr{ .rhsExpr = null };
9 const obj = AstObject{ .lhsExpr = lhsExpr };
10 _ = obj;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:17: error: struct 'LhsExpr' depends on itself
18// tmp.zig:5:5: note: while checking this field
19// tmp.zig:2:5: note: while checking this field
test/cases/compile_errors/stage1/obj/struct_field_missing_type.zig created+13
......@@ -0,0 +1,13 @@
1const Letter = struct {
2 A,
3};
4export fn entry() void {
5 var a = Letter { .A = {} };
6 _ = a;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: struct field missing type
test/cases/compile_errors/stage1/obj/struct_init_syntax_for_array.zig created+10
......@@ -0,0 +1,10 @@
1const foo = [3]u16{ .x = 1024 };
2comptime {
3 _ = foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:13: error: initializing array with struct syntax
test/cases/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 _ = @Type(@typeInfo(struct { const foo = 1; }));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type
test/cases/compile_errors/stage1/obj/struct_with_invalid_field.zig created+30
......@@ -0,0 +1,30 @@
1const std = @import("std",);
2const Allocator = std.mem.Allocator;
3const ArrayList = std.ArrayList;
4
5const HeaderWeight = enum {
6 H1, H2, H3, H4, H5, H6,
7};
8
9const MdText = ArrayList(u8);
10
11const MdNode = union(enum) {
12 Header: struct {
13 text: MdText,
14 weight: HeaderValue,
15 },
16};
17
18export fn entry() void {
19 const a = MdNode.Header {
20 .text = MdText.init(std.testing.allocator),
21 .weight = HeaderWeight.H1,
22 };
23 _ = a;
24}
25
26// error
27// backend=stage1
28// target=native
29//
30// tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'
test/cases/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a -= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/sub_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a - a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig created+12
......@@ -0,0 +1,12 @@
1const y = sub(10, 20);
2fn sub(a: u16, b: u16) u16 {
3 return a - b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/cases/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 a -%= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a -% a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/suspend_inside_suspend_block.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 _ = async foo();
3}
4fn foo() void {
5 suspend {
6 suspend {
7 }
8 }
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:6:9: error: cannot suspend inside suspend block
16// tmp.zig:5:5: note: other suspend block here
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig created+24
......@@ -0,0 +1,24 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 Number.Four => 4,
13 Number.Two => 2,
14 }
15}
16
17export fn entry() usize { return @sizeOf(@TypeOf(f)); }
18
19// error
20// backend=stage1
21// target=native
22//
23// tmp.zig:13:15: error: duplicate switch value
24// tmp.zig:10:15: note: other value here
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig created+25
......@@ -0,0 +1,25 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 Number.Four => 4,
13 Number.Two => 2,
14 else => 10,
15 }
16}
17
18export fn entry() usize { return @sizeOf(@TypeOf(f)); }
19
20// error
21// backend=stage1
22// target=native
23//
24// tmp.zig:13:15: error: duplicate switch value
25// tmp.zig:10:15: note: other value here
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig created+16
......@@ -0,0 +1,16 @@
1fn foo(x: u8) u8 {
2 return switch (x) {
3 0 ... 100 => @as(u8, 0),
4 101 ... 200 => 1,
5 201, 203 ... 207 => 2,
6 206 ... 255 => 3,
7 };
8}
9export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:6:9: error: duplicate switch value
16// tmp.zig:5:14: note: previous value here
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_type.zig created+17
......@@ -0,0 +1,17 @@
1fn foo(comptime T: type, x: T) u8 {
2 _ = x;
3 return switch (T) {
4 u32 => 0,
5 u64 => 1,
6 u32 => 2,
7 else => 3,
8 };
9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:9: error: duplicate switch value
17// tmp.zig:4:9: note: previous value here
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig created+21
......@@ -0,0 +1,21 @@
1const Test = struct {
2 bar: i32,
3};
4const Test2 = Test;
5fn foo(comptime T: type, x: T) u8 {
6 _ = x;
7 return switch (T) {
8 Test => 0,
9 u64 => 1,
10 Test2 => 2,
11 else => 3,
12 };
13}
14export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:10:9: error: duplicate switch value
21// tmp.zig:8:9: note: previous value here
test/cases/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig created+21
......@@ -0,0 +1,21 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 }
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(f)); }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch
test/cases/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig created+16
......@@ -0,0 +1,16 @@
1fn f(x: u32) void {
2 const value: bool = switch (x) {
3 1234 => false,
4 else => true,
5 else => true,
6 };
7}
8export fn entry() void {
9 f(1234);
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:5:9: error: multiple else prongs in switch expression
test/cases/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig created+12
......@@ -0,0 +1,12 @@
1fn foo(x: u8) void {
2 switch (x) {
3 0 => {},
4 }
5}
6export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:5: error: switch must handle all possibilities
test/cases/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig created+13
......@@ -0,0 +1,13 @@
1fn foo(x: *u8) void {
2 switch (x) {
3 &y => {},
4 }
5}
6const y: u8 = 100;
7export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: else prong required when switching on type '*u8'
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig created+14
......@@ -0,0 +1,14 @@
1fn foo(x: bool) void {
2 switch (x) {
3 true => {},
4 false => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig created+24
......@@ -0,0 +1,24 @@
1const TestEnum = enum{ T1, T2 };
2
3fn err(x: u8) TestEnum {
4 switch (x) {
5 0 => return TestEnum.T1,
6 else => return TestEnum.T2,
7 }
8}
9
10fn foo(x: u8) void {
11 switch (err(x)) {
12 TestEnum.T1 => {},
13 TestEnum.T2 => {},
14 else => {},
15 }
16}
17
18export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
19
20// error
21// backend=stage1
22// target=native
23//
24// tmp.zig:14:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig created+17
......@@ -0,0 +1,17 @@
1fn foo(x: i8) void {
2 switch (x) {
3 -128...0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 4...127 => {},
8 else => {},
9 }
10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig created+17
......@@ -0,0 +1,17 @@
1fn foo(x: u8) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 4...255 => {},
8 else => {},
9 }
10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig created+14
......@@ -0,0 +1,14 @@
1fn foo(x: u1) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig created+16
......@@ -0,0 +1,16 @@
1fn foo(x: u2) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 else => {},
8 }
9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:7:9: error: unreachable else prong, all cases already handled
test/cases/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig created+12
......@@ -0,0 +1,12 @@
1const Foo = enum { M };
2
3export fn entry() void {
4 var f = Foo.M;
5 switch (f) {}
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch
test/cases/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig created+22
......@@ -0,0 +1,22 @@
1const Payload = union {
2 A: i32,
3 B: f64,
4 C: bool,
5};
6export fn entry() void {
7 const a = Payload { .A = 1234 };
8 foo(a);
9}
10fn foo(a: *const Payload) void {
11 switch (a.*) {
12 Payload.A => {},
13 else => unreachable,
14 }
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:11:14: error: switch on union which has no attached enum
22// tmp.zig:1:17: note: consider 'union(enum)' here
test/cases/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig created+17
......@@ -0,0 +1,17 @@
1export fn entry() void {
2 Test(i32);
3}
4fn Test(comptime T: type) void {
5 const x = switch (T) {
6 []u8 => |x| x,
7 i32 => |x| x,
8 else => unreachable,
9 };
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter
test/cases/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 var q: u8 = 0;
3 switch (q) {
4 1...2 => {},
5 0...255 => {},
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:9: error: duplicate switch value
test/cases/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig created+16
......@@ -0,0 +1,16 @@
1const FloatInt = extern union {
2 Float: f32,
3 Int: i32,
4};
5export fn entry() void {
6 var fi = FloatInt{.Float = 123.45};
7 var tagName = @tagName(fi);
8 _ = tagName;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:19: error: union has no associated enum
16// tmp.zig:1:18: note: declared here
test/cases/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = 'a'.*[0..];
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'
test/cases/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig created+13
......@@ -0,0 +1,13 @@
1const Empty = struct {
2 val: void,
3};
4export fn foo() void {
5 const fieldOffset = @bitOffsetOf(Empty, "val",);
6 _ = fieldOffset;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset
test/cases/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig created+13
......@@ -0,0 +1,13 @@
1const Empty = struct {
2 val: void,
3};
4export fn foo() void {
5 const fieldOffset = @offsetOf(Empty, "val",);
6 _ = fieldOffset;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset
test/cases/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig created+10
......@@ -0,0 +1,10 @@
1threadlocal const x: i32 = 1234;
2export fn entry() i32 {
3 return x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:1: error: threadlocal variable cannot be constant
test/cases/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig created+12
......@@ -0,0 +1,12 @@
1const a : @TypeOf(b) = 0;
2const b : @TypeOf(a) = 0;
3export fn entry() void {
4 const c = a + b;
5 _ = c;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:19: error: dependency loop detected
test/cases/compile_errors/stage1/obj/truncate_sign_mismatch.zig created+25
......@@ -0,0 +1,25 @@
1export fn entry1() i8 {
2 var x: u32 = 10;
3 return @truncate(i8, x);
4}
5export fn entry2() u8 {
6 var x: i32 = -10;
7 return @truncate(u8, x);
8}
9export fn entry3() i8 {
10 comptime var x: u32 = 10;
11 return @truncate(i8, x);
12}
13export fn entry4() u8 {
14 comptime var x: i32 = -10;
15 return @truncate(u8, x);
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:3:26: error: expected signed integer type, found 'u32'
23// tmp.zig:7:26: error: expected unsigned integer type, found 'i32'
24// tmp.zig:11:26: error: expected signed integer type, found 'u32'
25// tmp.zig:15:26: error: expected unsigned integer type, found 'i32'
test/cases/compile_errors/stage1/obj/truncate_undefined_value.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var z = @truncate(u8, @as(u16, undefined));
3 _ = z;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:27: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 try something();
3}
4fn something() anyerror!void { }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: expected type 'void', found 'anyerror'
test/cases/compile_errors/stage1/obj/type_checking_function_pointers.zig created+13
......@@ -0,0 +1,13 @@
1fn a(b: fn (*const u8) void) void {
2 b('a');
3}
4fn c(d: u8) void {_ = d;}
5export fn entry() void {
6 a(c);
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'
test/cases/compile_errors/stage1/obj/type_variables_must_be_constant.zig created+10
......@@ -0,0 +1,10 @@
1var foo = u8;
2export fn entry() foo {
3 return 1;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:1: error: variable of type 'type' must be constant
test/cases/compile_errors/stage1/obj/undeclared_identifier.zig created+11
......@@ -0,0 +1,11 @@
1export fn a() void {
2 return
3 b +
4 c;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:5: error: use of undeclared identifier 'b'
test/cases/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig created+12
......@@ -0,0 +1,12 @@
1export fn foo() void {
2 test_a_thing();
3}
4fn test_a_thing() void {
5 bad_fn_call();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'
test/cases/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig created+11
......@@ -0,0 +1,11 @@
1export fn a() void {
2 if (false) {
3 lol_this_doesnt_exist = nonsense;
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'
test/cases/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig created+13
......@@ -0,0 +1,13 @@
1const Foo = struct {
2 a: undefined,
3};
4export fn entry1() void {
5 const foo: Foo = undefined;
6 _ = foo;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:8: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/undefined_function_call.zig created+9
......@@ -0,0 +1,9 @@
1export fn a() void {
2 b();
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/cases/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig created+10
......@@ -0,0 +1,10 @@
1export fn f1() usize {
2 var _: usize = 2;
3 return _;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: '_' used as an identifier without @"_" syntax
test/cases/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig created+13
......@@ -0,0 +1,13 @@
1export fn returns() void {
2 for ([_]void{}) |_, i| {
3 for ([_]void{}) |_, j| {
4 return _;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/cases/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig created+16
......@@ -0,0 +1,16 @@
1export fn returns() void {
2 while (optionalReturn()) |_| {
3 while (optionalReturn()) |_| {
4 return _;
5 }
6 }
7}
8fn optionalReturn() ?u32 {
9 return 1;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/cases/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig created+18
......@@ -0,0 +1,18 @@
1export fn returns() void {
2 while (optionalReturnError()) |_| {
3 while (optionalReturnError()) |_| {
4 return;
5 } else |_| {
6 if (_ == error.optionalReturnError) return;
7 }
8 }
9}
10fn optionalReturnError() !?u32 {
11 return error.optionalReturnError;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:17: error: '_' used as an identifier without @"_" syntax
test/cases/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig created+18
......@@ -0,0 +1,18 @@
1const MultipleChoice = union(enum(u32)) {
2 A = 20,
3 B = 40,
4 C = 60,
5 D = 1000,
6 E = 60,
7};
8export fn entry() void {
9 var x = MultipleChoice { .C = {} };
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:9: error: enum tag value 60 already taken
18// tmp.zig:4:9: note: other occurrence here
test/cases/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig created+22
......@@ -0,0 +1,22 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10 D: bool,
11};
12export fn entry() void {
13 var a = Payload {.A = 1234};
14 _ = a;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:10:5: error: enum field not found: 'D'
22// tmp.zig:1:16: note: enum declared here
test/cases/compile_errors/stage1/obj/union_fields_with_value_assignments.zig created+14
......@@ -0,0 +1,14 @@
1const MultipleChoice = union {
2 A: i32 = 20,
3};
4export fn entry() void {
5 var x: MultipleChoice = undefined;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type
14// tmp.zig:2:14: note: tag value specified here
test/cases/compile_errors/stage1/obj/union_with_0_fields.zig created+7
......@@ -0,0 +1,7 @@
1const Foo = union {};
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:13: error: union declarations must have at least one tag
test/cases/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig created+19
......@@ -0,0 +1,19 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = union(Letter) {
7 A: i32,
8 B: f64,
9};
10export fn entry() usize {
11 return @sizeOf(Payload);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:17: error: enum field missing: 'C'
19// tmp.zig:4:5: note: declared here
test/cases/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig created+16
......@@ -0,0 +1,16 @@
1const U = union(enum(i2)) {
2 A: u8,
3 B: u8,
4 C: u8,
5 D: u8,
6};
7export fn entry() void {
8 _ = U{ .D = 1 };
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:22: error: specified integer tag type cannot represent every field
16// tmp.zig:1:22: note: type i2 cannot fit values in range 0...3
test/cases/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig created+17
......@@ -0,0 +1,17 @@
1const U = union(enum(u2)) {
2 A: u8,
3 B: u8,
4 C: u8,
5 D: u8,
6 E: u8,
7};
8export fn entry() void {
9 _ = U{ .E = 1 };
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:1:22: error: specified integer tag type cannot represent every field
17// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
test/cases/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig created+7
......@@ -0,0 +1,7 @@
1export const T = [*]opaque {};
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:21: error: unknown-length pointer to opaque
test/cases/compile_errors/stage1/obj/unreachable_code-double_break.zig created+12
......@@ -0,0 +1,12 @@
1export fn a() void {
2 const b = blk: {
3 break :blk break :blk @as(u32, 1);
4 };
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: unreachable code
12// tmp.zig:3:20: note: control flow is diverted here
test/cases/compile_errors/stage1/obj/unreachable_code-nested_returns.zig created+10
......@@ -0,0 +1,10 @@
1export fn a() i32 {
2 return return 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: unreachable code
10// tmp.zig:2:12: note: control flow is diverted here
test/cases/compile_errors/stage1/obj/unreachable_code.zig created+13
......@@ -0,0 +1,13 @@
1export fn a() void {
2 return;
3 b();
4}
5
6fn b() void {}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:6: error: unreachable code
13// tmp.zig:2:5: note: control flow is diverted here
test/cases/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig created+16
......@@ -0,0 +1,16 @@
1fn foo(comptime x: i32) i32 {
2 comptime {
3 if (x >= 0) return -x;
4 unreachable;
5 }
6}
7export fn entry() void {
8 _ = foo(-42);
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:4:9: error: reached unreachable code
16// tmp.zig:8:12: note: called from here
test/cases/compile_errors/stage1/obj/unreachable_parameter.zig created+8
......@@ -0,0 +1,8 @@
1fn f(a: noreturn) void { _ = a; }
2export fn entry() void { f(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:9: error: parameter of type 'noreturn' not allowed
test/cases/compile_errors/stage1/obj/unreachable_variable.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() void {
2 const a: noreturn = {};
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:25: error: expected type 'noreturn', found 'void'
test/cases/compile_errors/stage1/obj/unreachable_with_return.zig created+8
......@@ -0,0 +1,8 @@
1fn a() noreturn {return;}
2export fn entry() void { a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:18: error: expected type 'noreturn', found 'void'
test/cases/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 var bar: u32 = 3;
3 asm volatile ("" : [baz]"+r"(bar) : : "");
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215
test/cases/compile_errors/stage1/obj/unused_variable_error_on_errdefer.zig created+13
......@@ -0,0 +1,13 @@
1fn foo() !void {
2 errdefer |a| unreachable;
3 return error.A;
4}
5export fn entry() void {
6 foo() catch unreachable;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:15: error: unused variable: 'a'
test/cases/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const a: fn () anyopaque = undefined;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:20: error: return type cannot be opaque
test/cases/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 var x: i32 = 1234;
3 var p: *i32 = &x;
4 var pp: *?*i32 = &p;
5 pp.* = null;
6 var y = p.*;
7 _ = y;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:4:23: error: expected type '*?*i32', found '**i32'
test/cases/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig created+11
......@@ -0,0 +1,11 @@
1var v = 25;
2export fn entry() void {
3 var arr: [v]u8 = undefined;
4 _ = arr;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:1: error: unable to infer variable type
test/cases/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig created+13
......@@ -0,0 +1,13 @@
1const Cmd = struct {
2 exec: fn () void,
3};
4export fn entry() void {
5 const command = Cmd{ .exec = undefined };
6 command.exec();
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:12: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/use_of_undeclared_identifier.zig created+9
......@@ -0,0 +1,9 @@
1export fn f() void {
2 b = 3;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/cases/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig created+13
......@@ -0,0 +1,13 @@
1const resolutions = [*][*]const u8{
2 "[320 240 ]",
3 null,
4};
5comptime {
6 _ = resolutions;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'
test/cases/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig created+11
......@@ -0,0 +1,11 @@
1const MenuEffect = enum {};
2fn func(effect: MenuEffect) void { _ = effect; }
3export fn entry() void {
4 func(MenuEffect.ThisDoesNotExist);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:20: error: enum declarations must have at least one tag
test/cases/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig created+7
......@@ -0,0 +1,7 @@
1usingnamespace void;
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:1: error: expected struct, enum, or union; found 'void'
test/cases/compile_errors/stage1/obj/variable_has_wrong_type.zig created+10
......@@ -0,0 +1,10 @@
1export fn f() i32 {
2 const a = "a";
3 return a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'
test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var sp = asm volatile ("mov %[foo], sp"
3 : [bar] "=r" (-> usize),
4 );
5 _ = sp;
6}
7
8// error
9// backend=stage1
10// target=x86_64-linux-gnu
11//
12// tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs
test/cases/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig created+19
......@@ -0,0 +1,19 @@
1fn Undeclared() type {
2 return T;
3}
4fn Gen() type {
5 const X = Undeclared();
6 return struct {
7 x: X,
8 };
9}
10export fn entry() void {
11 const S = Gen();
12 _ = S;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:12: error: use of undeclared identifier 'T'
test/cases/compile_errors/stage1/obj/variable_with_type_noreturn.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry9() void {
2 var z: noreturn = return;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: unreachable code
10// tmp.zig:2:23: note: control flow is diverted here
test/cases/compile_errors/stage1/obj/vector_index_out_of_bounds.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:62: error: index 3 outside vector of size 3
test/cases/compile_errors/stage1/obj/volatile_on_global_assembly.zig created+9
......@@ -0,0 +1,9 @@
1comptime {
2 asm volatile ("");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: volatile is meaningless on global assembly
test/cases/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 _ = @wasmMemoryGrow(0, 1);
3 return;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only
test/cases/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 _ = @wasmMemorySize(0);
3 return;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only
test/cases/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 while (bar()) {}
3}
4fn bar() anyerror!i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'
test/cases/compile_errors/stage1/obj/while_expected_bool_got_optional.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 while (bar()) {}
3}
4fn bar() ?i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected type 'bool', found '?i32'
test/cases/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;} else |err| {_ = err;}
3}
4fn bar() bool { return true; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected error union type, found 'bool'
test/cases/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;} else |err| {_ = err;}
3}
4fn bar() ?i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected error union type, found '?i32'
test/cases/compile_errors/stage1/obj/while_expected_optional_got_bool.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;}
3}
4fn bar() bool { return true; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected optional type, found 'bool'
test/cases/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig created+10
......@@ -0,0 +1,10 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;}
3}
4fn bar() anyerror!i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'
test/cases/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig created+22
......@@ -0,0 +1,22 @@
1fn returns() usize {
2 return 2;
3}
4export fn f1() void {
5 while (true) returns();
6}
7export fn f2() void {
8 var x: ?i32 = null;
9 while (x) |_| returns();
10}
11export fn f3() void {
12 var x: anyerror!i32 = error.Bad;
13 while (x) |_| returns() else |_| unreachable;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:5:25: error: expression value is ignored
21// tmp.zig:9:26: error: expression value is ignored
22// tmp.zig:13:26: error: expression value is ignored
test/cases/compile_errors/stage1/obj/write_to_const_global_variable.zig created+11
......@@ -0,0 +1,11 @@
1const x : i32 = 99;
2fn f() void {
3 x = 1;
4}
5export fn entry() void { f(); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: cannot assign to constant
test/cases/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 var frame: @Frame(foo) = undefined;
3 frame = async bar();
4}
5fn foo() void {
6 suspend {}
7}
8fn bar() void {
9 suspend {}
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'
test/cases/compile_errors/stage1/obj/wrong_function_type.zig created+11
......@@ -0,0 +1,11 @@
1const fns = [_]fn() void { a, b, c };
2fn a() i32 {return 0;}
3fn b() i32 {return 1;}
4fn c() i32 {return 2;}
5export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'
test/cases/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig created+16
......@@ -0,0 +1,16 @@
1const U = union(enum) {
2 A: type,
3};
4const S = struct {
5 u: U,
6};
7export fn entry() void {
8 comptime var v: S = undefined;
9 v.u.A = U{ .A = i32 };
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:8: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/stage1/obj/wrong_number_of_arguments.zig created+10
......@@ -0,0 +1,10 @@
1export fn a() void {
2 c(1);
3}
4fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:6: error: expected 3 argument(s), found 1
test/cases/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig created+14
......@@ -0,0 +1,14 @@
1const Foo = struct {
2 fn method(self: *const Foo, a: i32) void {_ = self; _ = a;}
3};
4fn f(foo: *const Foo) void {
5
6 foo.method(1, 2);
7}
8export fn entry() usize { return @sizeOf(@TypeOf(f)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:15: error: expected 2 argument(s), found 3
test/cases/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig created+12
......@@ -0,0 +1,12 @@
1pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
2 _ = msg; _ = error_return_trace;
3 while (true) {}
4}
5const builtin = @import("std").builtin;
6
7// error
8// backend=stage1
9// target=native
10//
11// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'
12// note: only one of the functions is generic
test/cases/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig created+10
......@@ -0,0 +1,10 @@
1test "" {}
2
3pub fn panic() void {}
4
5
6// error
7// backend=stage1
8// target=native
9//
10// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'
test/cases/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig created+12
......@@ -0,0 +1,12 @@
1const Derp = opaque {};
2extern fn bar(d: *Derp) void;
3export fn foo() void {
4 var x = @as(u8, 1);
5 bar(@ptrCast(*anyopaque, &x));
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'
test/cases/compile_errors/stage1/obj/wrong_return_type_for_main.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() f32 { }
2
3// error
4// backend=stage1
5// target=native
6//
7// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/cases/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig created+10
......@@ -0,0 +1,10 @@
1comptime {
2 const array = [2]u8{1, 2, 3};
3 _ = array;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:31: error: index 2 outside array of size 2
test/cases/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry1() void {
2 var frame: @Frame(foo) = undefined;
3 @asyncCall(&frame, {}, foo, {});
4}
5
6fn foo() i32 {
7 return 0;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:33: error: expected tuple or struct, found 'void'
test/cases/compile_errors/stage1/obj/wrong_type_for_reify_type.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() void {
2 _ = @Type(0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'
test/cases/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() i32 {
5 var frame: @Frame(foo) = undefined;
6 return await @asyncCall(&frame, false, foo, .{});
7}
8fn foo() i32 {
9 return 1234;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:37: error: expected type '*i32', found 'bool'
test/cases/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var e = error.Foo;
3 @panic(e);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'
test/cases/compile_errors/stage1/obj/wrong_type_to_hasField.zig created+9
......@@ -0,0 +1,9 @@
1export fn entry() bool {
2 return @hasField(i32, "hi");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: type 'i32' does not support @hasField
test/cases/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 var x: i32 = 1234;
3 while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'
test/cases/compile_errors/stage1/obj/wrong_types_given_to_export.zig created+10
......@@ -0,0 +1,10 @@
1fn entry() callconv(.C) void { }
2comptime {
3 @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'
test/cases/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig created+11
......@@ -0,0 +1,11 @@
1const A = B;
2test "Crash" {
3 _ = @typeInfo(@This()).Struct.decls[0];
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:1:11: error: use of undeclared identifier 'B'
test/cases/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig created+28
......@@ -0,0 +1,28 @@
1export fn foo() void {
2 const a: *void = undefined;
3 _ = @alignCast(2, a);
4}
5export fn bar() void {
6 const a: ?*void = undefined;
7 _ = @alignCast(2, a);
8}
9export fn baz() void {
10 const a: []void = undefined;
11 _ = @alignCast(2, a);
12}
13export fn qux() void {
14 const a = struct {
15 fn a(comptime b: u32) void { _ = b; }
16 }.a;
17 _ = @alignCast(2, a);
18}
19
20// error
21// backend=stage1
22// target=native
23// is_test=1
24//
25// tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'
26// tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'
27// tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'
28// tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'
test/cases/compile_errors/stage1/test/bad_splat_type.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 const c = 4;
3 var v = @splat(4, c);
4 _ = v;
5}
6
7// error
8// backend=stage1
9// target=native
10// is_test=1
11//
12// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid
test/cases/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig created+13
......@@ -0,0 +1,13 @@
1pub const A = error.A;
2pub const AB = A | error.B;
3export fn entry() void {
4 var x: AB = undefined;
5 _ = x;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'
test/cases/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig created+11
......@@ -0,0 +1,11 @@
1pub export fn entry() void {
2 var call_me: fn () void = undefined;
3 @call(.{ .modifier = .always_inline }, call_me, .{});
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/cases/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig created+11
......@@ -0,0 +1,11 @@
1pub export fn entry() void {
2 var call_me: fn () void = undefined;
3 @call(.{ .modifier = .compile_time }, call_me, .{});
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/cases/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig created+15
......@@ -0,0 +1,15 @@
1pub const fnty1 = ?fn (i8) void;
2pub const fnty2 = ?fn (u64) void;
3export fn entry() void {
4 var a: fnty1 = undefined;
5 var b: fnty2 = undefined;
6 a = b;
7}
8
9// error
10// backend=stage1
11// target=native
12// is_test=1
13//
14// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'
15// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'
test/cases/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig created+16
......@@ -0,0 +1,16 @@
1export fn entry() void {
2 nosuspend {
3 const bar = async foo();
4 suspend {}
5 resume bar;
6 }
7}
8fn foo() void {}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:4:9: error: suspend inside nosuspend block
16// tmp.zig:2:5: note: nosuspend block here
test/cases/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig created+14
......@@ -0,0 +1,14 @@
1export fn entry() void {
2 const U = union { A: u32, B: u64 };
3 var u = U{ .A = 42 };
4 var ok = u == .A;
5 _ = ok;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types
14// tmp.zig:2:15: note: type U is not a tagged union
test/cases/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig created+14
......@@ -0,0 +1,14 @@
1comptime {
2 var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
3 var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
4 var x = a + b;
5 _ = x;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:4:15: error: operation caused overflow
14// tmp.zig:4:15: note: when computing vector element at index 2
test/cases/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig created+19
......@@ -0,0 +1,19 @@
1export fn entry() void {
2 const anon = .{
3 .inner = .{
4 .a = .{
5 .something = "text",
6 },
7 .a = .{},
8 },
9 };
10 _ = anon;
11}
12
13// error
14// backend=stage1
15// target=native
16// is_test=1
17//
18// tmp.zig:7:13: error: duplicate field
19// tmp.zig:4:13: note: other field here
test/cases/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig created+15
......@@ -0,0 +1,15 @@
1pub export fn entry() void {
2 const bitfield = struct {
3 e: u8,
4 e: u8,
5 };
6 var a = .{@sizeOf(bitfield)};
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:4:9: error: duplicate struct field: 'e'
test/cases/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig created+11
......@@ -0,0 +1,11 @@
1pub export fn entry() void {
2 var arr: [100]u8 = undefined;
3 for (arr) |bits| _ = @popCount(bits);
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:26: error: expected 2 arguments, found 1
test/cases/compile_errors/stage1/test/export_with_empty_name_string.zig created+11
......@@ -0,0 +1,11 @@
1pub export fn entry() void { }
2comptime {
3 @export(entry, .{ .name = "" });
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:5: error: exported symbol name cannot be empty
test/cases/compile_errors/stage1/test/helpful_return_type_error_message.zig created+30
......@@ -0,0 +1,30 @@
1export fn foo() u32 {
2 return error.Ohno;
3}
4fn bar() !u32 {
5 return error.Ohno;
6}
7export fn baz() void {
8 try bar();
9}
10export fn qux() u32 {
11 return bar();
12}
13export fn quux() u32 {
14 var buf: u32 = 0;
15 buf = bar();
16}
17
18// error
19// backend=stage1
20// target=native
21// is_test=1
22//
23// tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'
24// tmp.zig:1:17: note: function cannot return an error
25// tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'
26// tmp.zig:7:17: note: function cannot return an error
27// tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
28// tmp.zig:10:17: note: function cannot return an error
29// tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
30// tmp.zig:14:5: note: cannot store an error in type 'u32'
test/cases/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig created+16
......@@ -0,0 +1,16 @@
1export fn foo() void {
2 var a: f32 = 2;
3 _ = @floatToInt(comptime_int, a);
4}
5export fn bar() void {
6 var a: u32 = 2;
7 _ = @intToFloat(comptime_float, a);
8}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:3:35: error: unable to evaluate constant expression
16// tmp.zig:7:37: error: unable to evaluate constant expression
test/cases/compile_errors/stage1/test/invalid_assignments.zig created+20
......@@ -0,0 +1,20 @@
1export fn entry1() void {
2 var a: []const u8 = "foo";
3 a[0..2] = "bar";
4}
5export fn entry2() void {
6 var a: u8 = 2;
7 a + 2 = 3;
8}
9export fn entry4() void {
10 2 + 2 = 3;
11}
12
13// error
14// backend=stage1
15// target=native
16// is_test=1
17//
18// tmp.zig:3:6: error: invalid left-hand side to assignment
19// tmp.zig:7:7: error: invalid left-hand side to assignment
20// tmp.zig:10:7: error: invalid left-hand side to assignment
test/cases/compile_errors/stage1/test/invalid_float_casts.zig created+26
......@@ -0,0 +1,26 @@
1export fn foo() void {
2 var a: f32 = 2;
3 _ = @floatCast(comptime_float, a);
4}
5export fn bar() void {
6 var a: f32 = 2;
7 _ = @floatToInt(f32, a);
8}
9export fn baz() void {
10 var a: f32 = 2;
11 _ = @intToFloat(f32, a);
12}
13export fn qux() void {
14 var a: u32 = 2;
15 _ = @floatCast(f32, a);
16}
17
18// error
19// backend=stage1
20// target=native
21// is_test=1
22//
23// tmp.zig:3:36: error: unable to evaluate constant expression
24// tmp.zig:7:21: error: expected integer type, found 'f32'
25// tmp.zig:11:26: error: expected int type, found 'f32'
26// tmp.zig:15:25: error: expected float type, found 'u32'
test/cases/compile_errors/stage1/test/invalid_int_casts.zig created+26
......@@ -0,0 +1,26 @@
1export fn foo() void {
2 var a: u32 = 2;
3 _ = @intCast(comptime_int, a);
4}
5export fn bar() void {
6 var a: u32 = 2;
7 _ = @intToFloat(u32, a);
8}
9export fn baz() void {
10 var a: u32 = 2;
11 _ = @floatToInt(u32, a);
12}
13export fn qux() void {
14 var a: f32 = 2;
15 _ = @intCast(u32, a);
16}
17
18// error
19// backend=stage1
20// target=native
21// is_test=1
22//
23// tmp.zig:3:32: error: unable to evaluate constant expression
24// tmp.zig:7:21: error: expected float type, found 'u32'
25// tmp.zig:11:26: error: expected float type, found 'u32'
26// tmp.zig:15:23: error: expected integer type, found 'f32'
test/cases/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig created+27
......@@ -0,0 +1,27 @@
1const E = enum(u8) {
2 a,
3 b,
4 _,
5};
6const U = union(E) {
7 a,
8 b,
9};
10export fn foo() void {
11 var e = @intToEnum(E, 15);
12 var u: U = e;
13 _ = u;
14}
15export fn bar() void {
16 const e = @intToEnum(E, 15);
17 var u: U = e;
18 _ = u;
19}
20
21// error
22// backend=stage1
23// target=native
24// is_test=1
25//
26// tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum
27// tmp.zig:17:16: error: no tag by value 15
test/cases/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig created+19
......@@ -0,0 +1,19 @@
1export fn entry() void {
2 _ = @Type(.{ .Pointer = .{
3 .size = .One,
4 .is_const = false,
5 .is_volatile = false,
6 .alignment = 1,
7 .address_space = .generic,
8 .child = u8,
9 .is_allowzero = false,
10 .sentinel = &@as(u8, 0),
11 }});
12}
13
14// error
15// backend=stage1
16// target=native
17// is_test=1
18//
19// tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers
test/cases/compile_errors/stage1/test/nested_vectors.zig created+13
......@@ -0,0 +1,13 @@
1export fn entry() void {
2 const V1 = @import("std").meta.Vector(4, u8);
3 const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
4 var v: V2 = undefined;
5 _ = v;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid
test/cases/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig created+20
......@@ -0,0 +1,20 @@
1const A = enum {
2 a,
3 b,
4 _ = 1,
5};
6const B = enum {
7 a,
8 b,
9 _,
10};
11comptime { _ = A; _ = B; }
12
13// error
14// backend=stage1
15// target=native
16// is_test=1
17//
18// tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value
19// tmp.zig:6:11: error: non-exhaustive enum missing integer tag type
20// tmp.zig:9:5: note: marked non-exhaustive here
test/cases/compile_errors/stage1/test/non-exhaustive_enums.zig created+22
......@@ -0,0 +1,22 @@
1const B = enum(u1) {
2 a,
3 _,
4 b,
5};
6const C = enum(u1) {
7 a,
8 b,
9 _,
10};
11pub export fn entry() void {
12 _ = B;
13 _ = C;
14}
15
16// error
17// backend=stage1
18// target=native
19// is_test=1
20//
21// tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last
22// tmp.zig:6:11: error: non-exhaustive enum specifies every value
test/cases/compile_errors/stage1/test/not_an_enum_type.zig created+20
......@@ -0,0 +1,20 @@
1export fn entry() void {
2 var self: Error = undefined;
3 switch (self) {
4 InvalidToken => |x| return x.token,
5 ExpectedVarDeclOrFn => |x| return x.token,
6 }
7}
8const Error = union(enum) {
9 A: InvalidToken,
10 B: ExpectedVarDeclOrFn,
11};
12const InvalidToken = struct {};
13const ExpectedVarDeclOrFn = struct {};
14
15// error
16// backend=stage1
17// target=native
18// is_test=1
19//
20// tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'
test/cases/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig created+74
......@@ -0,0 +1,74 @@
1const A = packed struct {
2 x: anyerror,
3};
4const B = packed struct {
5 x: [2]u24,
6};
7const C = packed struct {
8 x: [1]anyerror,
9};
10const D = packed struct {
11 x: [1]S,
12};
13const E = packed struct {
14 x: [1]U,
15};
16const F = packed struct {
17 x: ?anyerror,
18};
19const G = packed struct {
20 x: Enum,
21};
22export fn entry1() void {
23 var a: A = undefined;
24 _ = a;
25}
26export fn entry2() void {
27 var b: B = undefined;
28 _ = b;
29}
30export fn entry3() void {
31 var r: C = undefined;
32 _ = r;
33}
34export fn entry4() void {
35 var d: D = undefined;
36 _ = d;
37}
38export fn entry5() void {
39 var e: E = undefined;
40 _ = e;
41}
42export fn entry6() void {
43 var f: F = undefined;
44 _ = f;
45}
46export fn entry7() void {
47 var g: G = undefined;
48 _ = g;
49}
50const S = struct {
51 x: i32,
52};
53const U = struct {
54 A: i32,
55 B: u32,
56};
57const Enum = enum {
58 A,
59 B,
60};
61
62// error
63// backend=stage1
64// target=native
65// is_test=1
66//
67// tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
68// tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)
69// tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
70// tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation
71// tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation
72// tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation
73// tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation
74// tmp.zig:57:14: note: enum declaration does not specify an integer tag type
test/cases/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var pointer: ?*u0 = null;
3 var x = @ptrToInt(pointer);
4 _ = x;
5}
6
7// error
8// backend=stage1
9// target=native
10// is_test=1
11//
12// tmp.zig:3:23: error: pointer to size 0 type has no address
test/cases/compile_errors/stage1/test/reassign_to_array_parameter.zig created+13
......@@ -0,0 +1,13 @@
1fn reassign(a: [3]f32) void {
2 a = [3]f32{4, 5, 6};
3}
4export fn entry() void {
5 reassign(.{1, 2, 3});
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:2:15: error: cannot assign to constant
test/cases/compile_errors/stage1/test/reassign_to_slice_parameter.zig created+13
......@@ -0,0 +1,13 @@
1pub fn reassign(s: []const u8) void {
2 s = s[0..];
3}
4export fn entry() void {
5 reassign("foo");
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:2:10: error: cannot assign to constant
test/cases/compile_errors/stage1/test/reassign_to_struct_parameter.zig created+16
......@@ -0,0 +1,16 @@
1const S = struct {
2 x: u32,
3};
4fn reassign(s: S) void {
5 s = S{.x = 2};
6}
7export fn entry() void {
8 reassign(S{.x = 3});
9}
10
11// error
12// backend=stage1
13// target=native
14// is_test=1
15//
16// tmp.zig:5:10: error: cannot assign to constant
test/cases/compile_errors/stage1/test/reference_to_const_data.zig created+30
......@@ -0,0 +1,30 @@
1export fn foo() void {
2 var ptr = &[_]u8{0,0,0,0};
3 ptr[1] = 2;
4}
5export fn bar() void {
6 var ptr = &@as(u32, 2);
7 ptr.* = 2;
8}
9export fn baz() void {
10 var ptr = &true;
11 ptr.* = false;
12}
13export fn qux() void {
14 const S = struct{
15 x: usize,
16 y: usize,
17 };
18 var ptr = &S{.x=1,.y=2};
19 ptr.x = 2;
20}
21
22// error
23// backend=stage1
24// target=native
25// is_test=1
26//
27// tmp.zig:3:14: error: cannot assign to constant
28// tmp.zig:7:13: error: cannot assign to constant
29// tmp.zig:11:13: error: cannot assign to constant
30// tmp.zig:19:13: error: cannot assign to constant
test/cases/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig created+12
......@@ -0,0 +1,12 @@
1export fn entry() void {
2 var var_1: f32 = undefined;
3 var var_2: u32 = undefined;
4 _ = @TypeOf(var_1, var_2);
5}
6
7// error
8// backend=stage1
9// target=native
10// is_test=1
11//
12// tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'
test/cases/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig created+10
......@@ -0,0 +1,10 @@
1export fn entry() void {
2 _ = @TypeOf();
3}
4
5// error
6// backend=stage1
7// target=native
8// is_test=1
9//
10// tmp.zig:2:9: error: expected at least 1 argument, found 0
test/cases/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig created+10
......@@ -0,0 +1,10 @@
1extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5// error
6// backend=stage1
7// target=native
8// is_test=1
9//
10// tmp.zig:1:1: error: extern functions have no body
test/cases/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig created+8
......@@ -0,0 +1,8 @@
1extern var foo: int = 2;
2
3// error
4// backend=stage1
5// target=native
6// is_test=1
7//
8// tmp.zig:1:23: error: extern variables have no initializers
test/cases/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig created+14
......@@ -0,0 +1,14 @@
1pub fn A() type {
2 return Q;
3}
4test "1" {
5 _ = A().a;
6 _ = A().a;
7}
8
9// error
10// backend=stage1
11// target=native
12// is_test=1
13//
14// tmp.zig:2:12: error: use of undeclared identifier 'Q'
test/cases/compile_errors/stage1/test/return_invalid_type_from_test.zig created+8
......@@ -0,0 +1,8 @@
1test "example" { return 1; }
2
3// error
4// backend=stage1
5// target=native
6// is_test=1
7//
8// tmp.zig:1:25: error: expected type 'void', found 'comptime_int'
test/cases/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig created+34
......@@ -0,0 +1,34 @@
1export fn entry() void {
2 const S = struct {
3 fn a() void {
4 var x: u24 = 42;
5 _ = x >> 24;
6 }
7 fn b() void {
8 var x: u24 = 42;
9 _ = x << 24;
10 }
11 fn c() void {
12 var x: u24 = 42;
13 _ = @shlExact(x, 24);
14 }
15 fn d() void {
16 var x: u24 = 42;
17 _ = @shrExact(x, 24);
18 }
19 };
20 S.a();
21 S.b();
22 S.c();
23 S.d();
24}
25
26// error
27// backend=stage1
28// target=native
29// is_test=1
30//
31// tmp.zig:5:19: error: RHS of shift is too large for LHS type
32// tmp.zig:9:19: error: RHS of shift is too large for LHS type
33// tmp.zig:13:17: error: RHS of shift is too large for LHS type
34// tmp.zig:17:17: error: RHS of shift is too large for LHS type
test/cases/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig created+15
......@@ -0,0 +1,15 @@
1export fn entry() void {
2 const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
3 const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
4 var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
5 _ = z;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:4:39: error: mask index '4' has out-of-bounds selection
14// tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)
15// tmp.zig:4:30: note: selections from the second vector are specified with negative numbers
test/cases/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig created+16
......@@ -0,0 +1,16 @@
1pub export fn entry() void {
2 var x: i32 = 0;
3 switch (x) {
4 6...1 => {},
5 -1...-5 => {},
6 else => unreachable,
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:4:9: error: range start value is greater than the end value
16// tmp.zig:5:9: error: range start value is greater than the end value
test/cases/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig created+19
......@@ -0,0 +1,19 @@
1const E = enum{
2 a,
3 b,
4};
5pub export fn entry() void {
6 var e: E = .b;
7 switch (e) {
8 .a => {},
9 .b => {},
10 _ => {},
11 }
12}
13
14// error
15// backend=stage1
16// target=native
17// is_test=1
18//
19// tmp.zig:7:5: error: switch on exhaustive enum has `_` prong
test/cases/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig created+35
......@@ -0,0 +1,35 @@
1const E = enum(u8) {
2 a,
3 b,
4 _,
5};
6const U = union(E) {
7 a: i32,
8 b: u32,
9};
10pub export fn entry() void {
11 var e: E = .b;
12 switch (e) { // error: switch not handling the tag `b`
13 .a => {},
14 _ => {},
15 }
16 switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
17 .a => {},
18 .b => {},
19 }
20 var u = U{.a = 2};
21 switch (u) { // error: `_` prong not allowed when switching on tagged union
22 .a => {},
23 .b => {},
24 _ => {},
25 }
26}
27
28// error
29// backend=stage1
30// target=native
31// is_test=1
32//
33// tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch
34// tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong
35// tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union
test/cases/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig created+11
......@@ -0,0 +1,11 @@
1test "enum" {
2 const E = enum(u8) {A, B, _};
3 _ = @tagName(@intToEnum(E, 5));
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:18: error: no tag by value 5
test/cases/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig created+14
......@@ -0,0 +1,14 @@
1const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
2extern fn fn_decl(fmt: [*:0]u8, ...) void;
3
4export fn main() void {
5 const x: fn_ty = fn_decl;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12// is_test=1
13//
14// tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'
test/cases/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 var x = .{};
3 x = x ++ .{ 1, 2, 3 };
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'
test/cases/compile_errors/stage2/comptime_unreachable.zig created+7
......@@ -0,0 +1,7 @@
1pub export fn entry() void {
2 comptime unreachable;
3}
4
5// error
6//
7// :2:14: error: reached unreachable code
test/cases/compile_errors/stage2/constant_inside_comptime_function_has_compile_error.zig created+21
......@@ -0,0 +1,21 @@
1const ContextAllocator = MemoryPool(usize);
2
3pub fn MemoryPool(comptime T: type) type {
4 const free_list_t = @compileError("aoeu",);
5 _ = T;
6
7 return struct {
8 free_list: free_list_t,
9 };
10}
11
12export fn entry() void {
13 var allocator: ContextAllocator = undefined;
14 _ = allocator;
15}
16
17// error
18// target=native
19//
20// :4:5: error: unreachable code
21// :4:25: note: control flow is diverted here
test/cases/compile_errors/stage2/duplicate-unused_labels.zig created+31
......@@ -0,0 +1,31 @@
1comptime {
2 blk: { blk: while (false) {} }
3}
4comptime {
5 blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} }
6}
7comptime {
8 blk: for (@as([0]void, undefined)) |_| { blk: {} }
9}
10comptime {
11 blk: {}
12}
13comptime {
14 blk: while(false) {}
15}
16comptime {
17 blk: for(@as([0]void, undefined)) |_| {}
18}
19
20// error
21// target=native
22//
23// :2:12: error: redefinition of label 'blk'
24// :2:5: note: previous definition here
25// :5:26: error: redefinition of label 'blk'
26// :5:5: note: previous definition here
27// :8:46: error: redefinition of label 'blk'
28// :8:5: note: previous definition here
29// :11:5: error: unused block label
30// :14:5: error: unused while loop label
31// :17:5: error: unused for loop label
test/cases/compile_errors/stage2/embed_outside_package.zig created+8
......@@ -0,0 +1,8 @@
1export fn a() usize {
2 return @embedFile("/root/foo").len;
3}
4
5// error
6// target=native
7//
8//:2:23: error: embed of file outside package path: '/root/foo'
test/cases/compile_errors/stage2/import_outside_package.zig created+8
......@@ -0,0 +1,8 @@
1export fn a() usize {
2 return @import("../../above.zig").len;
3}
4
5// error
6// target=native
7//
8// :2:20: error: import of file outside package path: '../../above.zig'
test/cases/compile_errors/stage2/out_of_bounds_index.zig created+29
......@@ -0,0 +1,29 @@
1comptime {
2 var array = [_:0]u8{ 1, 2, 3, 4 };
3 var src_slice: [:0]u8 = &array;
4 var slice = src_slice[2..6];
5 _ = slice;
6}
7comptime {
8 var array = [_:0]u8{ 1, 2, 3, 4 };
9 var slice = array[2..6];
10 _ = slice;
11}
12comptime {
13 var array = [_]u8{ 1, 2, 3, 4 };
14 var slice = array[2..5];
15 _ = slice;
16}
17comptime {
18 var array = [_:0]u8{ 1, 2, 3, 4 };
19 var slice = array[3..2];
20 _ = slice;
21}
22
23// error
24// target=native
25//
26// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
27// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
28// :14:22: error: end index 5 out of bounds for array of length 4
29// :19:22: error: start index 3 is larger than end index 2
test/cases/compile_errors/stage2/slice_of_null_pointer.zig created+11
......@@ -0,0 +1,11 @@
1comptime {
2 var x: [*c]u8 = null;
3 var runtime_len: usize = 0;
4 var y = x[0..runtime_len];
5 _ = y;
6}
7
8// error
9// target=native
10//
11// :4:14: error: slice of null pointer
test/cases/compile_errors/stage2/struct_duplicate_field_name.zig created+16
......@@ -0,0 +1,16 @@
1const S = struct {
2 foo: u32,
3 foo: u32,
4};
5
6export fn entry() void {
7 const s: S = .{ .foo = 100 };
8 _ = s;
9}
10
11// error
12// target=native
13//
14// :3:5: error: duplicate struct field: 'foo'
15// :2:5: note: other field here
16// :1:11: note: struct declared here
test/cases/compile_errors/stage2/union_access_of_inactive_field.zig created+15
......@@ -0,0 +1,15 @@
1const U = union {
2 a: void,
3 b: u64,
4};
5comptime {
6 var u: U = .{ .a = {} };
7 const v = u.b;
8 _ = v;
9}
10
11// error
12// target=native
13//
14// :7:16: error: access of union field 'b' while field 'a' is active
15// :1:11: note: union declared here
test/cases/compile_errors/stage2/union_duplicate_enum_field.zig created+17
......@@ -0,0 +1,17 @@
1const E = enum { a, b };
2const U = union(E) {
3 a: u32,
4 a: u32,
5};
6
7export fn foo() void {
8 var u: U = .{ .a = 123 };
9 _ = u;
10}
11
12// error
13// target=native
14//
15// :4:5: error: duplicate union field: 'a'
16// :3:5: note: other field here
17// :2:11: note: union declared here
test/cases/compile_errors/stage2/union_duplicate_field_definition.zig created+16
......@@ -0,0 +1,16 @@
1const U = union {
2 foo: u32,
3 foo: u32,
4};
5
6export fn entry() void {
7 const u: U = .{ .foo = 100 };
8 _ = u;
9}
10
11// error
12// target=native
13//
14// :3:5: error: duplicate union field: 'foo'
15// :2:5: note: other field here
16// :1:11: note: union declared here
test/cases/compile_errors/stage2/union_enum_field_missing.zig created+21
......@@ -0,0 +1,21 @@
1const E = enum {
2 a,
3 b,
4 c,
5};
6
7const U = union(E) {
8 a: i32,
9 b: f64,
10};
11
12export fn entry() usize {
13 return @sizeOf(U);
14}
15
16// error
17// target=native
18//
19// :7:1: error: enum field(s) missing in union
20// :4:5: note: field 'c' missing, declared here
21// :1:11: note: enum declared here
test/cases/compile_errors/stage2/union_extra_field.zig created+20
......@@ -0,0 +1,20 @@
1const E = enum {
2 a,
3 b,
4 c,
5};
6const U = union(E) {
7 a: i32,
8 b: f64,
9 c: f64,
10 d: f64,
11};
12export fn entry() usize {
13 return @sizeOf(U);
14}
15
16// error
17// target=native
18//
19// :6:1: error: enum 'tmp.E' has no field named 'd'
20// :1:11: note: enum declared here
test/cases/compile_errors/stage2/union_runtime_coercion_from_enum.zig created+23
......@@ -0,0 +1,23 @@
1const E = enum {
2 a,
3 b,
4};
5const U = union(E) {
6 a: u32,
7 b: u64,
8};
9fn foo() E {
10 return E.b;
11}
12export fn doTheTest() u64 {
13 var u: U = foo();
14 return u.b;
15}
16
17// error
18// target=native
19//
20// :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields
21// :6:5: note: field 'a' has type 'u32'
22// :7:5: note: field 'b' has type 'u64'
23// :5:11: note: union declared here
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/enum_values.0.zig created+18
......@@ -0,0 +1,18 @@
1const Number = enum { One, Two, Three };
2
3pub fn main() void {
4 var number1 = Number.One;
5 var number2: Number = .Two;
6 if (false) {
7 number1;
8 number2;
9 }
10 const number3 = @intToEnum(Number, 2);
11 if (@enumToInt(number3) != 2) {
12 unreachable;
13 }
14 return;
15}
16
17// run
18//
test/cases/enum_values.1.zig created+22
......@@ -0,0 +1,22 @@
1const Number = enum { One, Two, Three };
2
3pub fn main() void {
4 var number1 = Number.One;
5 var number2: Number = .Two;
6 const number3 = @intToEnum(Number, 2);
7 assert(number1 != number2);
8 assert(number2 != number3);
9 assert(@enumToInt(number1) == 0);
10 assert(@enumToInt(number2) == 1);
11 assert(@enumToInt(number3) == 2);
12 var x: Number = .Two;
13 assert(number2 == x);
14
15 return;
16}
17fn assert(val: bool) void {
18 if (!val) unreachable;
19}
20
21// run
22//
test/cases/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/cases/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/cases/function_calls.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 foo();
3 bar();
4}
5fn foo() void {
6 bar();
7 bar();
8}
9fn bar() void {}
10
11// run
12//
test/cases/function_calls.1.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 bar();
3 foo();
4 foo();
5 bar();
6 foo();
7 bar();
8}
9fn foo() void {
10 bar();
11}
12fn bar() void {}
13
14// run
15//
test/cases/function_calls.2.zig created+14
......@@ -0,0 +1,14 @@
1pub fn main() void {
2 bar();
3 foo();
4 return;
5}
6fn foo() void {
7 bar();
8 bar();
9 bar();
10}
11fn bar() void {}
12
13// run
14//
test/cases/function_calls.3.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 foo(10, 20);
3}
4fn foo(x: u8, y: u8) void {
5 _ = x;
6 _ = y;
7}
8
9// run
10//
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/large_add_function.zig created+38
......@@ -0,0 +1,38 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l + d; // 227
18 const n = m + e; // 241
19 const o = n + f; // 265
20 const p = o + g; // 303
21 const q = p + h; // 365
22 const r = q + i; // 465
23 const s = r + j; // 575
24 const t = s + k; // 785
25 break :blk t;
26 };
27 const y = x + a; // 788
28 const z = y + a; // 791
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37// target=aarch64-linux,aarch64-macos
38//
test/cases/llvm/address_space_pointer_access_chaining_pointer_to_optional_array.zig created+12
......@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
2 return &a.*.?[0];
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/address_spaces_pointer_access_chaining_array_pointer.zig created+12
......@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
2 return &a[0];
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/address_spaces_pointer_access_chaining_complex.zig created+13
......@@ -0,0 +1,13 @@
1const A = struct { a: ?[1]i32 };
2fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
3 return &a[0].a.?[0];
4}
5pub fn main() void {
6 _ = entry;
7}
8
9// error
10// output_mode=Exe
11// backend=llvm
12// target=x86_64-linux,x86_64-macos
13//
test/cases/llvm/address_spaces_pointer_access_chaining_struct_pointer.zig created+13
......@@ -0,0 +1,13 @@
1const A = struct { a: i32 };
2fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
3 return &a.a;
4}
5pub fn main() void {
6 _ = entry;
7}
8
9// error
10// output_mode=Exe
11// backend=stage2,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/cases/llvm/any_typed_null_to_any_typed_optional.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 var a: ?*anyopaque = undefined;
3 a = @as(?usize, null);
4}
5
6// error
7// output_mode=Exe
8// backend=stage2,llvm
9// target=x86_64-linux,x86_64-macos
10//
11// :3:21: error: expected *anyopaque, found ?usize
test/cases/llvm/blocks.zig created+22
......@@ -0,0 +1,22 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 const val: i32 = blk: {
7 var x: i32 = 1;
8 if (!ok) break :blk x + 9;
9 break :blk x + 19;
10 };
11 return val + 10;
12}
13
14pub fn main() void {
15 assert(foo(false) == 20);
16 assert(foo(true) == 30);
17}
18
19// run
20// backend=stage2,llvm
21// target=x86_64-linux,x86_64-macos
22//
test/cases/llvm/dereferencing_though_multiple_pointers_with_address_spaces.zig created+12
......@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
2 return a.*.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/f_segment_address_space_reading_and_writing.zig created+48
......@@ -0,0 +1,48 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn setFs(value: c_ulong) void {
6 asm volatile (
7 \\syscall
8 :
9 : [number] "{rax}" (158),
10 [code] "{rdi}" (0x1002),
11 [val] "{rsi}" (value),
12 : "rcx", "r11", "memory"
13 );
14}
15
16fn getFs() c_ulong {
17 var result: c_ulong = undefined;
18 asm volatile (
19 \\syscall
20 :
21 : [number] "{rax}" (158),
22 [code] "{rdi}" (0x1003),
23 [ptr] "{rsi}" (@ptrToInt(&result)),
24 : "rcx", "r11", "memory"
25 );
26 return result;
27}
28
29var test_value: u64 = 12345;
30
31pub fn main() void {
32 const orig_fs = getFs();
33
34 setFs(@ptrToInt(&test_value));
35 assert(getFs() == @ptrToInt(&test_value));
36
37 var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
38 assert(test_ptr.* == 12345);
39 test_ptr.* = 98765;
40 assert(test_value == 98765);
41
42 setFs(orig_fs);
43}
44
45// run
46// backend=llvm
47// target=x86_64-linux
48//
test/cases/llvm/for_loop.zig created+16
......@@ -0,0 +1,16 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var x: u32 = 0;
7 for ("hello") |_| {
8 x += 1;
9 }
10 assert("hello".len == x);
11}
12
13// run
14// backend=stage2,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/cases/llvm/hello_world.zig created+12
......@@ -0,0 +1,12 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=llvm
9// target=x86_64-linux,x86_64-macos
10//
11// hello world!
12//
test/cases/llvm/invalid_address_space_coercion.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/cases/llvm/invalid_pointer_keeps_address_space_when_taking_address_of_dereference.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/cases/llvm/nested_blocks.zig created+24
......@@ -0,0 +1,24 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 var val: i32 = blk: {
7 const val2: i32 = another: {
8 if (!ok) break :blk 10;
9 break :another 10;
10 };
11 break :blk val2 + 10;
12 };
13 return val;
14}
15
16pub fn main() void {
17 assert(foo(false) == 10);
18 assert(foo(true) == 20);
19}
20
21// run
22// backend=stage2, llvm
23// target=x86_64-linux,x86_64-macos
24//
test/cases/llvm/optionals.zig created+45
......@@ -0,0 +1,45 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var opt_val: ?i32 = 10;
7 var null_val: ?i32 = null;
8
9 var val1: i32 = opt_val.?;
10 const val1_1: i32 = opt_val.?;
11 var ptr_val1 = &(opt_val.?);
12 const ptr_val1_1 = &(opt_val.?);
13
14 var val2: i32 = null_val orelse 20;
15 const val2_2: i32 = null_val orelse 20;
16
17 var value: i32 = 20;
18 var ptr_val2 = &(null_val orelse value);
19
20 const val3 = opt_val orelse 30;
21 var val3_var = opt_val orelse 30;
22
23 assert(val1 == 10);
24 assert(val1_1 == 10);
25 assert(ptr_val1.* == 10);
26 assert(ptr_val1_1.* == 10);
27
28 assert(val2 == 20);
29 assert(val2_2 == 20);
30 assert(ptr_val2.* == 20);
31
32 assert(val3 == 10);
33 assert(val3_var == 10);
34
35 (null_val orelse val2) = 1234;
36 assert(val2 == 1234);
37
38 (opt_val orelse val2) = 5678;
39 assert(opt_val.? == 5678);
40}
41
42// run
43// backend=llvm
44// target=x86_64-linux,x86_64-macos
45//
test/cases/llvm/pointer_keeps_address_space.zig created+12
......@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/pointer_keeps_address_space_when_taking_address_of_dereference.zig created+12
......@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/pointer_to_explicit_generic_address_space_coerces_to_implicit_pointer.zig created+12
......@@ -0,0 +1,12 @@
1fn entry(a: *addrspace(.generic) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/pointer_with_different_address_spaces.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.fs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32
test/cases/llvm/pointers_with_different_address_spaces.zig created+13
......@@ -0,0 +1,13 @@
1fn entry(a: ?*addrspace(.gs) i32) *i32 {
2 return a.?;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:13: error: expected *i32, found *addrspace(.gs) i32
test/cases/llvm/rem.zig created+15
......@@ -0,0 +1,15 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4fn rem(lhs: i32, rhs: i32, expected: i32) bool {
5 return @rem(lhs, rhs) == expected;
6}
7pub fn main() void {
8 assert(rem(-5, 3, -2));
9 assert(rem(5, 3, 2));
10}
11
12// run
13// backend=stage2,llvm
14// target=x86_64-linux,x86_64-macos
15//
test/cases/llvm/shift_right_plus_left.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i >> 1, 8);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10// backend=llvm
11// target=x86_64-linux,x86_64-macos
12//
test/cases/llvm/shift_right_plus_left.1.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i << 1, 32);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10//
test/cases/llvm/simple_addition_and_subtraction.zig created+20
......@@ -0,0 +1,20 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5pub fn main() void {
6 var a: i32 = -5;
7 const x = add(a, 7);
8 var y = add(2, 0);
9 y -= x;
10 assert(y == 0);
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18// backend=stage2,llvm
19// target=x86_64-linux,x86_64-macos
20//
test/cases/llvm/simple_if_statement.zig created+16
......@@ -0,0 +1,16 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9pub fn main() void {
10 assert(add(1, 2) == 3);
11}
12
13// run
14// backend=stage2,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/cases/llvm/while_loops.zig created+18
......@@ -0,0 +1,18 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var sum: u32 = 0;
7 var i: u32 = 0;
8 while (i < 5) : (i += 1) {
9 sum += i;
10 }
11 assert(sum == 10);
12 assert(i == 5);
13}
14
15// run
16// backend=stage2,llvm
17// target=x86_64-linux,x86_64-macos
18//
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/multiplying_numbers_at_runtime_and_comptime.0.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 mul(3, 4);
3}
4
5fn mul(a: u32, b: u32) void {
6 if (a * b != 12) unreachable;
7}
8
9// run
10// target=x86_64-linux,x86_64-macos
11//
test/cases/multiplying_numbers_at_runtime_and_comptime.1.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 if (x - 12 != 0) unreachable;
3}
4
5fn mul(a: u32, b: u32) u32 {
6 return a * b;
7}
8
9const x = mul(3, 4);
10
11// run
12//
test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 var x: usize = 5;
3 const y = mul(2, 3, x);
4 if (y - 30 != 0) unreachable;
5}
6
7inline fn mul(a: usize, b: usize, c: usize) usize {
8 return a * b * c;
9}
10
11// run
12//
test/cases/non_leaf_functions.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() void {
2 foo();
3}
4
5fn foo() void {
6 bar();
7}
8
9fn bar() void {}
10
11// run
12//
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/plan9/exit.zig created+5
......@@ -0,0 +1,5 @@
1pub fn main() void {}
2
3// run
4// target=x86_64-plan9,aarch64-plan9
5//
test/cases/plan9/hello_world_with_updates.0.zig created+28
......@@ -0,0 +1,28 @@
1pub fn main() void {
2 const str = "Hello World!\n";
3 asm volatile (
4 \\push $0
5 \\push %%r10
6 \\push %%r11
7 \\push $1
8 \\push $0
9 \\syscall
10 \\pop %%r11
11 \\pop %%r11
12 \\pop %%r11
13 \\pop %%r11
14 \\pop %%r11
15 :
16 // pwrite
17 : [syscall_number] "{rbp}" (51),
18 [hey] "{r11}" (@ptrToInt(str)),
19 [strlen] "{r10}" (str.len),
20 : "rcx", "rbp", "r11", "memory"
21 );
22}
23
24// run
25// target=x86_64-plan9
26//
27// Hello World
28//
test/cases/plan9/hello_world_with_updates.1.zig created+10
......@@ -0,0 +1,10 @@
1const std = @import("std");
2pub fn main() void {
3 const str = "Hello World!\n";
4 _ = std.os.plan9.pwrite(1, str, str.len, 0);
5}
6
7// run
8//
9// Hello World
10//
test/cases/recursive_fibonacci.zig created+24
......@@ -0,0 +1,24 @@
1pub fn main() void {
2 assert(fib(0) == 0);
3 assert(fib(1) == 1);
4 assert(fib(2) == 1);
5 assert(fib(3) == 2);
6 assert(fib(10) == 55);
7 assert(fib(20) == 6765);
8}
9
10fn fib(n: u32) u32 {
11 if (n < 2) {
12 return n;
13 } else {
14 return fib(n - 2) + fib(n - 1);
15 }
16}
17
18fn assert(ok: bool) void {
19 if (!ok) unreachable;
20}
21
22// run
23// target=arm-linux,x86_64-linux,x86_64-macos,wasm32-wasi
24//
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/riscv64-linux/hello_world_with_updates.0.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("ecall"
7 :
8 : [number] "{a7}" (64),
9 [arg1] "{a0}" (1),
10 [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
11 [arg3] "{a2}" ("Hello, World!\n".len),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18// target=riscv64-linux
19//
20// Hello, World!
21//
test/cases/riscv64-linux/hello_world_with_updates.1.zig created+27
......@@ -0,0 +1,27 @@
1pub fn main() void {
2 print();
3 print();
4 print();
5 print();
6}
7
8fn print() void {
9 asm volatile ("ecall"
10 :
11 : [number] "{a7}" (64),
12 [arg1] "{a0}" (1),
13 [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
14 [arg3] "{a2}" ("Hello, World!\n".len),
15 : "rcx", "r11", "memory"
16 );
17 return;
18}
19
20// run
21// target=riscv64-linux
22//
23// Hello, World!
24// Hello, World!
25// Hello, World!
26// Hello, World!
27//
test/cases/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/cases/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/cases/save_function_return_values_in_callee_preserved_register.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 assert(foo() == 43);
3}
4
5fn foo() u32 {
6 return bar() + baz(42);
7}
8
9fn bar() u32 {
10 return 1;
11}
12
13fn baz(x: u32) u32 {
14 return x;
15}
16
17fn assert(ok: bool) void {
18 if (!ok) unreachable;
19}
20
21// run
22//
test/cases/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/cases/sparcv9-linux/hello_world.zig created+27
......@@ -0,0 +1,27 @@
1const msg = "Hello, World!\n";
2
3pub export fn _start() noreturn {
4 asm volatile ("ta 0x6d"
5 :
6 : [number] "{g1}" (4),
7 [arg1] "{o0}" (1),
8 [arg2] "{o1}" (@ptrToInt(msg)),
9 [arg3] "{o2}" (msg.len),
10 : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
11 );
12
13 asm volatile ("ta 0x6d"
14 :
15 : [number] "{g1}" (1),
16 [arg1] "{o0}" (0),
17 : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
18 );
19
20 unreachable;
21}
22
23// run
24// target=sparcv9-linux
25//
26// Hello, World!
27//
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/unused_vars.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() void {
2 const x = 1;
3}
4
5// error
6//
7// :2:11: error: unused local constant
test/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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/cases/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
test/cases/wasm-wasi/conditions.0.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i > @as(u8, 4)) {
4 i += 10;
5 }
6 return i - 15;
7}
8
9// run
10// target=wasm32-wasi
11//
test/cases/wasm-wasi/conditions.1.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else {
6 i = 2;
7 }
8 return i - 2;
9}
10
11// run
12//
test/cases/wasm-wasi/conditions.2.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else if (i == @as(u8, 5)) {
6 i = 20;
7 }
8 return i - 20;
9}
10
11// run
12//
test/cases/wasm-wasi/conditions.3.zig created+16
......@@ -0,0 +1,16 @@
1pub fn main() u8 {
2 var i: u8 = 11;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else {
6 if (i > @as(u8, 10)) {
7 i += 20;
8 } else {
9 i = 20;
10 }
11 }
12 return i - 31;
13}
14
15// run
16//
test/cases/wasm-wasi/conditions.4.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 assert(foo(true) != @as(i32, 30));
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9fn foo(ok: bool) i32 {
10 const x = if (ok) @as(i32, 20) else @as(i32, 10);
11 return x;
12}
13
14// run
15//
test/cases/wasm-wasi/conditions.5.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 assert(foo(false) == @as(i32, 20));
3 assert(foo(true) == @as(i32, 30));
4}
5
6fn assert(ok: bool) void {
7 if (!ok) unreachable;
8}
9
10fn foo(ok: bool) i32 {
11 const val: i32 = blk: {
12 var x: i32 = 1;
13 if (!ok) break :blk x + @as(i32, 9);
14 break :blk x + @as(i32, 19);
15 };
16 return val + 10;
17}
18
19// run
20//
test/cases/wasm-wasi/error_unions.0.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 var e1 = error.Foo;
3 var e2 = error.Bar;
4 assert(e1 != e2);
5 assert(e1 == error.Foo);
6 assert(e2 == error.Bar);
7}
8
9fn assert(b: bool) void {
10 if (!b) unreachable;
11}
12
13// run
14// target=wasm32-wasi
15//
test/cases/wasm-wasi/error_unions.1.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var e: anyerror!u8 = 5;
3 const i = e catch 10;
4 return i - 5;
5}
6
7// run
8//
test/cases/wasm-wasi/error_unions.2.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var e: anyerror!u8 = error.Foo;
3 const i = e catch 10;
4 return i - 10;
5}
6
7// run
8//
test/cases/wasm-wasi/error_unions.3.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 69;
4 return i - 5;
5}
6
7fn foo() anyerror!u8 {
8 return 5;
9}
10
11// run
12//
test/cases/wasm-wasi/error_unions.4.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 69;
4 return i - 69;
5}
6
7fn foo() anyerror!u8 {
8 return error.Bruh;
9}
10
11// run
12//
test/cases/wasm-wasi/error_unions.5.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 42;
4 return i - 42;
5}
6
7fn foo() anyerror!u8 {
8 return error.Dab;
9}
10
11// run
12//
test/cases/wasm-wasi/locals.0.zig created+14
......@@ -0,0 +1,14 @@
1pub fn main() void {
2 var i: u8 = 5;
3 var y: f32 = 42.0;
4 var x: u8 = 10;
5 if (false) {
6 y;
7 x;
8 }
9 if (i != 5) unreachable;
10}
11
12// run
13// target=wasm32-wasi
14//
test/cases/wasm-wasi/locals.1.zig created+17
......@@ -0,0 +1,17 @@
1pub fn main() void {
2 var i: u8 = 5;
3 var y: f32 = 42.0;
4 _ = y;
5 var x: u8 = 10;
6 foo(i, x);
7 i = x;
8 if (i != 10) unreachable;
9}
10fn foo(x: u8, y: u8) void {
11 _ = y;
12 var i: u8 = 10;
13 i = x;
14}
15
16// run
17//
test/cases/wasm-wasi/optionals.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var x: ?u8 = 5;
3 var y: u8 = 0;
4 if (x) |val| {
5 y = val;
6 }
7 return y - 5;
8}
9
10// run
11// target=wasm32-wasi
12//
test/cases/wasm-wasi/optionals.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() u8 {
2 var x: ?u8 = null;
3 var y: u8 = 0;
4 if (x) |val| {
5 y = val;
6 }
7 return y;
8}
9
10// run
11//
test/cases/wasm-wasi/optionals.2.zig created+7
......@@ -0,0 +1,7 @@
1pub fn main() u8 {
2 var x: ?u8 = 5;
3 return x.? - 5;
4}
5
6// run
7//
test/cases/wasm-wasi/optionals.3.zig created+8
......@@ -0,0 +1,8 @@
1pub fn main() u8 {
2 var x: u8 = 5;
3 var y: ?u8 = x;
4 return y.? - 5;
5}
6
7// run
8//
test/cases/wasm-wasi/optionals.4.zig created+13
......@@ -0,0 +1,13 @@
1pub fn main() u8 {
2 var val: ?u8 = 5;
3 while (val) |*v| {
4 v.* -= 1;
5 if (v.* == 2) {
6 val = null;
7 }
8 }
9 return 0;
10}
11
12// run
13//
test/cases/wasm-wasi/pointers.0.zig created+14
......@@ -0,0 +1,14 @@
1pub fn main() u8 {
2 var x: u8 = 0;
3
4 foo(&x);
5 return x - 2;
6}
7
8fn foo(x: *u8) void {
9 x.* = 2;
10}
11
12// run
13// target=wasm32-wasi
14//
test/cases/wasm-wasi/pointers.1.zig created+18
......@@ -0,0 +1,18 @@
1pub fn main() u8 {
2 var x: u8 = 0;
3
4 foo(&x);
5 bar(&x);
6 return x - 4;
7}
8
9fn foo(x: *u8) void {
10 x.* = 2;
11}
12
13fn bar(x: *u8) void {
14 x.* += 2;
15}
16
17// run
18//
test/cases/wasm-wasi/structs.0.zig created+10
......@@ -0,0 +1,10 @@
1const Example = struct { x: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };
5 return example.x - 5;
6}
7
8// run
9// target=wasm32-wasi
10//
test/cases/wasm-wasi/structs.1.zig created+10
......@@ -0,0 +1,10 @@
1const Example = struct { x: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };
5 example.x = 10;
6 return example.x - 10;
7}
8
9// run
10//
test/cases/wasm-wasi/structs.2.zig created+9
......@@ -0,0 +1,9 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5 return example.y + example.x - 15;
6}
7
8// run
9//
test/cases/wasm-wasi/structs.3.zig created+12
......@@ -0,0 +1,12 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5 var example2: Example = .{ .x = 10, .y = 20 };
6
7 example = example2;
8 return example.y + example.x - 30;
9}
10
11// run
12//
test/cases/wasm-wasi/structs.4.zig created+11
......@@ -0,0 +1,11 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5
6 example = .{ .x = 10, .y = 20 };
7 return example.y + example.x - 30;
8}
9
10// run
11//
test/cases/wasm-wasi/switch.0.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() u8 {
2 var val: u8 = 1;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 2;
11}
12
13// run
14// target=wasm32-wasi
15//
test/cases/wasm-wasi/switch.1.zig created+14
......@@ -0,0 +1,14 @@
1pub fn main() u8 {
2 var val: u8 = 2;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 3;
11}
12
13// run
14//
test/cases/wasm-wasi/switch.2.zig created+14
......@@ -0,0 +1,14 @@
1pub fn main() u8 {
2 var val: u8 = 10;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 5;
11}
12
13// run
14//
test/cases/wasm-wasi/switch.3.zig created+15
......@@ -0,0 +1,15 @@
1const MyEnum = enum { One, Two, Three };
2
3pub fn main() u8 {
4 var val: MyEnum = .Two;
5 var a: u8 = switch (val) {
6 .One => 1,
7 .Two => 2,
8 .Three => 3,
9 };
10
11 return a - 2;
12}
13
14// run
15//
test/cases/wasm-wasi/while_loops.0.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 5)) {
4 i += 1;
5 }
6
7 return i - 5;
8}
9
10// run
11// target=wasm32-wasi
12//
test/cases/wasm-wasi/while_loops.1.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;
5 i += x;
6 }
7 return i - 10;
8}
9
10// run
11//
test/cases/wasm-wasi/while_loops.2.zig created+12
......@@ -0,0 +1,12 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;
5 i += x;
6 if (i == @as(u8, 5)) break;
7 }
8 return i - 5;
9}
10
11// run
12//
test/cases/x86_64-linux/assert_function.0.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 assert(a + b == 7);
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14// target=x86_64-linux
15//
test/cases/x86_64-linux/assert_function.1.zig created+17
......@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 assert(e == 14);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/cases/x86_64-linux/assert_function.10.zig created+27
......@@ -0,0 +1,27 @@
1pub fn main() void {
2 assert(add(3, 4) == 116);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 break :blk j;
16 };
17 const y = x + a; // 113
18 const z = y + a; // 116
19 return z;
20}
21
22pub fn assert(ok: bool) void {
23 if (!ok) unreachable; // assertion failure
24}
25
26// run
27//
test/cases/x86_64-linux/assert_function.11.zig created+66
......@@ -0,0 +1,66 @@
1pub fn main() void {
2 assert(add(3, 4) == 1221);
3 assert(mul(3, 4) == 21609);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = j + k; // 320
18 const m = l + c; // 327
19 const n = m + d; // 337
20 const o = n + e; // 351
21 const p = o + f; // 375
22 const q = p + g; // 413
23 const r = q + h; // 475
24 const s = r + i; // 575
25 const t = s + j; // 685
26 const u = t + k; // 895
27 const v = u + l; // 1215
28 break :blk v;
29 };
30 const y = x + a; // 1218
31 const z = y + a; // 1221
32 return z;
33}
34
35fn mul(a: u32, b: u32) u32 {
36 const x: u32 = blk: {
37 const c = a * a * a * a; // 81
38 const d = a * a * a * b; // 108
39 const e = a * a * b * a; // 108
40 const f = a * a * b * b; // 144
41 const g = a * b * a * a; // 108
42 const h = a * b * a * b; // 144
43 const i = a * b * b * a; // 144
44 const j = a * b * b * b; // 192
45 const k = b * a * a * a; // 108
46 const l = b * a * a * b; // 144
47 const m = b * a * b * a; // 144
48 const n = b * a * b * b; // 192
49 const o = b * b * a * a; // 144
50 const p = b * b * a * b; // 192
51 const q = b * b * b * a; // 192
52 const r = b * b * b * b; // 256
53 const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
54 break :blk s;
55 };
56 const y = x * a; // 7203
57 const z = y * a; // 21609
58 return z;
59}
60
61pub fn assert(ok: bool) void {
62 if (!ok) unreachable; // assertion failure
63}
64
65// run
66//
test/cases/x86_64-linux/assert_function.12.zig created+47
......@@ -0,0 +1,47 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3 assert(add(4, 3) == 79);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = if (a < b) blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = k + c; // 217
18 const m = l + d; // 227
19 const n = m + e; // 241
20 const o = n + f; // 265
21 const p = o + g; // 303
22 const q = p + h; // 365
23 const r = q + i; // 465
24 const s = r + j; // 575
25 const t = s + k; // 785
26 break :blk t;
27 } else blk: {
28 const t = b + b + a; // 10
29 const c = a + t; // 14
30 const d = c + t; // 24
31 const e = d + t; // 34
32 const f = e + t; // 44
33 const g = f + t; // 54
34 const h = c + g; // 68
35 break :blk h + b; // 71
36 };
37 const y = x + a; // 788, 75
38 const z = y + a; // 791, 79
39 return z;
40}
41
42pub fn assert(ok: bool) void {
43 if (!ok) unreachable; // assertion failure
44}
45
46// run
47//
test/cases/x86_64-linux/assert_function.13.zig created+19
......@@ -0,0 +1,19 @@
1pub fn main() void {
2 const ignore =
3 \\ cool thx
4 \\
5 ;
6 _ = ignore;
7 add('ぁ', '\x03');
8}
9
10fn add(a: u32, b: u32) void {
11 assert(a + b == 12356);
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/cases/x86_64-linux/assert_function.14.zig created+17
......@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(aa, bb);
3}
4
5const aa = 'ぁ';
6const bb = '\x03';
7
8fn add(a: u32, b: u32) void {
9 assert(a + b == 12356);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/cases/x86_64-linux/assert_function.15.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 assert("hello"[0] == 'h');
3}
4
5pub fn assert(ok: bool) void {
6 if (!ok) unreachable; // assertion failure
7}
8
9// run
10//
test/cases/x86_64-linux/assert_function.16.zig created+11
......@@ -0,0 +1,11 @@
1const hello = "hello".*;
2pub fn main() void {
3 assert(hello[1] == 'e');
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/cases/x86_64-linux/assert_function.17.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 assert(i == 0xFFEEDDCCBBAA9988);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/cases/x86_64-linux/assert_function.18.zig created+35
......@@ -0,0 +1,35 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 for ("hello") |_| print();
7}
8
9fn print() void {
10 switch (builtin.os.tag) {
11 .linux => {
12 asm volatile ("syscall"
13 :
14 : [number] "{rax}" (1),
15 [arg1] "{rdi}" (1),
16 [arg2] "{rsi}" (@ptrToInt("hello\n")),
17 [arg3] "{rdx}" (6),
18 : "rcx", "r11", "memory"
19 );
20 },
21 .macos => {
22 _ = write(1, @ptrToInt("hello\n"), 6);
23 },
24 else => unreachable,
25 }
26}
27
28// run
29//
30// hello
31// hello
32// hello
33// hello
34// hello
35//
test/cases/x86_64-linux/assert_function.2.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 assert(i == 100);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/cases/x86_64-linux/assert_function.3.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 const j = i + d; // 110
14 assert(j == 110);
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/cases/x86_64-linux/assert_function.4.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 return a + b;
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/cases/x86_64-linux/assert_function.5.zig created+19
......@@ -0,0 +1,19 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 var x: u32 = undefined;
8 x = 0;
9 x += a;
10 x += b;
11 return x;
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/cases/x86_64-linux/assert_function.6.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 const a: u32 = 2;
3 const b: ?u32 = a;
4 const c = b.?;
5 if (c != 2) unreachable;
6}
7
8// run
9//
test/cases/x86_64-linux/assert_function.7.zig created+28
......@@ -0,0 +1,28 @@
1pub fn main() void {
2 var i: u32 = 0;
3 while (i < 4) : (i += 1) print();
4 assert(i == 4);
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("hello\n")),
13 [arg3] "{rdx}" (6),
14 : "rcx", "r11", "memory"
15 );
16}
17
18pub fn assert(ok: bool) void {
19 if (!ok) unreachable; // assertion failure
20}
21
22// run
23//
24// hello
25// hello
26// hello
27// hello
28//
test/cases/x86_64-linux/assert_function.8.zig created+24
......@@ -0,0 +1,24 @@
1pub fn main() void {
2 var i: u32 = 0;
3 inline while (i < 4) : (i += 1) print();
4 assert(i == 4);
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("hello\n")),
13 [arg3] "{rdx}" (6),
14 : "rcx", "r11", "memory"
15 );
16}
17
18pub fn assert(ok: bool) void {
19 if (!ok) unreachable; // assertion failure
20}
21
22// error
23//
24// :3:21: error: unable to resolve comptime value
test/cases/x86_64-linux/assert_function.9.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 assert(add(3, 4) == 20);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 break :blk e;
11 };
12 const y = x + a; // 17
13 const z = y + a; // 20
14 return z;
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/cases/x86_64-linux/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
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/cases/x86_64-linux/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/cases/x86_64-linux/comptime_var.2.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 comptime var len: u32 = 5;
3 print(len);
4 len += 9;
5 print(len);
6}
7
8fn print(len: usize) void {
9 asm volatile ("syscall"
10 :
11 : [number] "{rax}" (1),
12 [arg1] "{rdi}" (1),
13 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
14 [arg3] "{rdx}" (len),
15 : "rcx", "r11", "memory"
16 );
17}
18
19// run
20//
21// HelloHello, World!
22//
test/cases/x86_64-linux/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: reached unreachable code
test/cases/x86_64-linux/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/cases/x86_64-linux/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/cases/x86_64-linux/comptime_var.6.zig created+20
......@@ -0,0 +1,20 @@
1pub fn main() void {
2 comptime var i: u64 = 2;
3 inline while (i < 6) : (i += 1) {
4 print(i);
5 }
6}
7fn print(len: usize) void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("Hello")),
13 [arg3] "{rdx}" (len),
14 : "rcx", "r11", "memory"
15 );
16}
17
18// run
19//
20// HeHelHellHello
test/cases/x86_64-linux/hello_world_with_updates.0.zig created+5
......@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=x86_64-linux
4//
5// :107:9: error: struct 'tmp.tmp' has no member named 'main'
test/cases/x86_64-linux/hello_world_with_updates.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/cases/x86_64-linux/hello_world_with_updates.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/cases/x86_64-linux/hello_world_with_updates.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/cases/x86_64-linux/hello_world_with_updates.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/cases/x86_64-linux/hello_world_with_updates.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/cases/x86_64-linux/inline_assembly.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/cases/x86_64-linux/inline_assembly.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/cases/x86_64-linux/inline_assembly.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/cases/x86_64-linux/inline_assembly.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/cases/x86_64-linux/only_1_function_and_it_gets_updated.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/cases/x86_64-linux/only_1_function_and_it_gets_updated.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/cases/x86_64-macos/assert_function.0.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 assert(a + b == 7);
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14// target=x86_64-macos
15//
test/cases/x86_64-macos/assert_function.1.zig created+17
......@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 assert(e == 14);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/cases/x86_64-macos/assert_function.10.zig created+27
......@@ -0,0 +1,27 @@
1pub fn main() void {
2 assert(add(3, 4) == 116);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 break :blk j;
16 };
17 const y = x + a; // 113
18 const z = y + a; // 116
19 return z;
20}
21
22pub fn assert(ok: bool) void {
23 if (!ok) unreachable; // assertion failure
24}
25
26// run
27//
test/cases/x86_64-macos/assert_function.11.zig created+66
......@@ -0,0 +1,66 @@
1pub fn main() void {
2 assert(add(3, 4) == 1221);
3 assert(mul(3, 4) == 21609);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = j + k; // 320
18 const m = l + c; // 327
19 const n = m + d; // 337
20 const o = n + e; // 351
21 const p = o + f; // 375
22 const q = p + g; // 413
23 const r = q + h; // 475
24 const s = r + i; // 575
25 const t = s + j; // 685
26 const u = t + k; // 895
27 const v = u + l; // 1215
28 break :blk v;
29 };
30 const y = x + a; // 1218
31 const z = y + a; // 1221
32 return z;
33}
34
35fn mul(a: u32, b: u32) u32 {
36 const x: u32 = blk: {
37 const c = a * a * a * a; // 81
38 const d = a * a * a * b; // 108
39 const e = a * a * b * a; // 108
40 const f = a * a * b * b; // 144
41 const g = a * b * a * a; // 108
42 const h = a * b * a * b; // 144
43 const i = a * b * b * a; // 144
44 const j = a * b * b * b; // 192
45 const k = b * a * a * a; // 108
46 const l = b * a * a * b; // 144
47 const m = b * a * b * a; // 144
48 const n = b * a * b * b; // 192
49 const o = b * b * a * a; // 144
50 const p = b * b * a * b; // 192
51 const q = b * b * b * a; // 192
52 const r = b * b * b * b; // 256
53 const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
54 break :blk s;
55 };
56 const y = x * a; // 7203
57 const z = y * a; // 21609
58 return z;
59}
60
61pub fn assert(ok: bool) void {
62 if (!ok) unreachable; // assertion failure
63}
64
65// run
66//
test/cases/x86_64-macos/assert_function.12.zig created+47
......@@ -0,0 +1,47 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3 assert(add(4, 3) == 79);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = if (a < b) blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = k + c; // 217
18 const m = l + d; // 227
19 const n = m + e; // 241
20 const o = n + f; // 265
21 const p = o + g; // 303
22 const q = p + h; // 365
23 const r = q + i; // 465
24 const s = r + j; // 575
25 const t = s + k; // 785
26 break :blk t;
27 } else blk: {
28 const t = b + b + a; // 10
29 const c = a + t; // 14
30 const d = c + t; // 24
31 const e = d + t; // 34
32 const f = e + t; // 44
33 const g = f + t; // 54
34 const h = c + g; // 68
35 break :blk h + b; // 71
36 };
37 const y = x + a; // 788, 75
38 const z = y + a; // 791, 79
39 return z;
40}
41
42pub fn assert(ok: bool) void {
43 if (!ok) unreachable; // assertion failure
44}
45
46// run
47//
test/cases/x86_64-macos/assert_function.13.zig created+19
......@@ -0,0 +1,19 @@
1pub fn main() void {
2 const ignore =
3 \\ cool thx
4 \\
5 ;
6 _ = ignore;
7 add('ぁ', '\x03');
8}
9
10fn add(a: u32, b: u32) void {
11 assert(a + b == 12356);
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/cases/x86_64-macos/assert_function.14.zig created+17
......@@ -0,0 +1,17 @@
1pub fn main() void {
2 add(aa, bb);
3}
4
5const aa = 'ぁ';
6const bb = '\x03';
7
8fn add(a: u32, b: u32) void {
9 assert(a + b == 12356);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/cases/x86_64-macos/assert_function.15.zig created+10
......@@ -0,0 +1,10 @@
1pub fn main() void {
2 assert("hello"[0] == 'h');
3}
4
5pub fn assert(ok: bool) void {
6 if (!ok) unreachable; // assertion failure
7}
8
9// run
10//
test/cases/x86_64-macos/assert_function.16.zig created+11
......@@ -0,0 +1,11 @@
1const hello = "hello".*;
2pub fn main() void {
3 assert(hello[1] == 'e');
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/cases/x86_64-macos/assert_function.17.zig created+11
......@@ -0,0 +1,11 @@
1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 assert(i == 0xFFEEDDCCBBAA9988);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/cases/x86_64-macos/assert_function.18.zig created+35
......@@ -0,0 +1,35 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 for ("hello") |_| print();
7}
8
9fn print() void {
10 switch (builtin.os.tag) {
11 .linux => {
12 asm volatile ("syscall"
13 :
14 : [number] "{rax}" (1),
15 [arg1] "{rdi}" (1),
16 [arg2] "{rsi}" (@ptrToInt("hello\n")),
17 [arg3] "{rdx}" (6),
18 : "rcx", "r11", "memory"
19 );
20 },
21 .macos => {
22 _ = write(1, @ptrToInt("hello\n"), 6);
23 },
24 else => unreachable,
25 }
26}
27
28// run
29//
30// hello
31// hello
32// hello
33// hello
34// hello
35//
test/cases/x86_64-macos/assert_function.2.zig created+21
......@@ -0,0 +1,21 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 assert(i == 100);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/cases/x86_64-macos/assert_function.3.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 const j = i + d; // 110
14 assert(j == 110);
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/cases/x86_64-macos/assert_function.4.zig created+15
......@@ -0,0 +1,15 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 return a + b;
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/cases/x86_64-macos/assert_function.5.zig created+19
......@@ -0,0 +1,19 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 var x: u32 = undefined;
8 x = 0;
9 x += a;
10 x += b;
11 return x;
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/cases/x86_64-macos/assert_function.6.zig created+9
......@@ -0,0 +1,9 @@
1pub fn main() void {
2 const a: u32 = 2;
3 const b: ?u32 = a;
4 const c = b.?;
5 if (c != 2) unreachable;
6}
7
8// run
9//
test/cases/x86_64-macos/assert_function.7.zig created+23
......@@ -0,0 +1,23 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 var i: u32 = 0;
5 while (i < 4) : (i += 1) print();
6 assert(i == 4);
7}
8
9fn print() void {
10 _ = write(1, @ptrToInt("hello\n"), 6);
11}
12
13pub fn assert(ok: bool) void {
14 if (!ok) unreachable; // assertion failure
15}
16
17// run
18//
19// hello
20// hello
21// hello
22// hello
23//
test/cases/x86_64-macos/assert_function.8.zig created+19
......@@ -0,0 +1,19 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 var i: u32 = 0;
5 inline while (i < 4) : (i += 1) print();
6 assert(i == 4);
7}
8
9fn print() void {
10 _ = write(1, @ptrToInt("hello\n"), 6);
11}
12
13pub fn assert(ok: bool) void {
14 if (!ok) unreachable; // assertion failure
15}
16
17// error
18//
19// :5:21: error: unable to resolve comptime value
test/cases/x86_64-macos/assert_function.9.zig created+22
......@@ -0,0 +1,22 @@
1pub fn main() void {
2 assert(add(3, 4) == 20);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 break :blk e;
11 };
12 const y = x + a; // 17
13 const z = y + a; // 20
14 return z;
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/cases/x86_64-macos/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-macos
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/cases/x86_64-macos/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/cases/x86_64-macos/comptime_var.2.zig created+17
......@@ -0,0 +1,17 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 comptime var len: u32 = 5;
5 print(len);
6 len += 9;
7 print(len);
8}
9
10fn print(len: usize) void {
11 _ = write(1, @ptrToInt("Hello, World!\n"), len);
12}
13
14// run
15//
16// HelloHello, World!
17//
test/cases/x86_64-macos/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: reached unreachable code
test/cases/x86_64-macos/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/cases/x86_64-macos/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/cases/x86_64-macos/comptime_var.6.zig created+15
......@@ -0,0 +1,15 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 comptime var i: u64 = 2;
5 inline while (i < 6) : (i += 1) {
6 print(i);
7 }
8}
9fn print(len: usize) void {
10 _ = write(1, @ptrToInt("Hello"), len);
11}
12
13// run
14//
15// HeHelHellHello
test/cases/x86_64-macos/hello_world_with_updates.0.zig created+5
......@@ -0,0 +1,5 @@
1// error
2// output_mode=Exe
3// target=x86_64-macos
4//
5// :107:9: error: struct 'tmp.tmp' has no member named 'main'
test/cases/x86_64-macos/hello_world_with_updates.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/cases/x86_64-macos/hello_world_with_updates.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/cases/x86_64-macos/hello_world_with_updates.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/cases/x86_64-macos/hello_world_with_updates.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/cases/x86_64-macos/hello_world_with_updates.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/cases/x86_64-macos/hello_world_with_updates.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/compile_errors/stage1/exe/main_missing_name.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn (main) void {}
2
3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
7//
8// tmp.zig:1:5: error: missing function name
test/compile_errors/stage1/exe/missing_main_fn_in_executable.zig deleted-8
......@@ -1,8 +0,0 @@
1
2
3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
7//
8// error: root source file has no member called 'main'
test/compile_errors/stage1/exe/private_main_fn.zig deleted-9
......@@ -1,9 +0,0 @@
1fn main() void {}
2
3// error
4// backend=stage1
5// target=native
6// output_mode=Exe
7//
8// error: 'main' is private
9// tmp.zig:1:1: note: declared here
test/compile_errors/stage1/obj/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = struct {};
2export fn a() void {
3 const T = [*c]Foo;
4 var t: T = undefined;
5 _ = t;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'
test/compile_errors/stage1/obj/C_pointer_to_anyopaque.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn a() void {
2 var x: *anyopaque = undefined;
3 var y: [*c]anyopaque = x;
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:16: error: C pointers cannot point to opaque types
test/compile_errors/stage1/obj/Frame_of_generic_function.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 var frame: @Frame(func) = undefined;
3 _ = frame;
4}
5fn func(comptime T: type) void {
6 var x: T = undefined;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:16: error: @Frame() of generic function
test/compile_errors/stage1/obj/Issue_5586_Make_unary_minus_for_unsigned_types_a_compile_error.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn f1(x: u32) u32 {
2 const y = -%x;
3 return -y;
4}
5const V = @import("std").meta.Vector;
6export fn f2(x: V(4, u32)) V(4, u32) {
7 const y = -%x;
8 return -y;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:3:12: error: negation of type 'u32'
16// tmp.zig:8:12: error: negation of type 'u32'
test/compile_errors/stage1/obj/Issue_6823_dont_allow_._to_be_followed_by_.zig deleted-10
......@@ -1,10 +0,0 @@
1fn foo() void {
2 var sequence = "repeat".*** 10;
3 _ = sequence;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:28: error: '.*' cannot be followed by '*'. Are you missing a space?
test/compile_errors/stage1/obj/Issue_9165_windows_tcp_server_compilation_error.zig deleted-16
......@@ -1,16 +0,0 @@
1const std = @import("std");
2const builtin = @import("builtin");
3pub const io_mode = .evented;
4pub fn main() !void {
5 if (builtin.os.tag == .windows) {
6 _ = try (std.net.StreamServer.init(.{})).accept();
7 } else {
8 @compileError("Unsupported OS");
9 }
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// error: Unsupported OS
test/compile_errors/stage1/obj/access_non-existent_member_of_error_set.zig deleted-11
......@@ -1,11 +0,0 @@
1const Foo = error{A};
2comptime {
3 const z = Foo.Bar;
4 _ = z;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:18: error: no error named 'Bar' in 'Foo'
test/compile_errors/stage1/obj/accessing_runtime_parameter_from_outer_function.zig deleted-21
......@@ -1,21 +0,0 @@
1fn outer(y: u32) fn (u32) u32 {
2 const st = struct {
3 fn get(z: u32) u32 {
4 return z + y;
5 }
6 };
7 return st.get;
8}
9export fn entry() void {
10 var func = outer(10);
11 var x = func(3);
12 _ = x;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:4:24: error: 'y' not accessible from inner function
20// tmp.zig:3:28: note: crossed function definition here
21// tmp.zig:1:10: note: declared here
test/compile_errors/stage1/obj/add_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a += a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a + a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_overflow_in_function_evaluation.zig deleted-12
......@@ -1,12 +0,0 @@
1const y = add(65530, 10);
2fn add(a: u16, b: u16) u16 {
3 return a + b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/add_wrap_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a +%= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/add_wrap_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a +% a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/addition_with_non_numbers.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = struct {
2 field: i32,
3};
4const x = Foo {.field = 1} + Foo {.field = 2};
5
6export fn entry() usize { return @sizeOf(@TypeOf(x)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'
test/compile_errors/stage1/obj/address_of_number_literal.zig deleted-10
......@@ -1,10 +0,0 @@
1const x = 3;
2const y = &x;
3fn foo() *const i32 { return y; }
4export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'
test/compile_errors/stage1/obj/alignCast_expects_pointer_or_slice.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 @alignCast(4, @as(u32, 3));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:19: error: expected pointer or slice, found 'u32'
test/compile_errors/stage1/obj/align_n_expr_function_pointers_is_a_compile_error.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() align(1) void {
2 return;
3}
4
5// error
6// backend=stage1
7// target=wasm32-freestanding-none
8//
9// tmp.zig:1:23: error: align(N) expr is not allowed on function prototypes in wasm32/wasm64
test/compile_errors/stage1/obj/aligned_variable_of_zero-bit_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 var s: struct {} align(4) = undefined;
3 _ = s;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned
test/compile_errors/stage1/obj/alignment_of_enum_field_specified.zig deleted-14
......@@ -1,14 +0,0 @@
1const Number = enum {
2 a,
3 b align(i32),
4};
5export fn entry1() void {
6 var x: Number = undefined;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:7: error: expected ',' after field
test/compile_errors/stage1/obj/ambiguous_decl_reference.zig deleted-21
......@@ -1,21 +0,0 @@
1fn foo() void {}
2fn bar() void {
3 const S = struct {
4 fn baz() void {
5 foo();
6 }
7 fn foo() void {}
8 };
9 S.baz();
10}
11export fn entry() void {
12 bar();
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:5:13: error: ambiguous reference
20// tmp.zig:7:9: note: declared here
21// tmp.zig:1:1: note: also declared here
test/compile_errors/stage1/obj/and_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: bool = undefined;
3 _ = a and a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/array_access_of_non_array.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn f() void {
2 var bad : bool = undefined;
3 bad[0] = bad[0];
4}
5export fn g() void {
6 var bad : bool = undefined;
7 _ = bad[0];
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:8: error: array access of non-array type 'bool'
15// tmp.zig:7:12: error: array access of non-array type 'bool'
test/compile_errors/stage1/obj/array_access_of_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 var b: u8[40] = undefined;
3 _ = b;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: array access of non-array type 'type'
test/compile_errors/stage1/obj/array_access_of_undeclared_identifier.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 i[i] = i[i];
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: use of undeclared identifier 'i'
test/compile_errors/stage1/obj/array_access_with_non_integer_index.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn f() void {
2 var array = "aoeu";
3 var bad = false;
4 array[bad] = array[bad];
5}
6export fn g() void {
7 var array = "aoeu";
8 var bad = false;
9 _ = array[bad];
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:11: error: expected type 'usize', found 'bool'
17// tmp.zig:9:15: error: expected type 'usize', found 'bool'
test/compile_errors/stage1/obj/array_concatenation_with_wrong_type.zig deleted-11
......@@ -1,11 +0,0 @@
1const src = "aoeu";
2const derp: usize = 1234;
3const a = derp ++ "foo";
4
5export fn entry() usize { return @sizeOf(@TypeOf(a)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:11: error: expected array, found 'usize'
test/compile_errors/stage1/obj/array_in_c_exported_function.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn zig_array(x: [10]u8) void {
2 try std.testing.expect(std.mem.eql(u8, &x, "1234567890"));
3}
4const std = @import("std");
5export fn zig_return_array() [10]u8 {
6 return "1234567890".*;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:24: error: parameter of type '[10]u8' not allowed in function with calling convention 'C'
14// tmp.zig:5:30: error: return type '[10]u8' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/asm_at_compile_time.zig deleted-17
......@@ -1,17 +0,0 @@
1comptime {
2 doSomeAsm();
3}
4
5fn doSomeAsm() void {
6 asm volatile (
7 \\.globl aoeu;
8 \\.type aoeu, @function;
9 \\.set aoeu, derp;
10 );
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:5: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/assign_inline_fn_to_non-comptime_var.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var a = b;
3 _ = a;
4}
5fn b() callconv(.Inline) void { }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var
12// tmp.zig:5:1: note: declared here
test/compile_errors/stage1/obj/assign_null_to_non-optional_pointer.zig deleted-9
......@@ -1,9 +0,0 @@
1const a: *u8 = null;
2
3export fn entry() usize { return @sizeOf(@TypeOf(a)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:16: error: expected type '*u8', found '@Type(.Null)'
test/compile_errors/stage1/obj/assign_through_constant_pointer.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 var cstr = "Hat";
3 cstr[0] = 'W';
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:13: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_through_constant_slice.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 var cstr: []const u8 = "Hat";
3 cstr[0] = 'W';
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:13: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_constant_field.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = struct {
2 field: i32,
3};
4export fn derp() void {
5 const f = Foo {.field = 1234,};
6 f.field = 0;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:15: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_constant_variable.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 const a = 3;
3 a = 4;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: cannot assign to constant
test/compile_errors/stage1/obj/assign_to_invalid_dereference.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 'a'.* = 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'
test/compile_errors/stage1/obj/assign_too_big_number_to_u16.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 var vga_mem: u16 = 0xB8000;
3 _ = vga_mem;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'
test/compile_errors/stage1/obj/assign_unreachable.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 const a = return;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: unreachable code
10// tmp.zig:2:15: note: control flow is diverted here
test/compile_errors/stage1/obj/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig deleted-21
......@@ -1,21 +0,0 @@
1fn maybe(is: bool) ?u8 {
2 if (is) return @as(u8, 10) else return null;
3}
4const U = union {
5 Ye: u8,
6};
7const S = struct {
8 num: u8,
9};
10export fn entry() void {
11 var u = U{ .Ye = maybe(false) };
12 var s = S{ .num = maybe(false) };
13 _ = u;
14 _ = s;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:11:27: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'u8', found '?u8'
test/compile_errors/stage1/obj/async_function_depends_on_its_own_frame.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet
test/compile_errors/stage1/obj/async_function_indirectly_depends_on_its_own_frame.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 other();
6}
7fn other() void {
8 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:1: error: unable to determine async function frame of 'amain'
17// tmp.zig:5:10: note: analysis of function 'other' depends on the frame
test/compile_errors/stage1/obj/atomic_orderings_of_atomicStore_Acquire_or_AcqRel.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x: u32 = 0;
3 @atomicStore(u32, &x, 1, .Acquire);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel
test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-failure_stricter_than_success.zig deleted-11
......@@ -1,11 +0,0 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn f() void {
3 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:81: error: failure atomic ordering must be no stricter than success
test/compile_errors/stage1/obj/atomic_orderings_of_cmpxchg-success_Monotonic_or_stricter.zig deleted-11
......@@ -1,11 +0,0 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn f() void {
3 var x: i32 = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter
test/compile_errors/stage1/obj/atomic_orderings_of_fence_Acquire_or_stricter.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 @fence(.Monotonic);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:12: error: atomic ordering must be Acquire or stricter
test/compile_errors/stage1/obj/atomicrmw_with_bool_op_not_.Xchg.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x = false;
3 _ = @atomicRmw(bool, &x, .Add, true, .SeqCst);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:30: error: @atomicRmw with bool only allowed with .Xchg
test/compile_errors/stage1/obj/atomicrmw_with_enum_op_not_.Xchg.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 const E = enum(u8) {
3 a,
4 b,
5 c,
6 d,
7 };
8 var x: E = .a;
9 _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:27: error: @atomicRmw with enum only allowed with .Xchg
test/compile_errors/stage1/obj/atomicrmw_with_float_op_not_.Xchg_.Add_or_.Sub.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x: f32 = 0;
3 _ = @atomicRmw(f32, &x, .And, 2, .SeqCst);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:29: error: @atomicRmw with float only allowed with .Xchg, .Add and .Sub
test/compile_errors/stage1/obj/attempt_to_cast_enum_literal_to_error.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 switch (error.Hi) {
3 .Hi => {},
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: expected type 'error{Hi}', found '@Type(.EnumLiteral)'
test/compile_errors/stage1/obj/attempt_to_close_over_comptime_variable_from_outer_scope.zig deleted-14
......@@ -1,14 +0,0 @@
1fn SimpleList(comptime L: usize) type {
2 var T = u8;
3 return struct {
4 array: [L]T,
5 };
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:19: error: mutable 'T' not accessible from here
13// tmp.zig:2:9: note: declared mutable here
14// tmp.zig:3:12: note: crosses namespace boundary here
test/compile_errors/stage1/obj/attempt_to_create_17_bit_float_type.zig deleted-10
......@@ -1,10 +0,0 @@
1const builtin = @import("std").builtin;
2comptime {
3 _ = @Type(.{ .Float = .{ .bits = 17 } });
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:16: error: 17-bit float unsupported
test/compile_errors/stage1/obj/attempt_to_negate_a_non-integer_non-float_or_non-vector_type.zig deleted-14
......@@ -1,14 +0,0 @@
1fn foo() anyerror!u32 {
2 return 1;
3}
4
5export fn entry() void {
6 const x = -foo();
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:15: error: negation of type 'anyerror!u32'
test/compile_errors/stage1/obj/attempt_to_use_0_bit_type_in_extern_fn.zig deleted-17
......@@ -1,17 +0,0 @@
1extern fn foo(ptr: fn(*void) callconv(.C) void) void;
2
3export fn entry() void {
4 foo(bar);
5}
6
7fn bar(x: *void) callconv(.C) void { _ = x; }
8export fn entry2() void {
9 bar(&{});
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:1:23: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
17// tmp.zig:7:11: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/attempted_double_ampersand.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry(a: bool, b: bool) i32 {
2 if (a && b) {
3 return 1234;
4 }
5 return 5678;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:11: error: ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND
test/compile_errors/stage1/obj/attempted_double_pipe_on_boolean_values.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry(a: bool, b: bool) i32 {
2 if (a || b) {
3 return 1234;
4 }
5 return 5678;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:9: error: expected error set type, found 'bool'
13// tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR
test/compile_errors/stage1/obj/attempted_implicit_cast_from_T_to_slice_const_T.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x: [*]const bool = true;
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'
test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry(byte: u8) void {
2 const w: i32 = 1234;
3 var x: *const i32 = &w;
4 var y: *[1]i32 = x;
5 y[0] += 1;
6 _ = byte;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'
14// tmp.zig:4:22: note: cast discards const qualifier
test/compile_errors/stage1/obj/attempted_implicit_cast_from_const_T_to_sliceT.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 const u: u32 = 42;
3 const x: []u32 = &u;
4 _ = x;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:23: error: expected type '[]u32', found '*const u32'
test/compile_errors/stage1/obj/bad_alignCast_at_comptime.zig deleted-11
......@@ -1,11 +0,0 @@
1comptime {
2 const ptr = @intToPtr(*align(1) i32, 0x1);
3 const aligned = @alignCast(4, ptr);
4 _ = aligned;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes
test/compile_errors/stage1/obj/bad_alignment_in_asynccall.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var ptr: fn () callconv(.Async) void = func;
3 var bytes: [64]u8 = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});
5}
6fn func() callconv(.Async) void {}
7
8// error
9// backend=stage1
10// target=aarch64-linux-none
11//
12// tmp.zig:4:21: error: expected type '[]align(8) u8', found '*[64]u8'
test/compile_errors/stage1/obj/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn a() void {
2 var x: [10]u8 = undefined;
3 var y: []align(16) u8 = &x;
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'
test/compile_errors/stage1/obj/bad_alignment_type.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry1() void {
2 var x: []align(true) i32 = undefined;
3 _ = x;
4}
5export fn entry2() void {
6 var x: *align(@as(f64, 12.34)) i32 = undefined;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:20: error: expected type 'u29', found 'bool'
15// tmp.zig:6:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'
test/compile_errors/stage1/obj/bad_identifier_in_function_with_struct_defined_inside_function_which_references_local_const.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn entry() void {
2 const BlockKind = u32;
3
4 const Block = struct {
5 kind: BlockKind,
6 };
7
8 bogus;
9
10 _ = Block;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:8:5: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/bad_import.zig deleted-7
......@@ -1,7 +0,0 @@
1const bogus = @import("bogus-does-not-exist.zig",);
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:23: error: unable to load '${DIR}bogus-does-not-exist.zig': FileNotFound
test/compile_errors/stage1/obj/bad_usage_of_call.zig deleted-30
......@@ -1,30 +0,0 @@
1export fn entry1() void {
2 @call(.{}, foo, {});
3}
4export fn entry2() void {
5 comptime @call(.{ .modifier = .never_inline }, foo, .{});
6}
7export fn entry3() void {
8 comptime @call(.{ .modifier = .never_tail }, foo, .{});
9}
10export fn entry4() void {
11 @call(.{ .modifier = .never_inline }, bar, .{});
12}
13export fn entry5(c: bool) void {
14 var baz = if (c) baz1 else baz2;
15 @call(.{ .modifier = .compile_time }, baz, .{});
16}
17fn foo() void {}
18fn bar() callconv(.Inline) void {}
19fn baz1() void {}
20fn baz2() void {}
21
22// error
23// backend=stage1
24// target=native
25//
26// tmp.zig:2:21: error: expected tuple or struct, found 'void'
27// tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time
28// tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time
29// tmp.zig:11:5: error: no-inline call of inline function
30// tmp.zig:15:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/obj/bin_and_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a &= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_and_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a & a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_not_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = ~a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_or_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a |= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_or_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a | a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_xor_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a ^= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/bin_xor_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a ^ a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/binary_not_on_number_literal.zig deleted-11
......@@ -1,11 +0,0 @@
1const TINY_QUANTUM_SHIFT = 4;
2const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
3var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
4
5export fn entry() usize { return @sizeOf(@TypeOf(block_aligned_stuff)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'
test/compile_errors/stage1/obj/bitCast_same_size_but_bit_count_mismatch.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry(byte: u8) void {
2 var oops = @bitCast(u7, byte);
3 _ = oops;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/compile_errors/stage1/obj/bitCast_to_enum_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const y = @bitCast(enum(u32) { a, b }, @as(u32, 3));
3 _ = y;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:24: error: cannot cast a value of type 'y'
test/compile_errors/stage1/obj/bitCast_with_different_sizes_inside_an_expression.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
3 _ = foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4
test/compile_errors/stage1/obj/bit_shifting_only_works_on_integer_types.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = &@as(u8, 1) << 10;
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:16: error: bit shifting operation expected integer type, found '*const u8'
test/compile_errors/stage1/obj/bogus_compile_var.zig deleted-8
......@@ -1,8 +0,0 @@
1const x = @import("builtin").bogus;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'
test/compile_errors/stage1/obj/bogus_method_call_on_slice.zig deleted-11
......@@ -1,11 +0,0 @@
1var self = "aoeu";
2fn f(m: []const u8) void {
3 m.copy(u8, self[0..], m);
4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:6: error: no member named 'copy' in '[]const u8'
test/compile_errors/stage1/obj/bool_not_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: bool = undefined;
3 _ = !a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/branch_on_undefined_value.zig deleted-9
......@@ -1,9 +0,0 @@
1const x = if (undefined) true else false;
2
3export fn entry() usize { return @sizeOf(@TypeOf(x)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:15: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/cImport_with_bogus_include.zig deleted-9
......@@ -1,9 +0,0 @@
1const c = @cImport(@cInclude("bogus.h"));
2export fn entry() usize { return @sizeOf(@TypeOf(c.bogo)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:11: error: C import failed
9// .h:1:10: note: 'bogus.h' file not found
test/compile_errors/stage1/obj/call_assigned_to_constant.zig deleted-24
......@@ -1,24 +0,0 @@
1const Foo = struct {
2 x: i32,
3};
4fn foo() Foo {
5 return .{ .x = 42 };
6}
7fn bar(val: anytype) Foo {
8 return .{ .x = val };
9}
10export fn entry() void {
11 const baz: Foo = undefined;
12 baz = foo();
13}
14export fn entry1() void {
15 const baz: Foo = undefined;
16 baz = bar(42);
17}
18
19// error
20// backend=stage1
21// target=native
22//
23// tmp.zig:12:14: error: cannot assign to constant
24// tmp.zig:16:14: error: cannot assign to constant
test/compile_errors/stage1/obj/call_with_new_stack_on_unsupported_target.zig deleted-11
......@@ -1,11 +0,0 @@
1var buf: [10]u8 align(16) = undefined;
2export fn entry() void {
3 @call(.{ .stack = &buf }, foo, .{});
4}
5fn foo() void {}
6
7// error
8// backend=stage1
9// target=wasm32-wasi-none
10//
11// tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack
test/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export fn entry3() callconv(.AAPCSVFP) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64
10// tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64
11// tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64
test/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig deleted-7
......@@ -1,7 +0,0 @@
1export fn entry() callconv(.Interrupt) void {}
2
3// error
4// backend=stage1
5// target=aarch64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64
test/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig deleted-7
......@@ -1,7 +0,0 @@
1export fn entry() callconv(.Signal) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64
test/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig deleted-23
......@@ -1,23 +0,0 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export fn entry3() void {
13 var a: F3 = undefined;
14 _ = a;
15}
16
17// error
18// backend=stage1
19// target=x86_64-linux-none
20//
21// tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64
22// tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64
23// tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64
test/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry1() callconv(.Stdcall) void {}
2export fn entry2() callconv(.Fastcall) void {}
3export fn entry3() callconv(.Thiscall) void {}
4
5// error
6// backend=stage1
7// target=x86_64-linux-none
8//
9// tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64
10// tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64
11// tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64
test/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig deleted-7
......@@ -1,7 +0,0 @@
1export fn entry() callconv(.Vectorcall) void {}
2
3// error
4// backend=stage1
5// target=x86_64-linux-none
6//
7// tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64
test/compile_errors/stage1/obj/calling_a_generic_function_only_known_at_runtime.zig deleted-14
......@@ -1,14 +0,0 @@
1var foos = [_]fn(anytype) void { foo1, foo2 };
2
3fn foo1(arg: anytype) void {_ = arg;}
4fn foo2(arg: anytype) void {_ = arg;}
5
6pub fn main() !void {
7 foos[0](true);
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:9: error: calling a generic function requires compile-time known function value
test/compile_errors/stage1/obj/calling_function_with_naked_calling_convention.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Naked) void { }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: unable to call function with naked calling convention
11// tmp.zig:4:1: note: declared here
test/compile_errors/stage1/obj/calling_var_args_extern_function_passing_array_instead_of_pointer.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 foo("hello".*,);
3}
4pub extern fn foo(format: *const u8, ...) void;
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'
test/compile_errors/stage1/obj/cannot_break_out_of_defer_expression.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn foo() void {
2 while (true) {
3 defer {
4 break;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:13: error: cannot break out of defer expression
test/compile_errors/stage1/obj/cannot_continue_out_of_defer_expression.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn foo() void {
2 while (true) {
3 defer {
4 continue;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:13: error: cannot continue out of defer expression
test/compile_errors/stage1/obj/capture_group_on_switch_prong_with_incompatible_payload_types.zig deleted-21
......@@ -1,21 +0,0 @@
1const Union = union(enum) {
2 A: usize,
3 B: isize,
4};
5comptime {
6 var u = Union{ .A = 8 };
7 switch (u) {
8 .A, .B => |e| {
9 _ = e;
10 unreachable;
11 },
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:8:20: error: capture group with incompatible types
20// tmp.zig:8:9: note: type 'usize' here
21// tmp.zig:8:13: note: type 'isize' here
test/compile_errors/stage1/obj/cast_enum_literal_to_enum_but_it_doesnt_match.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = enum {
2 a,
3 b,
4};
5export fn entry() void {
6 const x: Foo = .c;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:20: error: enum 'Foo' has no field named 'c'
15// tmp.zig:1:13: note: 'Foo' declared here
test/compile_errors/stage1/obj/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig deleted-16
......@@ -1,16 +0,0 @@
1const SmallErrorSet = error{A};
2export fn entry() void {
3 var x: SmallErrorSet!i32 = foo();
4 _ = x;
5}
6fn foo() anyerror!i32 {
7 return error.B;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'
15// tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'
16// tmp.zig:3:35: note: cannot cast global error set into smaller set
test/compile_errors/stage1/obj/cast_global_error_set_to_error_set.zig deleted-15
......@@ -1,15 +0,0 @@
1const SmallErrorSet = error{A};
2export fn entry() void {
3 var x: SmallErrorSet = foo();
4 _ = x;
5}
6fn foo() anyerror {
7 return error.B;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'
15// tmp.zig:3:31: note: cannot cast global error set into smaller set
test/compile_errors/stage1/obj/cast_negative_integer_literal_to_usize.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = @as(usize, -10);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'
test/compile_errors/stage1/obj/cast_negative_value_to_unsigned_integer.zig deleted-17
......@@ -1,17 +0,0 @@
1comptime {
2 const value: i32 = -1;
3 const unsigned = @intCast(u32, value);
4 _ = unsigned;
5}
6export fn entry1() void {
7 const value: i32 = -1;
8 const unsigned: u32 = value;
9 _ = unsigned;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:22: error: attempt to cast negative value to unsigned integer
17// tmp.zig:8:27: error: cannot cast negative value -1 to unsigned integer type 'u32'
test/compile_errors/stage1/obj/cast_unreachable.zig deleted-11
......@@ -1,11 +0,0 @@
1fn f() i32 {
2 return @as(i32, return 1);
3}
4export fn entry() void { _ = f(); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:12: error: unreachable code
11// tmp.zig:2:21: note: control flow is diverted here
test/compile_errors/stage1/obj/casting_bit_offset_pointer_to_regular_pointer.zig deleted-21
......@@ -1,21 +0,0 @@
1const BitField = packed struct {
2 a: u3,
3 b: u3,
4 c: u2,
5};
6
7fn foo(bit_field: *const BitField) u3 {
8 return bar(&bit_field.b);
9}
10
11fn bar(x: *const u3) u3 {
12 return x.*;
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'
test/compile_errors/stage1/obj/catch_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: anyerror!bool = undefined;
3 _ = a catch false;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/chained_comparison_operators.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a(value: u32) bool {
2 return 1 < value < 1000;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: comparison operators cannot be chained
test/compile_errors/stage1/obj/cmpxchg_with_float.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x: f32 = 0;
3 _ = @cmpxchgWeak(f32, &x, 1, 2, .SeqCst, .SeqCst);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:22: error: expected bool, integer, enum or pointer type, found 'f32'
test/compile_errors/stage1/obj/colliding_invalid_top_level_functions.zig deleted-10
......@@ -1,10 +0,0 @@
1fn func() bogus {}
2fn func() bogus {}
3export fn entry() usize { return @sizeOf(@TypeOf(func)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:1: error: redeclaration of 'func'
10// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/compare_optional_to_non-optional_with_invalid_types.zig deleted-35
......@@ -1,35 +0,0 @@
1export fn inconsistentChildType() void {
2 var x: ?i32 = undefined;
3 const y: comptime_int = 10;
4 _ = (x == y);
5}
6
7export fn optionalToOptional() void {
8 var x: ?i32 = undefined;
9 var y: ?i32 = undefined;
10 _ = (x == y);
11}
12
13export fn optionalVector() void {
14 var x: ?@Vector(10, i32) = undefined;
15 var y: @Vector(10, i32) = undefined;
16 _ = (x == y);
17}
18
19export fn invalidChildType() void {
20 var x: ?[3]i32 = undefined;
21 var y: [3]i32 = undefined;
22 _ = (x == y);
23}
24
25// error
26// backend=stage1
27// target=native
28//
29// :4:12: error: cannot compare types '?i32' and 'comptime_int'
30// :4:12: note: optional child type 'i32' must be the same as non-optional type 'comptime_int'
31// :10:12: error: cannot compare types '?i32' and '?i32'
32// :10:12: note: optional to optional comparison is only supported for optional pointer types
33// :16:12: error: TODO add comparison of optional vector
34// :22:12: error: cannot compare types '?[3]i32' and '[3]i32'
35// :22:12: note: operator not supported for type '[3]i32'
test/compile_errors/stage1/obj/comparing_a_non-optional_pointer_against_null.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x: i32 = 1;
3 _ = &x == null;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: comparison of '*i32' with null
test/compile_errors/stage1/obj/comparing_against_undefined_produces_undefined_value.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 if (2 == undefined) {}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/comparison_operators_with_undefined_value.zig deleted-47
......@@ -1,47 +0,0 @@
1// operator ==
2comptime {
3 var a: i64 = undefined;
4 var x: i32 = 0;
5 if (a == a) x += 1;
6}
7// operator !=
8comptime {
9 var a: i64 = undefined;
10 var x: i32 = 0;
11 if (a != a) x += 1;
12}
13// operator >
14comptime {
15 var a: i64 = undefined;
16 var x: i32 = 0;
17 if (a > a) x += 1;
18}
19// operator <
20comptime {
21 var a: i64 = undefined;
22 var x: i32 = 0;
23 if (a < a) x += 1;
24}
25// operator >=
26comptime {
27 var a: i64 = undefined;
28 var x: i32 = 0;
29 if (a >= a) x += 1;
30}
31// operator <=
32comptime {
33 var a: i64 = undefined;
34 var x: i32 = 0;
35 if (a <= a) x += 1;
36}
37
38// error
39// backend=stage1
40// target=native
41//
42// tmp.zig:5:11: error: use of undefined value here causes undefined behavior
43// tmp.zig:11:11: error: use of undefined value here causes undefined behavior
44// tmp.zig:17:11: error: use of undefined value here causes undefined behavior
45// tmp.zig:23:11: error: use of undefined value here causes undefined behavior
46// tmp.zig:29:11: error: use of undefined value here causes undefined behavior
47// tmp.zig:35:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/comparison_with_error_union_and_error_value.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var number_or_error: anyerror!i32 = error.SomethingAwful;
3 _ = number_or_error == error.SomethingAwful;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'
test/compile_errors/stage1/obj/compile-time_division_by_zero.zig deleted-12
......@@ -1,12 +0,0 @@
1comptime {
2 const a: i32 = 1;
3 const b: i32 = 0;
4 const c = a / b;
5 _ = c;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:17: error: division by zero
test/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig deleted-12
......@@ -1,12 +0,0 @@
1comptime {
2 const a: i32 = 1;
3 const b: i32 = 0;
4 const c = a % b;
5 _ = c;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:17: error: division by zero
test/compile_errors/stage1/obj/compileError_shows_traceback_of_references_that_caused_it.zig deleted-14
......@@ -1,14 +0,0 @@
1const foo = @compileError("aoeu",);
2
3const bar = baz + foo;
4const baz = 1;
5
6export fn entry() i32 {
7 return bar;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:1:13: error: aoeu
test/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig deleted-17
......@@ -1,17 +0,0 @@
1const Bar = union(enum(u32)) {
2 X: i32 = 1
3};
4
5fn testCompileLog(x: Bar) void {
6 @compileLog(x);
7}
8
9pub fn main () void {
10 comptime testCompileLog(Bar{.X = 123});
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_error_in_struct_init_expression.zig deleted-16
......@@ -1,16 +0,0 @@
1const Foo = struct {
2 a: i32 = crap,
3 b: i32,
4};
5export fn entry() void {
6 var x = Foo{
7 .b = 5,
8 };
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:2:14: error: use of undeclared identifier 'crap'
test/compile_errors/stage1/obj/compile_error_when_evaluating_return_type_of_inferred_error_set.zig deleted-14
......@@ -1,14 +0,0 @@
1const Car = struct {
2 foo: *SymbolThatDoesNotExist,
3 pub fn init() !Car {}
4};
5export fn entry() void {
6 const car = Car.init();
7 _ = car;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'
test/compile_errors/stage1/obj/compile_log.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn foo() void {
2 comptime bar(12, "hi",);
3}
4fn bar(a: i32, b: []const u8) void {
5 @compileLog("begin",);
6 @compileLog("a", a, "b", b);
7 @compileLog("end",);
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:5: error: found compile log statement
15// tmp.zig:6:5: error: found compile log statement
16// tmp.zig:7:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_a_pointer_to_an_opaque_value.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 @compileLog(@ptrCast(*const anyopaque, &entry));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig deleted-14
......@@ -1,14 +0,0 @@
1fn Foo(comptime T: type) type {
2 @compileLog(@typeName(T));
3 return T;
4}
5export fn entry() void {
6 _ = Foo(i32);
7 _ = @typeName(Foo(i32));
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:5: error: found compile log statement
test/compile_errors/stage1/obj/compile_log_statement_warning_deduplication_in_generic_fn.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 inner(1);
3 inner(2);
4}
5fn inner(comptime n: usize) void {
6 comptime var i = 0;
7 inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:39: error: found compile log statement
test/compile_errors/stage1/obj/compile_time_division_by_zero.zig deleted-12
......@@ -1,12 +0,0 @@
1const y = foo(0);
2fn foo(x: u32) u32 {
3 return 1 / x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: division by zero
test/compile_errors/stage1/obj/comptime_cast_enum_to_union_but_field_has_payload.zig deleted-17
......@@ -1,17 +0,0 @@
1const Letter = enum { A, B, C };
2const Value = union(Letter) {
3 A: i32,
4 B,
5 C,
6};
7export fn entry() void {
8 var x: Value = Letter.A;
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'
17// tmp.zig:3:5: note: field 'A' declared here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_catch.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 const ints = [_]u8{ 1, 2 };
3 inline for (ints) |_| {
4 bad() catch continue;
5 }
6}
7fn bad() !void {
8 return error.Bad;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:4:21: error: comptime control flow inside runtime block
16// tmp.zig:4:15: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_bool.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var p: usize = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p == 11) continue;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:22: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_error.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var p: anyerror!i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p) |_| continue else |_| {}
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:20: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_if_optional.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var p: ?i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 if (p) |_| continue;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:20: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_switch.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn entry() void {
2 var p: i32 = undefined;
3 comptime var q = true;
4 inline while (q) {
5 switch (p) {
6 11 => continue,
7 else => {},
8 }
9 q = false;
10 }
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:19: error: comptime control flow inside runtime block
18// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_bool.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var p: usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p == 11) continue :outer;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:25: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_error.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn entry() void {
2 var p: anyerror!usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p) |_| {
6 continue :outer;
7 } else |_| {}
8 q = false;
9 }
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:13: error: comptime control flow inside runtime block
17// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_continue_inside_runtime_while_optional.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var p: ?usize = undefined;
3 comptime var q = true;
4 outer: inline while (q) {
5 while (p) |_| continue :outer;
6 q = false;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:23: error: comptime control flow inside runtime block
15// tmp.zig:5:9: note: runtime block created here
test/compile_errors/stage1/obj/comptime_float_in_asm_input.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3.17) : "");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float
test/compile_errors/stage1/obj/comptime_implicit_cast_f64_to_f32.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 const x: f64 = 16777217;
3 const y: f32 = x;
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information
test/compile_errors/stage1/obj/comptime_int_in_asm_input.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 asm volatile ("" : : [bar]"r"(3) : "");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int
test/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig deleted-12
......@@ -1,12 +0,0 @@
1fn foo() void {
2 const node: struct {} = undefined;
3 const vla_ptr = @ptrCast([*]const u8, &node);
4 _ = vla_ptr;
5}
6comptime { foo(); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_terminated.zig deleted-67
......@@ -1,67 +0,0 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..3 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..3 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..3 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..3 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..3 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..3 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..3 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel does not match memory at target index
62// :12:29: error: slice-sentinel does not match memory at target index
63// :20:29: error: slice-sentinel does not match memory at target index
64// :28:29: error: slice-sentinel does not match memory at target index
65// :36:29: error: slice-sentinel does not match memory at target index
66// :44:29: error: slice-sentinel does not match memory at target index
67// :52:29: error: slice-sentinel does not match memory at target index
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_memory_at_target_index_unterminated.zig deleted-67
......@@ -1,67 +0,0 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..3 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..3 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..3 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..3 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..3 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..3 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..3 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel does not match memory at target index
62// :12:29: error: slice-sentinel does not match memory at target index
63// :20:29: error: slice-sentinel does not match memory at target index
64// :28:29: error: slice-sentinel does not match memory at target index
65// :36:29: error: slice-sentinel does not match memory at target index
66// :44:29: error: slice-sentinel does not match memory at target index
67// :52:29: error: slice-sentinel does not match memory at target index
test/compile_errors/stage1/obj/comptime_slice-sentinel_does_not_match_target-sentinel.zig deleted-67
......@@ -1,67 +0,0 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..14 :255];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..14 :255];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..14 :255];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..14 :255];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..14 :255];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..14 :255];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..14 :255];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel does not match target-sentinel
62// :12:29: error: slice-sentinel does not match target-sentinel
63// :20:29: error: slice-sentinel does not match target-sentinel
64// :28:29: error: slice-sentinel does not match target-sentinel
65// :36:29: error: slice-sentinel does not match target-sentinel
66// :44:29: error: slice-sentinel does not match target-sentinel
67// :52:29: error: slice-sentinel does not match target-sentinel
test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_terminated.zig deleted-67
......@@ -1,67 +0,0 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..15 :1];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..15 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..15 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..15 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..15 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..15 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_:0]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..15 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: out of bounds slice
62// :12:29: error: out of bounds slice
63// :20:29: error: out of bounds slice
64// :28:29: error: out of bounds slice
65// :36:29: error: out of bounds slice
66// :44:29: error: out of bounds slice
67// :52:29: error: out of bounds slice
test/compile_errors/stage1/obj/comptime_slice-sentinel_is_out_of_bounds_unterminated.zig deleted-67
......@@ -1,67 +0,0 @@
1export fn foo_array() void {
2 comptime {
3 var target = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
4 const slice = target[0..14 :0];
5 _ = slice;
6 }
7}
8export fn foo_ptr_array() void {
9 comptime {
10 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
11 var target = &buf;
12 const slice = target[0..14 :0];
13 _ = slice;
14 }
15}
16export fn foo_vector_ConstPtrSpecialBaseArray() void {
17 comptime {
18 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
19 var target: [*]u8 = &buf;
20 const slice = target[0..14 :0];
21 _ = slice;
22 }
23}
24export fn foo_vector_ConstPtrSpecialRef() void {
25 comptime {
26 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
27 var target: [*]u8 = @ptrCast([*]u8, &buf);
28 const slice = target[0..14 :0];
29 _ = slice;
30 }
31}
32export fn foo_cvector_ConstPtrSpecialBaseArray() void {
33 comptime {
34 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
35 var target: [*c]u8 = &buf;
36 const slice = target[0..14 :0];
37 _ = slice;
38 }
39}
40export fn foo_cvector_ConstPtrSpecialRef() void {
41 comptime {
42 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
43 var target: [*c]u8 = @ptrCast([*c]u8, &buf);
44 const slice = target[0..14 :0];
45 _ = slice;
46 }
47}
48export fn foo_slice() void {
49 comptime {
50 var buf = [_]u8{ 'a', 'b', 'c', 'd' } ++ [_]u8{undefined} ** 10;
51 var target: []u8 = &buf;
52 const slice = target[0..14 :0];
53 _ = slice;
54 }
55}
56
57// error
58// backend=stage1
59// target=native
60//
61// :4:29: error: slice-sentinel is out of bounds
62// :12:29: error: slice-sentinel is out of bounds
63// :20:29: error: slice-sentinel is out of bounds
64// :28:29: error: slice-sentinel is out of bounds
65// :36:29: error: slice-sentinel is out of bounds
66// :44:29: error: slice-sentinel is out of bounds
67// :52:29: error: slice-sentinel is out of bounds
test/compile_errors/stage1/obj/comptime_slice_of_an_undefined_slice.zig deleted-11
......@@ -1,11 +0,0 @@
1comptime {
2 var a: []u8 = undefined;
3 var b = a[0..10];
4 _ = b;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:14: error: slice of undefined
test/compile_errors/stage1/obj/comptime_slice_of_undefined_pointer_non-zero_len.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const slice = @as([*]i32, undefined)[0..1];
3 _ = slice;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:41: error: non-zero length slice of undefined pointer
test/compile_errors/stage1/obj/comptime_struct_field_no_init_value.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = struct {
2 comptime b: i32,
3};
4export fn entry() void {
5 var f: Foo = undefined;
6 _ = f;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: comptime field without default initialization value
test/compile_errors/stage1/obj/const_frame_cast_to_anyframe.zig deleted-19
......@@ -1,19 +0,0 @@
1export fn a() void {
2 const f = async func();
3 resume f;
4}
5export fn b() void {
6 const f = async func();
7 var x: anyframe = &f;
8 _ = x;
9}
10fn func() void {
11 suspend {}
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'
19// tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'
test/compile_errors/stage1/obj/const_is_a_statement_not_an_expression.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 (const a = 0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:6: error: expected expression, found 'const'
test/compile_errors/stage1/obj/container_init_with_non-type.zig deleted-10
......@@ -1,10 +0,0 @@
1const zero: i32 = 0;
2const a = zero{1};
3
4export fn entry() usize { return @sizeOf(@TypeOf(a)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:11: error: expected type 'type', found 'i32'
test/compile_errors/stage1/obj/control_flow_uses_comptime_var_at_runtime.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn foo() void {
2 comptime var i = 0;
3 while (i < 5) : (i += 1) {
4 bar();
5 }
6}
7
8fn bar() void { }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime
15// tmp.zig:3:24: note: compile-time variable assigned here
test/compile_errors/stage1/obj/control_reaches_end_of_non-void_function.zig deleted-8
......@@ -1,8 +0,0 @@
1fn a() i32 {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:12: error: expected type 'i32', found 'void'
test/compile_errors/stage1/obj/declaration_between_fields.zig deleted-24
......@@ -1,24 +0,0 @@
1const S = struct {
2 const foo = 2;
3 const bar = 2;
4 const baz = 2;
5 a: struct {
6 a: u32,
7 b: u32,
8 },
9 const foo1 = 2;
10 const bar1 = 2;
11 const baz1 = 2;
12 b: usize,
13};
14comptime {
15 _ = S;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:9:5: error: declarations are not allowed between container fields
23// tmp.zig:5:5: note: field before declarations here
24// tmp.zig:12:5: note: field after declarations here
test/compile_errors/stage1/obj/declaration_with_same_name_as_primitive_must_use_special_syntax.zig deleted-12
......@@ -1,12 +0,0 @@
1const u8 = u16;
2export fn entry() void {
3 const a: u8 = 300;
4 _ = a;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:7: error: name shadows primitive 'u8'
12// tmp.zig:1:7: note: consider using @"u8" to disambiguate
test/compile_errors/stage1/obj/deduplicate_undeclared_identifier.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn a() void {
2 x += 1;
3}
4export fn b() void {
5 x += 1;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:5: error: use of undeclared identifier 'x'
test/compile_errors/stage1/obj/deref_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: *u8 = undefined;
3 _ = a.*;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: attempt to dereference undefined value
test/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var a: []u8 = undefined;
3 _ = a.*.len;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'
test/compile_errors/stage1/obj/dereference_an_array.zig deleted-14
......@@ -1,14 +0,0 @@
1var s_buffer: [10]u8 = undefined;
2pub fn pass(in: []u8) []u8 {
3 var out = &s_buffer;
4 out.*.* = in[0];
5 return out.*[0..1];
6}
7
8export fn entry() usize { return @sizeOf(@TypeOf(pass)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'
test/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(x: [*]i32) i32 {
2 return x.*;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'
test/compile_errors/stage1/obj/direct_struct_loop.zig deleted-8
......@@ -1,8 +0,0 @@
1const A = struct { a : A, };
2export fn entry() usize { return @sizeOf(A); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:11: error: struct 'A' depends on itself
test/compile_errors/stage1/obj/directly_embedding_opaque_type_in_struct_and_union.zig deleted-29
......@@ -1,29 +0,0 @@
1const O = opaque {};
2const Foo = struct {
3 o: O,
4};
5const Bar = union {
6 One: i32,
7 Two: O,
8};
9export fn a() void {
10 var foo: Foo = undefined;
11 _ = foo;
12}
13export fn b() void {
14 var bar: Bar = undefined;
15 _ = bar;
16}
17export fn c() void {
18 var baz: *opaque {} = undefined;
19 const qux = .{baz.*};
20 _ = qux;
21}
22
23// error
24// backend=stage1
25// target=native
26//
27// tmp.zig:3:5: error: opaque types have unknown size and therefore cannot be directly embedded in structs
28// tmp.zig:7:5: error: opaque types have unknown size and therefore cannot be directly embedded in unions
29// tmp.zig:19:22: error: opaque types have unknown size and therefore cannot be directly embedded in structs
test/compile_errors/stage1/obj/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig deleted-12
......@@ -1,12 +0,0 @@
1extern fn puts(s: [*:0]const u8) c_int;
2pub fn main() void {
3 const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
4 const no_zero_ptr: [*]const u8 = &no_zero_array;
5 _ = puts(no_zero_ptr);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'
test/compile_errors/stage1/obj/discarding_error_value.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = foo();
3}
4fn foo() !void {
5 return error.OutOfMemory;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/div_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a /= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/div_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a / a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/division_by_zero.zig deleted-18
......@@ -1,18 +0,0 @@
1const lit_int_x = 1 / 0;
2const lit_float_x = 1.0 / 0.0;
3const int_x = @as(u32, 1) / @as(u32, 0);
4const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5
6export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
7export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
9export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:21: error: division by zero
16// tmp.zig:2:25: error: division by zero
17// tmp.zig:3:27: error: division by zero
18// tmp.zig:4:31: error: division by zero
test/compile_errors/stage1/obj/dont_implicit_cast_double_pointer_to_anyopaque.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 var a: u32 = 1;
3 var ptr: *align(@alignOf(u32)) anyopaque = &a;
4 var b: *u32 = @ptrCast(*u32, ptr);
5 var ptr2: *anyopaque = &b;
6 _ = ptr2;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:29: error: expected type '*anyopaque', found '**u32'
test/compile_errors/stage1/obj/double_optional_on_main_return_value.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() ??void {
2}
3
4// error
5// backend=stage1
6// target=native
7//
8// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/compile_errors/stage1/obj/duplicate_boolean_switch_value.zig deleted-23
......@@ -1,23 +0,0 @@
1comptime {
2 const x = switch (true) {
3 true => false,
4 false => true,
5 true => false,
6 };
7 _ = x;
8}
9comptime {
10 const x = switch (true) {
11 false => true,
12 true => false,
13 false => true,
14 };
15 _ = x;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:5:9: error: duplicate switch value
23// tmp.zig:13:9: error: duplicate switch value
test/compile_errors/stage1/obj/duplicate_enum_field.zig deleted-16
......@@ -1,16 +0,0 @@
1const Foo = enum {
2 Bar,
3 Bar,
4};
5
6export fn entry() void {
7 const a: Foo = undefined;
8 _ = a;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:3:5: error: duplicate enum field: 'Bar'
16// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/duplicate_error_in_switch.zig deleted-22
......@@ -1,22 +0,0 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 error.Bar => {},
5 error.Foo => {},
6 else => {},
7 };
8}
9fn foo(x: i32) !void {
10 switch (x) {
11 0 ... 10 => return error.Foo,
12 11 ... 20 => return error.Bar,
13 else => {},
14 }
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo'
22// tmp.zig:3:14: note: other value here
test/compile_errors/stage1/obj/duplicate_error_value_in_error_set.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = error {
2 Bar,
3 Bar,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: duplicate error set field 'Bar'
15// tmp.zig:2:5: note: previous declaration here
test/compile_errors/stage1/obj/duplicate_field_in_struct_value_expression.zig deleted-20
......@@ -1,20 +0,0 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 const a = A {
8 .z = 1,
9 .y = 2,
10 .x = 3,
11 .z = 4,
12 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:11:9: error: duplicate field
test/compile_errors/stage1/obj/duplicate_struct_field.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = struct {
2 Bar: i32,
3 Bar: usize,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: duplicate struct field: 'Bar'
15// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/duplicate_union_field.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = union {
2 Bar: i32,
3 Bar: usize,
4};
5export fn entry() void {
6 const a: Foo = undefined;
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: duplicate union field: 'Bar'
15// tmp.zig:2:5: note: other field here
test/compile_errors/stage1/obj/embedFile_with_bogus_file.zig deleted-9
......@@ -1,9 +0,0 @@
1const resource = @embedFile("bogus.txt",);
2
3export fn entry() usize { return @sizeOf(@TypeOf(resource)); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:29: error: unable to find '
test/compile_errors/stage1/obj/empty_for_loop_body.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a() void {
2 for(undefined) |x|;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:23: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/empty_if_body.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a() void {
2 if(true);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:13: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/empty_switch_on_an_integer.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x: u32 = 0;
3 switch(x) {}
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: switch must handle all possibilities
test/compile_errors/stage1/obj/empty_while_loop_body.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a() void {
2 while(true);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:16: error: expected block or assignment, found ';'
test/compile_errors/stage1/obj/endless_loop_in_function_evaluation.zig deleted-12
......@@ -1,12 +0,0 @@
1const seventh_fib_number = fibonacci(7);
2fn fibonacci(x: i32) i32 {
3 return fibonacci(x - 1) + fibonacci(x - 2);
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(seventh_fib_number)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches
test/compile_errors/stage1/obj/enum_field_value_references_enum.zig deleted-15
......@@ -1,15 +0,0 @@
1pub const Foo = enum(c_int) {
2 A = Foo.B,
3 C = D,
4};
5export fn entry() void {
6 var s: Foo = Foo.E;
7 _ = s;
8}
9const D = 1;
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:17: error: enum 'Foo' depends on itself
test/compile_errors/stage1/obj/enum_in_field_count_range_but_not_matching_tag.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = enum(u32) {
2 A = 10,
3 B = 11,
4};
5export fn entry() void {
6 var x = @intToEnum(Foo, 0);
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0
15// tmp.zig:1:13: note: 'Foo' declared here
test/compile_errors/stage1/obj/enum_value_already_taken.zig deleted-18
......@@ -1,18 +0,0 @@
1const MultipleChoice = enum(u32) {
2 A = 20,
3 B = 40,
4 C = 60,
5 D = 1000,
6 E = 60,
7};
8export fn entry() void {
9 var x = MultipleChoice.C;
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:5: error: enum tag value 60 already taken
18// tmp.zig:4:5: note: other occurrence here
test/compile_errors/stage1/obj/enum_with_0_fields.zig deleted-7
......@@ -1,7 +0,0 @@
1const Foo = enum {};
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:13: error: enum declarations must have at least one tag
test/compile_errors/stage1/obj/enum_with_declarations_unavailable_for_reify_type.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 _ = @Type(@typeInfo(enum { foo, const bar = 1; }));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: Type.Enum.decls must be empty for @Type
test/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig deleted-16
......@@ -1,16 +0,0 @@
1const Set1 = error{A, C};
2const Set2 = error{B, D};
3export fn entry() void {
4 foo(Set1.A);
5}
6fn foo(x: Set1) void {
7 if (x == Set2.B) {
8
9 }
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors
test/compile_errors/stage1/obj/error_not_handled_in_switch.zig deleted-20
......@@ -1,20 +0,0 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 };
5}
6fn foo(x: i32) !void {
7 switch (x) {
8 0 ... 10 => return error.Foo,
9 11 ... 20 => return error.Bar,
10 21 ... 30 => return error.Baz,
11 else => {},
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:26: error: error.Baz not handled in switch
20// tmp.zig:2:26: error: error.Bar not handled in switch
test/compile_errors/stage1/obj/error_note_for_function_parameter_incompatibility.zig deleted-12
......@@ -1,12 +0,0 @@
1fn do_the_thing(func: fn (arg: i32) void) void { _ = func; }
2fn bar(arg: bool) void { _ = arg; }
3export fn entry() void {
4 do_the_thing(bar);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void
12// tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'
test/compile_errors/stage1/obj/error_union_operator_with_non_error_set_LHS.zig deleted-11
......@@ -1,11 +0,0 @@
1comptime {
2 const z = i32!i32;
3 var x: z = undefined;
4 _ = x;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:15: error: expected error set type, found type 'i32'
test/compile_errors/stage1/obj/error_when_evaluating_return_type.zig deleted-17
......@@ -1,17 +0,0 @@
1const Foo = struct {
2 map: @as(i32, i32),
3
4 fn init() Foo {
5 return undefined;
6 }
7};
8export fn entry() void {
9 var rule_set = try Foo.init();
10 _ = rule_set;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:2:19: error: expected type 'i32', found 'type'
test/compile_errors/stage1/obj/exceeded_maximum_bit_width_of_integer.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry1() void {
2 const T = u65536;
3 _ = T;
4}
5export fn entry2() void {
6 var x: i65536 = 1;
7 _ = x;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:15: error: primitive integer type 'u65536' exceeds maximum bit width of 65535
15// tmp.zig:6:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535
test/compile_errors/stage1/obj/explicit_cast_float_literal_to_integer_when_there_is_a_fraction_component.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() i32 {
2 return @as(i32, 12.34);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'
test/compile_errors/stage1/obj/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig deleted-13
......@@ -1,13 +0,0 @@
1const Set1 = error {A, B};
2const Set2 = error {A, C};
3comptime {
4 var x = Set1.B;
5 var y = @errSetCast(Set2, x);
6 _ = y;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:13: error: error.B not a member of error set 'Set2'
test/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig deleted-18
......@@ -1,18 +0,0 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export fn entry() void {
9 var y = @as(f32, 3);
10 var x = @intToEnum(Small, y);
11 _ = x;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:10:31: error: expected integer type, found 'f32'
test/compile_errors/stage1/obj/export_function_with_comptime_parameter.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo(comptime x: i32, y: i32) i32{
2 return x + y;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/export_generic_function.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo(num: anytype) i32 {
2 _ = num;
3 return 0;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:15: error: parameter of type 'anytype' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/exported_async_function.zig deleted-7
......@@ -1,7 +0,0 @@
1export fn foo() callconv(.Async) void {}
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:1: error: exported function cannot be async
test/compile_errors/stage1/obj/exported_enum_without_explicit_integer_tag_type.zig deleted-15
......@@ -1,15 +0,0 @@
1const E = enum { one, two };
2comptime {
3 @export(E, .{ .name = "E" });
4}
5const e: E = .two;
6comptime {
7 @export(e, .{ .name = "e" });
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:13: error: exported enum without explicit integer tag type
15// tmp.zig:7:13: error: exported enum value without explicit integer tag type
test/compile_errors/stage1/obj/extern_function_pointer_mismatch.zig deleted-12
......@@ -1,12 +0,0 @@
1const fns = [_](fn(i32)i32) { a, b, c };
2pub fn a(x: i32) i32 {return x + 0;}
3pub fn b(x: i32) i32 {return x + 1;}
4export fn c(x: i32) i32 {return x + 2;}
5
6export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'fn(i32) callconv(.C) i32'
test/compile_errors/stage1/obj/extern_function_with_comptime_parameter.zig deleted-11
......@@ -1,11 +0,0 @@
1extern fn foo(comptime x: i32, y: i32) i32;
2fn f() i32 {
3 return foo(1, 2);
4}
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/extern_struct_with_extern-compatible_but_inferred_integer_tag_type.zig deleted-43
......@@ -1,43 +0,0 @@
1pub const E = enum {
2@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",
3@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",
4@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",
5@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",
6@"46",@"47",@"48",@"49",@"50",@"51",@"52",@"53",@"54",@"55",@"56",
7@"57",@"58",@"59",@"60",@"61",@"62",@"63",@"64",@"65",@"66",@"67",
8@"68",@"69",@"70",@"71",@"72",@"73",@"74",@"75",@"76",@"77",@"78",
9@"79",@"80",@"81",@"82",@"83",@"84",@"85",@"86",@"87",@"88",@"89",
10@"90",@"91",@"92",@"93",@"94",@"95",@"96",@"97",@"98",@"99",@"100",
11@"101",@"102",@"103",@"104",@"105",@"106",@"107",@"108",@"109",
12@"110",@"111",@"112",@"113",@"114",@"115",@"116",@"117",@"118",
13@"119",@"120",@"121",@"122",@"123",@"124",@"125",@"126",@"127",
14@"128",@"129",@"130",@"131",@"132",@"133",@"134",@"135",@"136",
15@"137",@"138",@"139",@"140",@"141",@"142",@"143",@"144",@"145",
16@"146",@"147",@"148",@"149",@"150",@"151",@"152",@"153",@"154",
17@"155",@"156",@"157",@"158",@"159",@"160",@"161",@"162",@"163",
18@"164",@"165",@"166",@"167",@"168",@"169",@"170",@"171",@"172",
19@"173",@"174",@"175",@"176",@"177",@"178",@"179",@"180",@"181",
20@"182",@"183",@"184",@"185",@"186",@"187",@"188",@"189",@"190",
21@"191",@"192",@"193",@"194",@"195",@"196",@"197",@"198",@"199",
22@"200",@"201",@"202",@"203",@"204",@"205",@"206",@"207",@"208",
23@"209",@"210",@"211",@"212",@"213",@"214",@"215",@"216",@"217",
24@"218",@"219",@"220",@"221",@"222",@"223",@"224",@"225",@"226",
25@"227",@"228",@"229",@"230",@"231",@"232",@"233",@"234",@"235",
26@"236",@"237",@"238",@"239",@"240",@"241",@"242",@"243",@"244",
27@"245",@"246",@"247",@"248",@"249",@"250",@"251",@"252",@"253",
28@"254",@"255"
29};
30pub const S = extern struct {
31 e: E,
32};
33export fn entry() void {
34 if (@typeInfo(E).Enum.tag_type != u8) @compileError("did not infer u8 tag type");
35 const s: S = undefined;
36 _ = s;
37}
38
39// error
40// backend=stage1
41// target=native
42//
43// tmp.zig:31:5: error: extern structs cannot contain fields of type 'E'
test/compile_errors/stage1/obj/extern_struct_with_non-extern-compatible_integer_tag_type.zig deleted-14
......@@ -1,14 +0,0 @@
1pub const E = enum(u31) { A, B, C };
2pub const S = extern struct {
3 e: E,
4};
5export fn entry() void {
6 const s: S = undefined;
7 _ = s;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: extern structs cannot contain fields of type 'E'
test/compile_errors/stage1/obj/extern_union_field_missing_type.zig deleted-13
......@@ -1,13 +0,0 @@
1const Letter = extern union {
2 A,
3};
4export fn entry() void {
5 var a = Letter { .A = {} };
6 _ = a;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: union field missing type
test/compile_errors/stage1/obj/extern_union_given_enum_tag_type.zig deleted-20
......@@ -1,20 +0,0 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = extern union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10};
11export fn entry() void {
12 var a = Payload { .A = 1234 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:6:30: error: extern union does not support enum tag type
test/compile_errors/stage1/obj/extern_variable_has_no_type.zig deleted-10
......@@ -1,10 +0,0 @@
1extern var foo;
2pub export fn entry() void {
3 foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:8: error: unable to infer variable type
test/compile_errors/stage1/obj/fieldParentPtr-bad_field_name.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = extern struct {
2 derp: i32,
3};
4export fn foo(a: *i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:33: error: struct 'Foo' has no field 'a'
test/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig deleted-17
......@@ -1,17 +0,0 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
8 const field_ptr = @intToPtr(*i32, 0x1234);
9 const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
10 _ = another_foo_ptr;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:55: error: pointer value not based on parent struct
test/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig deleted-16
......@@ -1,16 +0,0 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
8 const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
9 _ = another_foo_ptr;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'
test/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = extern struct {
2 a: i32,
3};
4export fn foo(a: i32) *Foo {
5 return @fieldParentPtr(Foo, "a", a);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:38: error: expected pointer, found 'i32'
test/compile_errors/stage1/obj/fieldParentPtr-non_struct.zig deleted-10
......@@ -1,10 +0,0 @@
1const Foo = i32;
2export fn foo(a: *i32) *Foo {
3 return @fieldParentPtr(Foo, "a", a);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:28: error: expected struct type, found 'i32'
test/compile_errors/stage1/obj/field_access_of_opaque_type.zig deleted-16
......@@ -1,16 +0,0 @@
1const MyType = opaque {};
2
3export fn entry() bool {
4 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));
6}
7
8fn bar(x: *MyType) bool {
9 return x.blah;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType'
test/compile_errors/stage1/obj/field_access_of_slices.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 var slice: []i32 = undefined;
3 const info = @TypeOf(slice).unknown;
4 _ = info;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:32: error: type 'type' does not support field access
test/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = extern struct {
2 a: i32,
3};
4
5export fn entry(foo: [*]Foo) void {
6 foo.a += 1;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:8: error: type '[*]Foo' does not support field access
test/compile_errors/stage1/obj/field_type_supplied_in_an_enum.zig deleted-12
......@@ -1,12 +0,0 @@
1const Letter = enum {
2 A: void,
3 B,
4 C,
5};
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:8: error: enum fields do not have types
12// tmp.zig:1:16: note: consider 'union(enum)' here to make it a tagged union
test/compile_errors/stage1/obj/floatToInt_comptime_safety.zig deleted-17
......@@ -1,17 +0,0 @@
1comptime {
2 _ = @floatToInt(i8, @as(f32, -129.1));
3}
4comptime {
5 _ = @floatToInt(u8, @as(f32, -1.1));
6}
7comptime {
8 _ = @floatToInt(u8, @as(f32, 256.1));
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'
16// tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'
17// tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'
test/compile_errors/stage1/obj/float_literal_too_large_error.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 const a = 0x1.0p18495;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: float literal out of range of any type
test/compile_errors/stage1/obj/float_literal_too_small_error_denormal.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 const a = 0x1.0p-19000;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: float literal out of range of any type
test/compile_errors/stage1/obj/for_loop_body_expression_ignored.zig deleted-18
......@@ -1,18 +0,0 @@
1fn returns() usize {
2 return 2;
3}
4export fn f1() void {
5 for ("hello") |_| returns();
6}
7export fn f2() void {
8 var x: anyerror!i32 = error.Bad;
9 for ("hello") |_| returns() else unreachable;
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:5:30: error: expression value is ignored
18// tmp.zig:9:30: error: expression value is ignored
test/compile_errors/stage1/obj/frame_called_outside_of_function_definition.zig deleted-11
......@@ -1,11 +0,0 @@
1var handle_undef: anyframe = undefined;
2var handle_dummy: anyframe = @frame();
3export fn entry() bool {
4 return handle_undef == handle_dummy;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:30: error: @frame() called outside of function definition
test/compile_errors/stage1/obj/frame_causes_function_to_be_async.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 func();
3}
4fn func() void {
5 _ = @frame();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
13// tmp.zig:5:9: note: @frame() causes function to be async
test/compile_errors/stage1/obj/function_alignment_non_power_of_2.zig deleted-8
......@@ -1,8 +0,0 @@
1extern fn foo() align(3) void;
2export fn entry() void { return foo(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:23: error: alignment value 3 is not a power of 2
test/compile_errors/stage1/obj/function_call_assigned_to_incorrect_type.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 var arr: [4]f32 = undefined;
3 arr = concat();
4}
5fn concat() [16]f32 {
6 return [1]f32{0}**16;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:17: error: expected type '[4]f32', found '[16]f32'
test/compile_errors/stage1/obj/function_parameter_is_opaque.zig deleted-29
......@@ -1,29 +0,0 @@
1const FooType = opaque {};
2export fn entry1() void {
3 const someFuncPtr: fn (FooType) void = undefined;
4 _ = someFuncPtr;
5}
6
7export fn entry2() void {
8 const someFuncPtr: fn (@TypeOf(null)) void = undefined;
9 _ = someFuncPtr;
10}
11
12fn foo(p: FooType) void {_ = p;}
13export fn entry3() void {
14 _ = foo;
15}
16
17fn bar(p: @TypeOf(null)) void {_ = p;}
18export fn entry4() void {
19 _ = bar;
20}
21
22// error
23// backend=stage1
24// target=native
25//
26// tmp.zig:3:28: error: parameter of opaque type 'FooType' not allowed
27// tmp.zig:8:28: error: parameter of type '@Type(.Null)' not allowed
28// tmp.zig:12:11: error: parameter of opaque type 'FooType' not allowed
29// tmp.zig:17:11: error: parameter of type '@Type(.Null)' not allowed
test/compile_errors/stage1/obj/function_prototype_with_no_body.zig deleted-10
......@@ -1,10 +0,0 @@
1fn foo() void;
2export fn entry() void {
3 foo();
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:1: error: non-extern function has no body
test/compile_errors/stage1/obj/function_returning_opaque_type.zig deleted-19
......@@ -1,19 +0,0 @@
1const FooType = opaque {};
2export fn bar() !FooType {
3 return error.InvalidValue;
4}
5export fn bav() !@TypeOf(null) {
6 return error.InvalidValue;
7}
8export fn baz() !@TypeOf(undefined) {
9 return error.InvalidValue;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:2:18: error: Opaque return type 'FooType' not allowed
17// tmp.zig:1:1: note: type declared here
18// tmp.zig:5:18: error: Null return type '@Type(.Null)' not allowed
19// tmp.zig:8:18: error: Undefined return type '@Type(.Undefined)' not allowed
test/compile_errors/stage1/obj/function_with_ccc_indirectly_calling_async_function.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn entry() void {
2 foo();
3}
4fn foo() void {
5 bar();
6}
7fn bar() void {
8 suspend {}
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
16// tmp.zig:2:8: note: async function call here
17// tmp.zig:5:8: note: async function call here
18// tmp.zig:8:5: note: suspends here
test/compile_errors/stage1/obj/function_with_invalid_return_type.zig deleted-7
......@@ -1,7 +0,0 @@
1export fn foo() boid {}
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:17: error: use of undeclared identifier 'boid'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_enum_parameter.zig deleted-8
......@@ -1,8 +0,0 @@
1const Foo = enum { A, B, C };
2export fn entry(foo: Foo) void { _ = foo; }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_struct_parameter.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = struct {
2 A: i32,
3 B: f32,
4 C: bool,
5};
6export fn entry(foo: Foo) void { _ = foo; }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/function_with_non-extern_non-packed_union_parameter.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = union {
2 A: i32,
3 B: f32,
4 C: bool,
5};
6export fn entry(foo: Foo) void { _ = foo; }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'C'
test/compile_errors/stage1/obj/generic_fn_as_parameter_without_comptime_keyword.zig deleted-11
......@@ -1,11 +0,0 @@
1fn f(_: fn (anytype) void) void {}
2fn g(_: anytype) void {}
3export fn entry() void {
4 f(g);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:9: error: parameter of type 'fn(anytype) anytype' must be declared comptime
test/compile_errors/stage1/obj/generic_function_call_assigned_to_incorrect_type.zig deleted-13
......@@ -1,13 +0,0 @@
1pub export fn entry() void {
2 var res: []i32 = undefined;
3 res = myAlloc(i32);
4}
5fn myAlloc(comptime arg: type) anyerror!arg{
6 unreachable;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:18: error: expected type '[]i32', found 'anyerror!i32
test/compile_errors/stage1/obj/generic_function_instance_with_non-constant_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1fn foo(comptime x: i32, y: i32) i32 { return x + y; }
2fn test1(a: i32, b: i32) i32 {
3 return foo(a, b);
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(test1)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:16: error: runtime value cannot be passed to comptime arg
test/compile_errors/stage1/obj/generic_function_returning_opaque_type.zig deleted-25
......@@ -1,25 +0,0 @@
1const FooType = opaque {};
2fn generic(comptime T: type) !T {
3 return undefined;
4}
5export fn bar() void {
6 _ = generic(FooType);
7}
8export fn bav() void {
9 _ = generic(@TypeOf(null));
10}
11export fn baz() void {
12 _ = generic(@TypeOf(undefined));
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:6:16: error: call to generic function with Opaque return type 'FooType' not allowed
20// tmp.zig:2:1: note: function declared here
21// tmp.zig:1:1: note: type declared here
22// tmp.zig:9:16: error: call to generic function with Null return type '@Type(.Null)' not allowed
23// tmp.zig:2:1: note: function declared here
24// tmp.zig:12:16: error: call to generic function with Undefined return type '@Type(.Undefined)' not allowed
25// tmp.zig:2:1: note: function declared here
test/compile_errors/stage1/obj/generic_function_where_return_type_is_self-referenced.zig deleted-15
......@@ -1,15 +0,0 @@
1fn Foo(comptime T: type) Foo(T) {
2 return struct{ x: T };
3}
4export fn entry() void {
5 const t = Foo(u32) {
6 .x = 1
7 };
8 _ = t;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches
test/compile_errors/stage1/obj/global_variable_alignment_non_power_of_2.zig deleted-8
......@@ -1,8 +0,0 @@
1const some_data: [100]u8 align(3) = undefined;
2export fn entry() usize { return @sizeOf(@TypeOf(some_data)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:32: error: alignment value 3 is not a power of 2
test/compile_errors/stage1/obj/global_variable_initializer_must_be_constant_expression.zig deleted-9
......@@ -1,9 +0,0 @@
1extern fn foo() i32;
2const x = foo();
3export fn entry() i32 { return x; }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:11: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/hasDecl_with_non-container.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 _ = @hasDecl(i32, "hi");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'
test/compile_errors/stage1/obj/if_condition_is_bool_not_int.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 if (0) {}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'
test/compile_errors/stage1/obj/ignored_assert-err-ok_return_value.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 bar() catch unreachable;
3}
4fn bar() anyerror!i32 { return 0; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:11: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_comptime_statement_value.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 comptime {1;}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_comptime_value.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 comptime 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_deferred_function_call.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 defer bar();
3}
4fn bar() anyerror!i32 { return 0; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/ignored_deferred_statement_value.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 defer {1;}
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:12: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig deleted-22
......@@ -1,22 +0,0 @@
1export fn a() void {
2 while (true) : (bad()) {}
3}
4export fn b() void {
5 var x: anyerror!i32 = 1234;
6 while (x) |_| : (bad()) {} else |_| {}
7}
8export fn c() void {
9 var x: ?i32 = 1234;
10 while (x) |_| : (bad()) {}
11}
12fn bad() anyerror!void {
13 return error.Bad;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if`
21// tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if`
22// tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if`
test/compile_errors/stage1/obj/ignored_return_value.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 bar();
3}
4fn bar() i32 { return 0; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:8: error: expression value is ignored
test/compile_errors/stage1/obj/ignored_statement_value.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: expression value is ignored
test/compile_errors/stage1/obj/illegal_comparison_of_types.zig deleted-20
......@@ -1,20 +0,0 @@
1fn bad_eql_1(a: []u8, b: []u8) bool {
2 return a == b;
3}
4const EnumWithData = union(enum) {
5 One: void,
6 Two: i32,
7};
8fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
9 return a.* == b.*;
10}
11
12export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
13export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); }
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:14: error: operator not allowed for type '[]u8'
20// tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'
test/compile_errors/stage1/obj/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig deleted-42
......@@ -1,42 +0,0 @@
1export fn a() void {
2 var x: [*c]u8 = undefined;
3 var y: *align(4) u8 = x;
4 _ = y;
5}
6export fn b() void {
7 var x: [*c]const u8 = undefined;
8 var y: *u8 = x;
9 _ = y;
10}
11export fn c() void {
12 var x: [*c]u8 = undefined;
13 var y: *u32 = x;
14 _ = y;
15}
16export fn d() void {
17 var y: *align(1) u32 = undefined;
18 var x: [*c]u32 = y;
19 _ = x;
20}
21export fn e() void {
22 var y: *const u8 = undefined;
23 var x: [*c]u8 = y;
24 _ = x;
25}
26export fn f() void {
27 var y: *u8 = undefined;
28 var x: [*c]u32 = y;
29 _ = x;
30}
31
32// error
33// backend=stage1
34// target=native
35//
36// tmp.zig:3:27: error: cast increases pointer alignment
37// tmp.zig:8:18: error: cast discards const qualifier
38// tmp.zig:13:19: error: expected type '*u32', found '[*c]u8'
39// tmp.zig:13:19: note: pointer type child 'u8' cannot cast into pointer type child 'u32'
40// tmp.zig:18:22: error: cast increases pointer alignment
41// tmp.zig:23:21: error: cast discards const qualifier
42// tmp.zig:28:22: error: expected type '[*c]u32', found '*u8'
test/compile_errors/stage1/obj/implicit_cast_const_array_to_mutable_slice.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 const buffer: [1]u8 = [_]u8{8};
3 const sliceA: []u8 = &buffer;
4 _ = sliceA;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:27: error: cannot cast pointer to array literal to slice type '[]u8'
12// tmp.zig:3:27: note: cast discards const qualifier
test/compile_errors/stage1/obj/implicit_cast_from_array_to_mutable_slice.zig deleted-11
......@@ -1,11 +0,0 @@
1var global_array: [10]i32 = undefined;
2fn foo(param: []i32) void {_ = param;}
3export fn entry() void {
4 foo(global_array);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'
test/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig deleted-10
......@@ -1,10 +0,0 @@
1var x: f64 = 1.0;
2var y: f32 = x;
3
4export fn entry() usize { return @sizeOf(@TypeOf(y)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:14: error: expected type 'f32', found 'f64'
test/compile_errors/stage1/obj/implicit_cast_of_error_set_not_a_subset.zig deleted-16
......@@ -1,16 +0,0 @@
1const Set1 = error{A, B};
2const Set2 = error{A, C};
3export fn entry() void {
4 foo(Set1.B);
5}
6fn foo(set1: Set1) void {
7 var x: Set2 = set1;
8 _ = x;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:19: error: expected type 'Set2', found 'Set1'
16// tmp.zig:1:23: note: 'error.B' not a member of destination error set
test/compile_errors/stage1/obj/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig deleted-26
......@@ -1,26 +0,0 @@
1export fn entry() void {
2 var slice: []const u8 = "aoeu";
3 const opt_many_ptr: [*]const u8 = slice.ptr;
4 var ptr_opt_many_ptr = &opt_many_ptr;
5 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
6 ptr_opt_many_ptr = c_ptr;
7}
8export fn entry2() void {
9 var buf: [4]u8 = "aoeu".*;
10 var slice: []u8 = &buf;
11 var opt_many_ptr: [*]u8 = slice.ptr;
12 var ptr_opt_many_ptr = &opt_many_ptr;
13 var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
14 _ = c_ptr;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
22// tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
23// tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
24// tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
25// tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
26// tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'
test/compile_errors/stage1/obj/implicit_casting_null_c_pointer_to_zig_pointer.zig deleted-11
......@@ -1,11 +0,0 @@
1comptime {
2 var c_ptr: [*c]u8 = 0;
3 var zig_ptr: *u8 = c_ptr;
4 _ = zig_ptr;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:24: error: null pointer casted to type '*u8'
test/compile_errors/stage1/obj/implicit_casting_too_big_integers_to_C_pointers.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn a() void {
2 var ptr: [*c]u8 = (1 << 64) + 1;
3 _ = ptr;
4}
5export fn b() void {
6 var x: u65 = 0x1234;
7 var ptr: [*c]u8 = x;
8 _ = ptr;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'
16// tmp.zig:7:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'
test/compile_errors/stage1/obj/implicit_casting_undefined_c_pointer_to_zig_pointer.zig deleted-11
......@@ -1,11 +0,0 @@
1comptime {
2 var c_ptr: [*c]u8 = undefined;
3 var zig_ptr: *u8 = c_ptr;
4 _ = zig_ptr;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:24: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/implicit_dependency_on_libc.zig deleted-11
......@@ -1,11 +0,0 @@
1extern "c" fn exit(u8) void;
2export fn entry() void {
3 exit(0);
4}
5
6// error
7// backend=stage1
8// target=native-linux
9// is_test=1
10//
11// tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command
test/compile_errors/stage1/obj/implicit_semicolon-block_expr.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = {};
3 var good = {};
4 _ = {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:11: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-block_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 {}
3 var good = {};
4 ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:9: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-comptime_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = comptime {};
3 var good = {};
4 _ = comptime {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:20: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-comptime_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 comptime {}
3 var good = {};
4 comptime ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:18: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-defer.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 defer {}
3 var good = {};
4 defer ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:15: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-for_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = for(foo()) |_| {};
3 var good = {};
4 _ = for(foo()) |_| {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:26: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-for_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 for(foo()) |_| {}
3 var good = {};
4 for(foo()) |_| ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = if(true) {} else if(true) {} else {};
3 var good = {};
4 _ = if(true) {} else if(true) {} else {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:45: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if-else_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 if(true) {} else if(true) {} else {}
3 var good = {};
4 if(true) ({}) else if(true) ({}) else ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:47: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = if(true) {} else if(true) {};
3 var good = {};
4 _ = if(true) {} else if(true) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:37: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else-if_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 if(true) {} else if(true) {}
3 var good = {};
4 if(true) ({}) else if(true) ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:37: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = if(true) {} else {};
3 var good = {};
4 _ = if(true) {} else {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if-else_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 if(true) {} else {}
3 var good = {};
4 if(true) ({}) else ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = if(true) {};
3 var good = {};
4 _ = if(true) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:20: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-if_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 if(true) {}
3 var good = {};
4 if(true) ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-test_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = if (foo()) |_| {};
3 var good = {};
4 _ = if (foo()) |_| {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:26: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-test_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 if (foo()) |_| {}
3 var good = {};
4 if (foo()) |_| ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:24: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while-continue_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = while(true):({}) {};
3 var good = {};
4 _ = while(true):({}) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:28: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while-continue_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 while(true):({}) {}
3 var good = {};
4 while(true):({}) ({})
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:26: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while_expression.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = while(true) {};
3 var good = {};
4 _ = while(true) {}
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:23: error: expected ';' after statement
test/compile_errors/stage1/obj/implicit_semicolon-while_statement.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 while(true) {}
3 var good = {};
4 while(true) 1
5 var bad = {};
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:18: error: expected ';' or 'else' after statement
test/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig deleted-17
......@@ -1,17 +0,0 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export fn entry() void {
9 var x: u2 = Small.Two;
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:22: error: expected type 'u2', found 'Small'
test/compile_errors/stage1/obj/implicitly_increasing_pointer_alignment.zig deleted-19
......@@ -1,19 +0,0 @@
1const Foo = packed struct {
2 a: u8,
3 b: u32,
4};
5
6export fn entry() void {
7 var foo = Foo { .a = 1, .b = 10 };
8 bar(&foo.b);
9}
10
11fn bar(x: *u32) void {
12 x.* += 1;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'
test/compile_errors/stage1/obj/implicitly_increasing_slice_alignment.zig deleted-22
......@@ -1,22 +0,0 @@
1const Foo = packed struct {
2 a: u8,
3 b: u32,
4};
5
6export fn entry() void {
7 var foo = Foo { .a = 1, .b = 10 };
8 foo.b += 1;
9 bar(@as(*[1]u32, &foo.b)[0..]);
10}
11
12fn bar(x: []u32) void {
13 x[0] += 1;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:9:26: error: cast increases pointer alignment
21// tmp.zig:9:26: note: '*align(1) u32' has alignment 1
22// tmp.zig:9:26: note: '*[1]u32' has alignment 4
test/compile_errors/stage1/obj/import_outside_package_path.zig deleted-9
......@@ -1,9 +0,0 @@
1comptime{
2 _ = @import("../a.zig");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: import of file outside package path: '../a.zig'
test/compile_errors/stage1/obj/incompatible_sentinels.zig deleted-29
......@@ -1,29 +0,0 @@
1// Note: One of the error messages here is backwards. It would be nice to fix, but that's not
2// going to stop me from merging this branch which fixes a bunch of other stuff.
3export fn entry1(ptr: [*:255]u8) [*:0]u8 {
4 return ptr;
5}
6export fn entry2(ptr: [*]u8) [*:0]u8 {
7 return ptr;
8}
9export fn entry3() void {
10 var array: [2:0]u8 = [_:255]u8{ 1, 2 };
11 _ = array;
12}
13export fn entry4() void {
14 var array: [2:0]u8 = [_]u8{ 1, 2 };
15 _ = array;
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:4:12: error: expected type '[*:0]u8', found '[*:255]u8'
23// tmp.zig:4:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel
24// tmp.zig:7:12: error: expected type '[*:0]u8', found '[*]u8'
25// tmp.zig:7:12: note: destination pointer requires a terminating '0' sentinel
26// tmp.zig:10:35: error: expected type '[2:255]u8', found '[2:0]u8'
27// tmp.zig:10:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel
28// tmp.zig:14:31: error: expected type '[2:0]u8', found '[2]u8'
29// tmp.zig:14:31: note: destination array requires a terminating '0' sentinel
test/compile_errors/stage1/obj/incorrect_return_type.zig deleted-21
......@@ -1,21 +0,0 @@
1 pub export fn entry() void{
2 _ = foo();
3 }
4 const A = struct {
5 a: u32,
6 };
7 fn foo() A {
8 return bar();
9 }
10 const B = struct {
11 a: u32,
12 };
13 fn bar() B {
14 unreachable;
15 }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:8:16: error: expected type 'A', found 'B'
test/compile_errors/stage1/obj/increase_pointer_alignment_in_ptrCast.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() u32 {
2 var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
3 const ptr = @ptrCast(*u32, &bytes[0]);
4 return ptr.*;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:17: error: cast increases pointer alignment
12// tmp.zig:3:38: note: '*u8' has alignment 1
13// tmp.zig:3:26: note: '*u32' has alignment 4
test/compile_errors/stage1/obj/indexing_a_undefined_slice_at_comptime.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var slice: []u8 = undefined;
3 slice[0] = 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: index 0 outside slice of size 0
test/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig deleted-11
......@@ -1,11 +0,0 @@
1const array = [_]u8{};
2export fn foo() void {
3 const pointer = &array[0];
4 _ = pointer;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:27: error: accessing a zero length array is not allowed
test/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig deleted-12
......@@ -1,12 +0,0 @@
1const array = [_]u8{};
2export fn foo() void {
3 var index: usize = 0;
4 const pointer = &array[index];
5 _ = pointer;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:27: error: accessing a zero length array is not allowed
test/compile_errors/stage1/obj/indexing_single-item_pointer.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(ptr: *i32) i32 {
2 return ptr[1];
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: index of single-item pointer
test/compile_errors/stage1/obj/indirect_recursion_of_async_functions_detected.zig deleted-36
......@@ -1,36 +0,0 @@
1var frame: ?anyframe = null;
2
3export fn a() void {
4 _ = async rangeSum(10);
5 while (frame) |f| resume f;
6}
7
8fn rangeSum(x: i32) i32 {
9 suspend {
10 frame = @frame();
11 }
12 frame = null;
13
14 if (x == 0) return 0;
15 var child = rangeSumIndirect(x - 1);
16 return child + 1;
17}
18
19fn rangeSumIndirect(x: i32) i32 {
20 suspend {
21 frame = @frame();
22 }
23 frame = null;
24
25 if (x == 0) return 0;
26 var child = rangeSum(x - 1);
27 return child + 1;
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
35// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here
36// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/compile_errors/stage1/obj/indirect_struct_loop.zig deleted-10
......@@ -1,10 +0,0 @@
1const A = struct { b : B, };
2const B = struct { c : C, };
3const C = struct { a : A, };
4export fn entry() usize { return @sizeOf(A); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:11: error: struct 'A' depends on itself
test/compile_errors/stage1/obj/inferred_array_size_invalid_here.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 const x = [_]u8;
3 _ = x;
4}
5export fn entry2() void {
6 const S = struct { a: *const [_]u8 };
7 var a = .{ S{} };
8 _ = a;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:16: error: unable to infer array size
16// tmp.zig:6:35: error: unable to infer array size
test/compile_errors/stage1/obj/inferring_error_set_of_function_pointer.zig deleted-9
......@@ -1,9 +0,0 @@
1comptime {
2 const z: ?fn()!void = null;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:19: error: function prototype may not have inferred error set
test/compile_errors/stage1/obj/initializing_array_with_struct_syntax.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = [_]u8{ .y = 2 };
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: initializing array with struct syntax
test/compile_errors/stage1/obj/instantiating_an_undefined_value_for_an_invalid_struct_that_contains_itself.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = struct {
2 x: Foo,
3};
4
5var foo: Foo = undefined;
6
7export fn entry() usize {
8 return @sizeOf(@TypeOf(foo.x));
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:13: error: struct 'Foo' depends on itself
test/compile_errors/stage1/obj/intToPtr_with_misaligned_address.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 var y = @intToPtr([*]align(4) u8, 5);
3 _ = y;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:13: error: pointer type '[*]align(4) u8' requires aligned address
test/compile_errors/stage1/obj/int_to_err_global_invalid_number.zig deleted-15
......@@ -1,15 +0,0 @@
1const Set1 = error{
2 A,
3 B,
4};
5comptime {
6 var x: u16 = 3;
7 var y = @intToError(x);
8 _ = y;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:13: error: integer value 3 represents no error
test/compile_errors/stage1/obj/int_to_err_non_global_invalid_number.zig deleted-19
......@@ -1,19 +0,0 @@
1const Set1 = error{
2 A,
3 B,
4};
5const Set2 = error{
6 A,
7 C,
8};
9comptime {
10 var x = @errorToInt(Set1.B);
11 var y = @errSetCast(Set2, @intToError(x));
12 _ = y;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:11:13: error: error.B not a member of error set 'Set2'
test/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn foo() void {
2 var x: usize = 0x1000;
3 var y: *void = @intToPtr(*void, x);
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information
test/compile_errors/stage1/obj/integer_cast_truncates_bits.zig deleted-31
......@@ -1,31 +0,0 @@
1export fn entry1() void {
2 const spartan_count: u16 = 300;
3 const byte = @intCast(u8, spartan_count);
4 _ = byte;
5}
6export fn entry2() void {
7 const spartan_count: u16 = 300;
8 const byte: u8 = spartan_count;
9 _ = byte;
10}
11export fn entry3() void {
12 var spartan_count: u16 = 300;
13 var byte: u8 = spartan_count;
14 _ = byte;
15}
16export fn entry4() void {
17 var signed: i8 = -1;
18 var unsigned: u64 = signed;
19 _ = unsigned;
20}
21
22// error
23// backend=stage1
24// target=native
25//
26// tmp.zig:3:18: error: cast from 'u16' to 'u8' truncates bits
27// tmp.zig:8:22: error: integer value 300 cannot be coerced to type 'u8'
28// tmp.zig:13:20: error: expected type 'u8', found 'u16'
29// tmp.zig:13:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values
30// tmp.zig:18:25: error: expected type 'u64', found 'i8'
31// tmp.zig:18:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
test/compile_errors/stage1/obj/integer_overflow_error.zig deleted-8
......@@ -1,8 +0,0 @@
1const x : u8 = 300;
2export fn entry() usize { return @sizeOf(@TypeOf(x)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/integer_underflow_error.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 _ = @intToPtr(*anyopaque, ~@as(usize, @import("std").math.maxInt(usize)) - 1);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// :2:78: error: operation caused overflow
test/compile_errors/stage1/obj/invalid_break_expression.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 break;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: break expression outside loop
test/compile_errors/stage1/obj/invalid_builtin_fn.zig deleted-9
......@@ -1,9 +0,0 @@
1fn f() @bogus(foo) {
2}
3export fn entry() void { _ = f(); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:8: error: invalid builtin function: '@bogus'
test/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig deleted-17
......@@ -1,17 +0,0 @@
1const E = enum(usize) { One, Two };
2
3export fn entry() void {
4 foo(1);
5}
6
7fn foo(x: usize) void {
8 switch (x) {
9 E.One => {},
10 }
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:10: error: expected type 'usize', found 'E'
test/compile_errors/stage1/obj/invalid_comparison_for_function_pointers.zig deleted-10
......@@ -1,10 +0,0 @@
1fn foo() void {}
2const invalid = foo > foo;
3
4export fn entry() usize { return @sizeOf(@TypeOf(invalid)); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: operator not allowed for type 'fn() void'
test/compile_errors/stage1/obj/invalid_continue_expression.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 continue;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: continue expression outside loop
test/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig deleted-17
......@@ -1,17 +0,0 @@
1comptime {
2 var tile = Tile.Empty;
3 switch (tile.*) {
4 Tile.Empty => {},
5 Tile.Filled => {},
6 }
7}
8const Tile = enum {
9 Empty,
10 Filled,
11};
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'
test/compile_errors/stage1/obj/invalid_empty_unicode_escape.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 const a = '\u{}';
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:19: error: empty unicode escape sequence
test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-1.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0x1.0p1ab1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: 'a'
test/compile_errors/stage1/obj/invalid_exponent_in_float_literal-2.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0x1.0p50F;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:29: note: invalid byte: 'F'
test/compile_errors/stage1/obj/invalid_field_access_in_comptime.zig deleted-7
......@@ -1,7 +0,0 @@
1comptime { var x = doesnt_exist.whatever; _ = x; }
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'
test/compile_errors/stage1/obj/invalid_field_in_struct_value_expression.zig deleted-19
......@@ -1,19 +0,0 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 const a = A {
8 .z = 4,
9 .y = 2,
10 .foo = 42,
11 };
12 _ = a;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:10:9: error: no member named 'foo' in struct 'A'
test/compile_errors/stage1/obj/invalid_float_literal.zig deleted-13
......@@ -1,13 +0,0 @@
1const std = @import("std");
2
3pub fn main() void {
4 var bad_float :f32 = 0.0;
5 bad_float = bad_float + .20;
6 std.debug.assert(bad_float < 1.0);
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:29: error: expected expression, found '.'
test/compile_errors/stage1/obj/invalid_legacy_unicode_escape.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const a = '\U1234';
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expected expression, found 'invalid bytes'
10// tmp.zig:2:18: note: invalid byte: '1'
test/compile_errors/stage1/obj/invalid_maybe_type.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 if (true) |x| { _ = x; }
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: expected optional type, found 'bool'
test/compile_errors/stage1/obj/invalid_member_of_builtin_enum.zig deleted-11
......@@ -1,11 +0,0 @@
1const builtin = @import("std").builtin;
2export fn entry() void {
3 const foo = builtin.Mode.x86;
4 _ = foo;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'
test/compile_errors/stage1/obj/invalid_multiple_dereferences.zig deleted-19
......@@ -1,19 +0,0 @@
1export fn a() void {
2 var box = Box{ .field = 0 };
3 box.*.field = 1;
4}
5export fn b() void {
6 var box = Box{ .field = 0 };
7 var boxPtr = &box;
8 boxPtr.*.*.field = 1;
9}
10pub const Box = struct {
11 field: i32,
12};
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'
19// tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'
test/compile_errors/stage1/obj/invalid_optional_type_in_extern_struct.zig deleted-10
......@@ -1,10 +0,0 @@
1const stroo = extern struct {
2 moo: ?[*c]u8,
3};
4export fn testf(fluff: *stroo) void { _ = fluff; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'
test/compile_errors/stage1/obj/invalid_pointer_for_var_type.zig deleted-13
......@@ -1,13 +0,0 @@
1extern fn ext() usize;
2var bytes: [ext()]u8 = undefined;
3export fn f() void {
4 for (bytes) |*b, i| {
5 b.* = @as(u8, i);
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:13: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/invalid_pointer_syntax.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo() void {
2 var guid: *:0 const u8 = undefined;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:16: error: expected type expression, found ':'
test/compile_errors/stage1/obj/invalid_shift_amount_error.zig deleted-11
......@@ -1,11 +0,0 @@
1const x : u8 = 2;
2fn f() u16 {
3 return x << 8;
4}
5export fn entry() u16 { return f(); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:17: error: integer value 8 cannot be coerced to type 'u3'
test/compile_errors/stage1/obj/invalid_struct_field.zig deleted-19
......@@ -1,19 +0,0 @@
1const A = struct { x : i32, };
2export fn f() void {
3 var a : A = undefined;
4 a.foo = 1;
5 const y = a.bar;
6 _ = y;
7}
8export fn g() void {
9 var a : A = undefined;
10 const y = a.bar;
11 _ = y;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:4:6: error: no member named 'foo' in struct 'A'
19// tmp.zig:10:16: error: no member named 'bar' in struct 'A'
test/compile_errors/stage1/obj/invalid_suspend_in_exported_function.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 var frame = async func();
3 var result = await frame;
4 _ = result;
5}
6fn func() void {
7 suspend {}
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:1:1: error: function with calling convention 'C' cannot be async
15// tmp.zig:3:18: note: await here is a suspend point
test/compile_errors/stage1/obj/invalid_type.zig deleted-8
......@@ -1,8 +0,0 @@
1fn a() bogus {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:8: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/invalid_type_used_in_array_type.zig deleted-14
......@@ -1,14 +0,0 @@
1const Item = struct {
2 field: SomeNonexistentType,
3};
4var items: [100]Item = undefined;
5export fn entry() void {
6 const a = items[0];
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-1.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0._0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-10.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1.0__0e-1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:25: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-11.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1.0e-1__0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-12.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0_x0.0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: 'x'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-13.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0x_0.0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-14.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0x0.0_p1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:27: note: invalid byte: 'p'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-2.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0_.0;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '.'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-3.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 0.0_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:25: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-4.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1.0e_1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:25: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-5.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1.0e+_1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:26: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-6.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1.0e-_1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:26: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-7.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1.0e-1_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_float_literal-9.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: f128 = 1__0.0e-1;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:23: note: invalid byte: '_'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-1.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: u128 = 0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:26: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-2.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: u128 = 0b0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-3.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: u128 = 0o0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_underscore_placement_in_int_literal-4.zig deleted-11
......@@ -1,11 +0,0 @@
1fn main() void {
2 var bad: u128 = 0x0010_;
3 _ = bad;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: expected expression, found 'invalid bytes'
11// tmp.zig:2:28: note: invalid byte: ';'
test/compile_errors/stage1/obj/invalid_union_field_access_in_comptime.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = union {
2 Bar: u8,
3 Baz: void,
4};
5comptime {
6 var foo = Foo {.Baz = {}};
7 const bar_val = foo.Bar;
8 _ = bar_val;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set
test/compile_errors/stage1/obj/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var foo: u32 = @This(){};
3 _ = foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:27: error: type 'u32' does not support array initialization
test/compile_errors/stage1/obj/issue_2687_coerce_from_undefined_array_pointer_to_slice.zig deleted-27
......@@ -1,27 +0,0 @@
1export fn foo1() void {
2 const a: *[1]u8 = undefined;
3 var b: []u8 = a;
4 _ = b;
5}
6export fn foo2() void {
7 comptime {
8 var a: *[1]u8 = undefined;
9 var b: []u8 = a;
10 _ = b;
11 }
12}
13export fn foo3() void {
14 comptime {
15 const a: *[1]u8 = undefined;
16 var b: []u8 = a;
17 _ = b;
18 }
19}
20
21// error
22// backend=stage1
23// target=native
24//
25// tmp.zig:3:19: error: use of undefined value here causes undefined behavior
26// tmp.zig:9:23: error: use of undefined value here causes undefined behavior
27// tmp.zig:16:23: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/issue_3818_bitcast_from_parray-slice_to_u16.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn foo1() void {
2 var bytes = [_]u8{1, 2};
3 const word: u16 = @bitCast(u16, bytes[0..]);
4 _ = word;
5}
6export fn foo2() void {
7 var bytes: []const u8 = &[_]u8{1, 2};
8 const word: u16 = @bitCast(u16, bytes);
9 _ = word;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'
17// tmp.zig:8:32: error: destination type 'u16' has size 2 but source type '[]const u8' has size 16
test/compile_errors/stage1/obj/issue_4207_coerce_from_non-terminated-slice_to_terminated-pointer.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn foo() [*:0]const u8 {
2 var buffer: [64]u8 = undefined;
3 return buffer[0..];
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// :3:18: error: expected type '[*:0]const u8', found '*[64]u8'
11// :3:18: note: destination pointer requires a terminating '0' sentinel
test/compile_errors/stage1/obj/issue_5221_invalid_struct_init_type_referenced_by_typeInfo_and_passed_into_function.zig deleted-16
......@@ -1,16 +0,0 @@
1fn ignore(comptime param: anytype) void {_ = param;}
2
3export fn foo() void {
4 const MyStruct = struct {
5 wrong_type: []u8 = "foo",
6 };
7
8 comptime ignore(@typeInfo(MyStruct).Struct.fields[0]);
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// :5:28: error: cannot cast pointer to array literal to slice type '[]u8'
16// :5:28: note: cast discards const qualifier
test/compile_errors/stage1/obj/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn foo() void {
2 var u: ?*anyopaque = null;
3 var v: *anyopaque = undefined;
4 v = u;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:9: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type '*anyopaque', found '?*anyopaque'
test/compile_errors/stage1/obj/issue_7810-comptime_slice-len_increment_beyond_bounds.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn foo_slice_len_increment_beyond_bounds() void {
2 comptime {
3 var buf_storage: [8]u8 = undefined;
4 var buf: []const u8 = buf_storage[0..];
5 buf.len += 1;
6 buf[8] = 42;
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// :6:12: error: out of bounds slice
test/compile_errors/stage1/obj/issue_9346_return_outside_of_function_scope.zig deleted-7
......@@ -1,7 +0,0 @@
1pub const empty = return 1;
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:19: error: 'return' outside function scope
test/compile_errors/stage1/obj/labeled_break_not_found.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 blah: while (true) {
3 while (true) {
4 break :outer;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:20: error: label not found: 'outer'
test/compile_errors/stage1/obj/labeled_continue_not_found.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 var i: usize = 0;
3 blah: while (i < 10) : (i += 1) {
4 while (true) {
5 continue :outer;
6 }
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:23: error: label not found: 'outer'
test/compile_errors/stage1/obj/lazy_pointer_with_undefined_element_type.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn foo() void {
2 comptime var T: type = undefined;
3 const S = struct { x: *T };
4 const I = @typeInfo(S);
5 _ = I;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// :3:28: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/libc_headers_note.zig deleted-12
......@@ -1,12 +0,0 @@
1const c = @cImport(@cInclude("stdio.h"));
2export fn entry() void {
3 _ = c.printf("hello, world!\n");
4}
5
6// error
7// backend=stage1
8// is_test=1
9// target=native-linux
10//
11// tmp.zig:1:11: error: C import failed
12// tmp.zig:1:11: note: libc headers not available; compilation does not link against libc
test/compile_errors/stage1/obj/load_too_many_bytes_from_comptime_reinterpreted_pointer.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 const float: f32 = 5.99999999999994648725e-01;
3 const float_ptr = &float;
4 const int_ptr = @ptrCast(*const i64, float_ptr);
5 const int_val = int_ptr.*;
6 _ = int_val;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes
test/compile_errors/stage1/obj/load_vector_pointer_with_unknown_runtime_index.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn entry() void {
2 var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
3
4 var i: u32 = 0;
5 var x = loadv(&v[i]);
6 _ = x;
7}
8
9fn loadv(ptr: anytype) i32 {
10 return ptr.*;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:10:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/compile_errors/stage1/obj/local_shadows_global_that_occurs_later.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 var foo = true;
3 _ = foo;
4}
5fn foo() void {}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:9: error: local shadows declaration of 'foo'
12// tmp.zig:5:1: note: declared here
test/compile_errors/stage1/obj/local_variable_redeclaration.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn f() void {
2 const a : i32 = 0;
3 var a = 0;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: redeclaration of local constant 'a'
11// tmp.zig:2:11: note: previous declaration here
test/compile_errors/stage1/obj/local_variable_redeclares_parameter.zig deleted-11
......@@ -1,11 +0,0 @@
1fn f(a : i32) void {
2 const a = 0;
3}
4export fn entry() void { f(1); }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:11: error: redeclaration of function parameter 'a'
11// tmp.zig:1:6: note: previous declaration here
test/compile_errors/stage1/obj/local_variable_shadowing_global.zig deleted-14
......@@ -1,14 +0,0 @@
1const Foo = struct {};
2const Bar = struct {};
3
4export fn entry() void {
5 var Bar : i32 = undefined;
6 _ = Bar;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:9: error: local shadows declaration of 'Bar'
14// tmp.zig:2:1: note: declared here
test/compile_errors/stage1/obj/locally_shadowing_a_primitive_type.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn foo() void {
2 const u8 = u16;
3 const a: u8 = 300;
4 _ = a;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:11: error: name shadows primitive 'u8'
12// tmp.zig:2:11: note: consider using @"u8" to disambiguate
test/compile_errors/stage1/obj/main_function_with_bogus_args_type.zig deleted-7
......@@ -1,7 +0,0 @@
1pub fn main(args: [][]bogus) !void {_ = args;}
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:23: error: use of undeclared identifier 'bogus'
test/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig deleted-21
......@@ -1,21 +0,0 @@
1const Foo = struct {
2 x: i32,
3
4 fn init(x: i32) Foo {
5 return Foo {
6 .x = x,
7 };
8 }
9};
10
11export fn f() void {
12 const derp = Foo.init(3);
13
14 derp.init();
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:14:5: error: expected type 'i32', found 'Foo'
test/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig deleted-30
......@@ -1,30 +0,0 @@
1pub const List = struct {
2 len: usize,
3 allocator: *Allocator,
4
5 pub fn init(allocator: *Allocator) List {
6 return List {
7 .len = 0,
8 .allocator = allocator,
9 };
10 }
11};
12
13pub var global_allocator = Allocator {
14 .field = 1234,
15};
16
17pub const Allocator = struct {
18 field: i32,
19};
20
21export fn foo() void {
22 var x = List.init(&global_allocator);
23 x.init();
24}
25
26// error
27// backend=stage1
28// target=native
29//
30// tmp.zig:23:5: error: expected type '*Allocator', found '*List'
test/compile_errors/stage1/obj/missing_boolean_switch_value.zig deleted-19
......@@ -1,19 +0,0 @@
1comptime {
2 const x = switch (true) {
3 true => false,
4 };
5 _ = x;
6}
7comptime {
8 const x = switch (true) {
9 false => true,
10 };
11 _ = x;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:2:15: error: switch must handle all possibilities
19// tmp.zig:8:15: error: switch must handle all possibilities
test/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig deleted-18
......@@ -1,18 +0,0 @@
1const Geo3DTex2D = struct { vertices: [][2]f32 };
2pub fn getGeo3DTex2D() Geo3DTex2D {
3 return Geo3DTex2D{
4 .vertices = [_][2]f32{
5 [_]f32{ -0.5, -0.5},
6 },
7 };
8}
9export fn entry() void {
10 var geo_data = getGeo3DTex2D();
11 _ = geo_data;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32'
test/compile_errors/stage1/obj/missing_else_clause.zig deleted-16
......@@ -1,16 +0,0 @@
1fn f(b: bool) void {
2 const x : i32 = if (b) h: { break :h 1; };
3 _ = x;
4}
5fn g(b: bool) void {
6 const y = if (b) h: { break :h @as(i32, 1); };
7 _ = y;
8}
9export fn entry() void { f(true); g(true); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:2:21: error: expected type 'i32', found 'void'
16// tmp.zig:6:15: error: incompatible types: 'i32' and 'void'
test/compile_errors/stage1/obj/missing_field_in_struct_value_expression.zig deleted-20
......@@ -1,20 +0,0 @@
1const A = struct {
2 x : i32,
3 y : i32,
4 z : i32,
5};
6export fn f() void {
7 // we want the error on the '{' not the 'A' because
8 // the A could be a complicated expression
9 const a = A {
10 .z = 4,
11 .y = 2,
12 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:9:17: error: missing field: 'x'
test/compile_errors/stage1/obj/missing_function_call_param.zig deleted-31
......@@ -1,31 +0,0 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4
5 fn member_a(foo: *const Foo) i32 {
6 return foo.a;
7 }
8 fn member_b(foo: *const Foo) i32 {
9 return foo.b;
10 }
11};
12
13const member_fn_type = @TypeOf(Foo.member_a);
14const members = [_]member_fn_type {
15 Foo.member_a,
16 Foo.member_b,
17};
18
19fn f(foo: *const Foo, index: usize) void {
20 const result = members[index]();
21 _ = foo;
22 _ = result;
23}
24
25export fn entry() usize { return @sizeOf(@TypeOf(f)); }
26
27// error
28// backend=stage1
29// target=native
30//
31// tmp.zig:20:34: error: expected 1 argument(s), found 0
test/compile_errors/stage1/obj/missing_function_name.zig deleted-8
......@@ -1,8 +0,0 @@
1fn () void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:1: error: missing function name
test/compile_errors/stage1/obj/missing_param_name.zig deleted-8
......@@ -1,8 +0,0 @@
1fn f(i32) void {}
2export fn entry() usize { return @sizeOf(@TypeOf(f)); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:6: error: missing parameter name
test/compile_errors/stage1/obj/missing_parameter_name_of_generic_function.zig deleted-11
......@@ -1,11 +0,0 @@
1fn dump(anytype) void {}
2export fn entry() void {
3 var a: u8 = 9;
4 dump(a);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:9: error: missing parameter name
test/compile_errors/stage1/obj/missing_result_type_for_phi_node.zig deleted-12
......@@ -1,12 +0,0 @@
1fn foo() !void {
2 return anyerror.Foo;
3}
4export fn entry() void {
5 foo() catch 0;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'
test/compile_errors/stage1/obj/misspelled_type_with_pointer_only_reference.zig deleted-37
......@@ -1,37 +0,0 @@
1const JasonHM = u8;
2const JasonList = *JsonNode;
3
4const JsonOA = union(enum) {
5 JSONArray: JsonList,
6 JSONObject: JasonHM,
7};
8
9const JsonType = union(enum) {
10 JSONNull: void,
11 JSONInteger: isize,
12 JSONDouble: f64,
13 JSONBool: bool,
14 JSONString: []u8,
15 JSONArray: void,
16 JSONObject: void,
17};
18
19pub const JsonNode = struct {
20 kind: JsonType,
21 jobject: ?JsonOA,
22};
23
24fn foo() void {
25 var jll: JasonList = undefined;
26 jll.init(1234);
27 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
28 _ = jd;
29}
30
31export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
32
33// error
34// backend=stage1
35// target=native
36//
37// tmp.zig:5:16: error: use of undeclared identifier 'JsonList'
test/compile_errors/stage1/obj/mod_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a %= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mod_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a % a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig deleted-12
......@@ -1,12 +0,0 @@
1const y = mul(300, 6000);
2fn mul(a: u16, b: u16) u16 {
3 return a * b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/mult_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a *= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a * a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_wrap_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a *%= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/mult_wrap_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a *% a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/multiple_function_definitions.zig deleted-10
......@@ -1,10 +0,0 @@
1fn a() void {}
2fn a() void {}
3export fn entry() void { a(); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:1: error: redeclaration of 'a'
10// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/negate_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = -a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:10: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/negate_wrap_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = -%a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig deleted-12
......@@ -1,12 +0,0 @@
1const y = neg(-128);
2fn neg(x: i8) i8 {
3 return -x;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:12: error: negation caused overflow
test/compile_errors/stage1/obj/nested_error_set_mismatch.zig deleted-20
......@@ -1,20 +0,0 @@
1const NextError = error{NextError};
2const OtherError = error{OutOfMemory};
3
4export fn entry() void {
5 const a: ?NextError!i32 = foo();
6 _ = a;
7}
8
9fn foo() ?OtherError!i32 {
10 return null;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'
18// tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'
19// tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'
20// tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set
test/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 foo(error.A);
3}
4fn foo(a: anyerror) void {
5 switch (a) {
6 error.A => {},
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:5: error: else prong required when switching on type 'anyerror'
test/compile_errors/stage1/obj/noalias_on_non_pointer_param.zig deleted-8
......@@ -1,8 +0,0 @@
1fn f(noalias x: i32) void { _ = x; }
2export fn entry() void { f(1234); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:6: error: noalias on non-pointer parameter
test/compile_errors/stage1/obj/non-async_function_pointer_eventually_is_inferred_to_become_async.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn a() void {
2 var non_async_fn: fn () void = undefined;
3 non_async_fn = func;
4}
5fn func() void {
6 suspend {}
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:1: error: 'func' cannot be async
14// tmp.zig:3:20: note: required to be non-async here
15// tmp.zig:6:5: note: suspends here
test/compile_errors/stage1/obj/non-const_expression_function_call_with_struct_return_value_outside_function.zig deleted-17
......@@ -1,17 +0,0 @@
1const Foo = struct {
2 x: i32,
3};
4const a = get_it();
5fn get_it() Foo {
6 global_side_effect = true;
7 return Foo {.x = 13};
8}
9var global_side_effect = false;
10
11export fn entry() usize { return @sizeOf(@TypeOf(a)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:26: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non-const_expression_in_struct_literal_outside_function.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = struct {
2 x: i32,
3};
4const a = Foo {.x = get_it()};
5extern fn get_it() i32;
6
7export fn entry() usize { return @sizeOf(@TypeOf(a)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:21: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non-const_switch_number_literal.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn foo() void {
2 const x = switch (bar()) {
3 1, 2 => 1,
4 3, 4 => 2,
5 else => 3,
6 };
7 _ = x;
8}
9fn bar() i32 {
10 return 2;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'
test/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig deleted-51
......@@ -1,51 +0,0 @@
1export fn entry1() void {
2 var m2 = &2;
3 _ = m2;
4}
5export fn entry2() void {
6 var a = undefined;
7 _ = a;
8}
9export fn entry3() void {
10 var b = 1;
11 _ = b;
12}
13export fn entry4() void {
14 var c = 1.0;
15 _ = c;
16}
17export fn entry5() void {
18 var d = null;
19 _ = d;
20}
21export fn entry6(opaque_: *Opaque) void {
22 var e = opaque_.*;
23 _ = e;
24}
25export fn entry7() void {
26 var f = i32;
27 _ = f;
28}
29export fn entry8() void {
30 var h = (Foo {}).bar;
31 _ = h;
32}
33const Opaque = opaque {};
34const Foo = struct {
35 fn bar(self: *const Foo) void {_ = self;}
36};
37
38// error
39// backend=stage1
40// target=native
41//
42// tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime
43// tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime
44// tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime
45// tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
46// tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime
47// tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type
48// tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime
49// tmp.zig:22:4: error: variable of type 'Opaque' not allowed
50// tmp.zig:26:4: error: variable of type 'type' must be const or comptime
51// tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime
test/compile_errors/stage1/obj/non-enum_tag_type_passed_to_union.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = union(u32) {
2 A: i32,
3};
4export fn entry() void {
5 const x = @typeInfo(Foo).Union.tag_type.?;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:19: error: expected enum tag type, found 'u32'
test/compile_errors/stage1/obj/non-extern_function_with_var_args.zig deleted-10
......@@ -1,10 +0,0 @@
1fn foo(args: ...) void {}
2export fn entry() void {
3 foo();
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:14: error: expected type expression, found '...'
test/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig deleted-14
......@@ -1,14 +0,0 @@
1const Foo = struct {
2 name: []const u8,
3 T: type,
4};
5export fn entry() void {
6 const xx: [2]Foo = undefined;
7 for (xx) |f| { _ = f;}
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known
test/compile_errors/stage1/obj/non-integer_tag_type_to_automatic_union_enum.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = union(enum(f32)) {
2 A: i32,
3};
4export fn entry() void {
5 const x = @typeInfo(Foo).Union.tag_type.?;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:24: error: expected integer tag type, found 'f32'
test/compile_errors/stage1/obj/non-pure_function_returns_type.zig deleted-24
......@@ -1,24 +0,0 @@
1var a: u32 = 0;
2pub fn List(comptime T: type) type {
3 a += 1;
4 return SmallList(T, 8);
5}
6
7pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) type {
8 return struct {
9 items: []T,
10 length: usize,
11 prealloc_items: [STATIC_SIZE]T,
12 };
13}
14
15export fn function_with_return_type_type() void {
16 var list: List(i32) = undefined;
17 list.length = 10;
18}
19
20// error
21// backend=stage1
22// target=native
23//
24// tmp.zig:3:7: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non_async_function_pointer_passed_to_asyncCall.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var ptr = afunc;
3 var bytes: [100]u8 align(16) = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});
5}
6fn afunc() void { }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:32: error: expected async function, found 'fn() void'
test/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig deleted-11
......@@ -1,11 +0,0 @@
1fn f() []u8 {
2 return s ++ "foo";
3}
4var s: [10]u8 = undefined;
5export fn entry() usize { return @sizeOf(@TypeOf(f)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:12: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig deleted-14
......@@ -1,14 +0,0 @@
1const Foo = struct {
2 y: [get()]u8,
3};
4var global_var: usize = 1;
5fn get() usize { return global_var; }
6
7export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:25: error: cannot store runtime value in compile time variable
14// tmp.zig:2:12: note: called from here
test/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn foo() void {
2 const Errors = u8 || u16;
3 _ = Errors;
4}
5export fn bar() void {
6 const Errors = error{} || u16;
7 _ = Errors;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:20: error: expected error set type, found type 'u8'
15// tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR
16// tmp.zig:6:31: error: expected error set type, found type 'u16'
17// tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR
test/compile_errors/stage1/obj/non_float_passed_to_floatToInt.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = @floatToInt(i32, @as(i32, 54));
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:32: error: expected float type, found 'i32'
test/compile_errors/stage1/obj/non_int_passed_to_intToFloat.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = @intToFloat(f32, 1.1);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:32: error: expected int type, found 'comptime_float'
test/compile_errors/stage1/obj/non_pointer_given_to_ptrToInt.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(x: i32) usize {
2 return @ptrToInt(x);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: expected pointer, found 'i32'
test/compile_errors/stage1/obj/normal_string_with_newline.zig deleted-9
......@@ -1,9 +0,0 @@
1const foo = "a
2b";
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:13: error: expected expression, found 'invalid bytes'
9// tmp.zig:1:15: note: invalid byte: '\n'
test/compile_errors/stage1/obj/offsetOf-bad_field_name.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = struct {
2 derp: i32,
3};
4export fn foo() usize {
5 return @offsetOf(Foo, "a",);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:27: error: struct 'Foo' has no field 'a'
test/compile_errors/stage1/obj/offsetOf-non_struct.zig deleted-10
......@@ -1,10 +0,0 @@
1const Foo = i32;
2export fn foo() usize {
3 return @offsetOf(Foo, "a",);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:22: error: expected struct type, found 'i32'
test/compile_errors/stage1/obj/only_equality_binary_operator_allowed_for_error_sets.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 const z = error.A > error.B;
3 _ = z;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:23: error: operator not allowed for errors
test/compile_errors/stage1/obj/opaque_type_with_field.zig deleted-11
......@@ -1,11 +0,0 @@
1const Opaque = opaque { foo: i32 };
2export fn entry() void {
3 const foo: ?*Opaque = null;
4 _ = foo;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:25: error: opaque types cannot have fields
test/compile_errors/stage1/obj/optional_pointer_to_void_in_extern_struct.zig deleted-14
......@@ -1,14 +0,0 @@
1const Foo = extern struct {
2 x: ?*const void,
3};
4const Bar = extern struct {
5 foo: Foo,
6 y: i32,
7};
8export fn entry(bar: *Bar) void {_ = bar;}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'
test/compile_errors/stage1/obj/or_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: bool = undefined;
3 _ = a or a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/orelse_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: ?bool = undefined;
3 _ = a orelse false;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:11: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/out_of_range_comptime_int_passed_to_floatToInt.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = @floatToInt(i8, 200);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'
test/compile_errors/stage1/obj/overflow_in_enum_value_allocation.zig deleted-14
......@@ -1,14 +0,0 @@
1const Moo = enum(u8) {
2 Last = 255,
3 Over,
4};
5pub fn main() void {
6 var y = Moo.Last;
7 _ = y;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'
test/compile_errors/stage1/obj/packed_union_given_enum_tag_type.zig deleted-20
......@@ -1,20 +0,0 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = packed union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10};
11export fn entry() void {
12 var a = Payload { .A = 1234 };
13 _ = a;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:6:30: error: packed union does not support enum tag type
test/compile_errors/stage1/obj/packed_union_with_automatic_layout_field.zig deleted-18
......@@ -1,18 +0,0 @@
1const Foo = struct {
2 a: u32,
3 b: f32,
4};
5const Payload = packed union {
6 A: Foo,
7 B: bool,
8};
9export fn entry() void {
10 var a = Payload { .B = true };
11 _ = a;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation
test/compile_errors/stage1/obj/panic_called_at_compile_time.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 comptime {
3 @panic("aoeu",);
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: encountered @panic at compile-time
test/compile_errors/stage1/obj/parameter_redeclaration.zig deleted-10
......@@ -1,10 +0,0 @@
1fn f(a : i32, a : i32) void {
2}
3export fn entry() void { f(1, 2); }
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:1:15: error: redeclaration of function parameter 'a'
10// tmp.zig:1:6: note: previous declaration here
test/compile_errors/stage1/obj/parameter_shadowing_global.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = struct {};
2fn f(Foo: i32) void {}
3export fn entry() void {
4 f(1234);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:2:6: error: local shadows declaration of 'Foo'
12// tmp.zig:1:1: note: declared here
test/compile_errors/stage1/obj/pass_const_ptr_to_mutable_ptr_fn.zig deleted-17
......@@ -1,17 +0,0 @@
1fn foo() bool {
2 const a = @as([]const u8, "a",);
3 const b = &a;
4 return ptrEql(b, b);
5}
6fn ptrEql(a: *[]const u8, b: *[]const u8) bool {
7 _ = a; _ = b;
8 return true;
9}
10
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'
test/compile_errors/stage1/obj/passing_a_not-aligned-enough_pointer_to_cmpxchg.zig deleted-12
......@@ -1,12 +0,0 @@
1const AtomicOrder = @import("std").builtin.AtomicOrder;
2export fn entry() bool {
3 var x: i32 align(1) = 1234;
4 while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
5 return x == 5678;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'
test/compile_errors/stage1/obj/passing_an_under-aligned_function_pointer.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
3}
4fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) i32, answer: i32) void {
5 if (ptr() != answer) unreachable;
6}
7fn alignedSmall() align(4) i32 { return 1234; }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'
test/compile_errors/stage1/obj/peer_cast_then_implicit_cast_const_pointer_to_mutable_C_pointer.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn func() void {
2 var strValue: [*c]u8 = undefined;
3 strValue = strValue orelse "";
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'
11// tmp.zig:3:32: note: cast discards const qualifier
test/compile_errors/stage1/obj/pointer_arithmetic_on_pointer-to-array.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn foo() void {
2 var x: [10]u8 = undefined;
3 var y = &x;
4 var z = y + 1;
5 _ = z;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:4:17: error: integer value 1 cannot be coerced to type '*[10]u8'
test/compile_errors/stage1/obj/pointer_attributes_checked_when_coercing_pointer_to_anon_literal.zig deleted-24
......@@ -1,24 +0,0 @@
1comptime {
2 const c: [][]const u8 = &.{"hello", "world" };
3 _ = c;
4}
5comptime {
6 const c: *[2][]const u8 = &.{"hello", "world" };
7 _ = c;
8}
9const S = struct {a: u8 = 1, b: u32 = 2};
10comptime {
11 const c: *S = &.{};
12 _ = c;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:31: error: cannot cast pointer to array literal to slice type '[][]const u8'
20// tmp.zig:2:31: note: cast discards const qualifier
21// tmp.zig:6:33: error: cannot cast pointer to array literal to '*[2][]const u8'
22// tmp.zig:6:33: note: cast discards const qualifier
23// tmp.zig:11:21: error: expected type '*S', found '*const struct:11:21'
24// tmp.zig:11:21: note: cast discards const qualifier
test/compile_errors/stage1/obj/pointer_to_noreturn.zig deleted-8
......@@ -1,8 +0,0 @@
1fn a() *noreturn {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:9: error: pointer to noreturn not allowed
test/compile_errors/stage1/obj/popCount-non-integer.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(x: f32) u32 {
2 return @popCount(f32, x);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: expected integer type, found 'f32'
test/compile_errors/stage1/obj/prevent_bad_implicit_casting_of_anyframe_types.zig deleted-24
......@@ -1,24 +0,0 @@
1export fn a() void {
2 var x: anyframe = undefined;
3 var y: anyframe->i32 = x;
4 _ = y;
5}
6export fn b() void {
7 var x: i32 = undefined;
8 var y: anyframe->i32 = x;
9 _ = y;
10}
11export fn c() void {
12 var x: @Frame(func) = undefined;
13 var y: anyframe->i32 = &x;
14 _ = y;
15}
16fn func() void {}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'
23// tmp.zig:8:28: error: expected type 'anyframe->i32', found 'i32'
24// tmp.zig:13:29: error: expected type 'anyframe->i32', found '*@Frame(func)'
test/compile_errors/stage1/obj/primitives_take_precedence_over_declarations.zig deleted-11
......@@ -1,11 +0,0 @@
1const @"u8" = u16;
2export fn entry() void {
3 const a: u8 = 300;
4 _ = a;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:19: error: integer value 300 cannot be coerced to type 'u8'
test/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() bool {
2 var x: u0 = 0;
3 const p = @ptrCast(?*u0, &x);
4 return p == null;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation
12// tmp.zig:3:31: note: '*u0' has no in-memory bits
13// tmp.zig:3:24: note: '?*u0' has in-memory bits
test/compile_errors/stage1/obj/ptrCast_discards_const_qualifier.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 const x: i32 = 1234;
3 const y = @ptrCast(*i32, &x);
4 _ = y;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:15: error: cast discards const qualifier
test/compile_errors/stage1/obj/ptrToInt_0_to_non_optional_pointer.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var b = @intToPtr(*i32, 0);
3 _ = b;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:13: error: pointer type '*i32' does not allow address zero
test/compile_errors/stage1/obj/ptrToInt_on_void.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() bool {
2 return @ptrToInt(&{}) == @ptrToInt(&{});
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:23: error: pointer to size 0 type has no address
test/compile_errors/stage1/obj/ptrcast_to_non-pointer.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(a: *i32) usize {
2 return @ptrCast(usize, a);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:21: error: expected pointer, found 'usize'
test/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig deleted-19
......@@ -1,19 +0,0 @@
1export fn entry() void {
2 try foo(452) catch |err| switch (err) {
3 error.A ... error.B => {},
4 else => {},
5 };
6}
7fn foo(x: i32) !void {
8 switch (x) {
9 0 ... 10 => return error.Foo,
10 11 ... 20 => return error.Bar,
11 else => {},
12 }
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:3:17: error: operator not allowed for errors
test/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig deleted-13
......@@ -1,13 +0,0 @@
1comptime {
2 const array: [4]u8 = "aoeu".*;
3 const sub_array = array[1..];
4 const int_ptr = @ptrCast(*const u24, sub_array);
5 const deref = int_ptr.*;
6 _ = deref;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes
test/compile_errors/stage1/obj/recursive_inferred_error_set.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 foo() catch unreachable;
3}
4fn foo() !void {
5 try foo();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet
test/compile_errors/stage1/obj/redefinition_of_enums.zig deleted-9
......@@ -1,9 +0,0 @@
1const A = enum {x};
2const A = enum {x};
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:1: error: redeclaration of 'A'
9// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/redefinition_of_global_variables.zig deleted-9
......@@ -1,9 +0,0 @@
1var a : i32 = 1;
2var a : i32 = 2;
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:1: error: redeclaration of 'a'
9// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/redefinition_of_struct.zig deleted-9
......@@ -1,9 +0,0 @@
1const A = struct { x : i32, };
2const A = struct { y : i32, };
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:2:1: error: redeclaration of 'A'
9// tmp.zig:1:1: note: other declaration here
test/compile_errors/stage1/obj/refer_to_the_type_of_a_generic_function.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 const Func = fn (type) void;
3 const f: Func = undefined;
4 f(i32);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/referring_to_a_struct_that_is_invalid.zig deleted-17
......@@ -1,17 +0,0 @@
1const UsbDeviceRequest = struct {
2 Type: u8,
3};
4
5export fn foo() void {
6 comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
7}
8
9fn assert(ok: bool) void {
10 if (!ok) unreachable;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:10:14: error: reached unreachable code
test/compile_errors/stage1/obj/regression_test_2980_base_type_u32_is_not_type_checked_properly_when_assigning_a_value_within_a_struct.zig deleted-21
......@@ -1,21 +0,0 @@
1const Foo = struct {
2 ptr: ?*usize,
3 uval: u32,
4};
5fn get_uval(x: u32) !u32 {
6 _ = x;
7 return error.NotFound;
8}
9export fn entry() void {
10 const afoo = Foo{
11 .ptr = null,
12 .uval = get_uval(42),
13 };
14 _ = afoo;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:12:25: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(get_uval)).Fn.return_type.?).ErrorUnion.error_set!u32'
test/compile_errors/stage1/obj/reify_type.Fn_with_is_generic_true.zig deleted-17
......@@ -1,17 +0,0 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = true,
6 .is_var_args = false,
7 .return_type = u0,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:20: error: Type.Fn.is_generic must be false for @Type
test/compile_errors/stage1/obj/reify_type.Fn_with_is_var_args_true_and_non-C_callconv.zig deleted-17
......@@ -1,17 +0,0 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = false,
6 .is_var_args = true,
7 .return_type = u0,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:20: error: varargs functions must have C calling convention
test/compile_errors/stage1/obj/reify_type.Fn_with_return_type_null.zig deleted-17
......@@ -1,17 +0,0 @@
1const Foo = @Type(.{
2 .Fn = .{
3 .calling_convention = .Unspecified,
4 .alignment = 0,
5 .is_generic = false,
6 .is_var_args = false,
7 .return_type = null,
8 .args = &.{},
9 },
10});
11comptime { _ = Foo; }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:20: error: Type.Fn.return_type must be non-null for @Type
test/compile_errors/stage1/obj/reify_type.Pointer_with_invalid_address_space.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn entry() void {
2 _ = @Type(.{ .Pointer = .{
3 .size = .One,
4 .is_const = false,
5 .is_volatile = false,
6 .alignment = 1,
7 .address_space = .gs,
8 .child = u8,
9 .is_allowzero = false,
10 .sentinel = null,
11 }});
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:2:16: error: address space 'gs' not available in stage 1 compiler, must be .generic
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_non-integer_tag_type.zig deleted-18
......@@ -1,18 +0,0 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = bool,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = false,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:1:20: error: Type.Enum.tag_type must be an integer type, not 'bool'
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_undefined_tag_type.zig deleted-18
......@@ -1,18 +0,0 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = undefined,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = false,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/reify_type_for_exhaustive_enum_with_zero_fields.zig deleted-18
......@@ -1,18 +0,0 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,
5 .fields = &.{},
6 .decls = &.{},
7 .is_exhaustive = true,
8 },
9});
10export fn entry() void {
11 _ = @intToEnum(Tag, 0);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:1:20: error: enums must have 1 or more fields
test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_enum_field.zig deleted-34
......@@ -1,34 +0,0 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u2,
5 .fields = &.{
6 .{ .name = "signed", .value = 0 },
7 .{ .name = "unsigned", .value = 1 },
8 .{ .name = "arst", .value = 2 },
9 },
10 .decls = &.{},
11 .is_exhaustive = true,
12 },
13});
14const Tagged = @Type(.{
15 .Union = .{
16 .layout = .Auto,
17 .tag_type = Tag,
18 .fields = &.{
19 .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
20 .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
21 },
22 .decls = &.{},
23 },
24});
25export fn entry() void {
26 var tagged = Tagged{ .signed = -1 };
27 tagged = .{ .unsigned = 1 };
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:14:23: error: enum field missing: 'arst'
test/compile_errors/stage1/obj/reify_type_for_tagged_union_with_extra_union_field.zig deleted-35
......@@ -1,35 +0,0 @@
1const Tag = @Type(.{
2 .Enum = .{
3 .layout = .Auto,
4 .tag_type = u1,
5 .fields = &.{
6 .{ .name = "signed", .value = 0 },
7 .{ .name = "unsigned", .value = 1 },
8 },
9 .decls = &.{},
10 .is_exhaustive = true,
11 },
12});
13const Tagged = @Type(.{
14 .Union = .{
15 .layout = .Auto,
16 .tag_type = Tag,
17 .fields = &.{
18 .{ .name = "signed", .field_type = i32, .alignment = @alignOf(i32) },
19 .{ .name = "unsigned", .field_type = u32, .alignment = @alignOf(u32) },
20 .{ .name = "arst", .field_type = f32, .alignment = @alignOf(f32) },
21 },
22 .decls = &.{},
23 },
24});
25export fn entry() void {
26 var tagged = Tagged{ .signed = -1 };
27 tagged = .{ .unsigned = 1 };
28}
29
30// error
31// backend=stage1
32// target=native
33//
34// tmp.zig:13:23: error: enum field not found: 'arst'
35// tmp.zig:1:20: note: enum declared here
test/compile_errors/stage1/obj/reify_type_for_union_with_opaque_field.zig deleted-19
......@@ -1,19 +0,0 @@
1const Untagged = @Type(.{
2 .Union = .{
3 .layout = .Auto,
4 .tag_type = null,
5 .fields = &.{
6 .{ .name = "foo", .field_type = opaque {}, .alignment = 1 },
7 },
8 .decls = &.{},
9 },
10});
11export fn entry() void {
12 _ = Untagged{};
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:1:25: error: opaque types have unknown size and therefore cannot be directly embedded in unions
test/compile_errors/stage1/obj/reify_type_for_union_with_zero_fields.zig deleted-17
......@@ -1,17 +0,0 @@
1const Untagged = @Type(.{
2 .Union = .{
3 .layout = .Auto,
4 .tag_type = null,
5 .fields = &.{},
6 .decls = &.{},
7 },
8});
9export fn entry() void {
10 _ = Untagged{};
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:25: error: unions must have 1 or more fields
test/compile_errors/stage1/obj/reify_type_union_payload_is_undefined.zig deleted-10
......@@ -1,10 +0,0 @@
1const Foo = @Type(.{
2 .Struct = undefined,
3});
4comptime { _ = Foo; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:20: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/reify_type_with_Type.Int.zig deleted-13
......@@ -1,13 +0,0 @@
1const builtin = @import("std").builtin;
2export fn entry() void {
3 _ = @Type(builtin.Type.Int{
4 .signedness = .signed,
5 .bits = 8,
6 });
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:3:31: error: expected type 'std.builtin.Type', found 'std.builtin.Type.Int'
test/compile_errors/stage1/obj/reify_type_with_non-constant_expression.zig deleted-11
......@@ -1,11 +0,0 @@
1const builtin = @import("std").builtin;
2var globalTypeInfo : builtin.Type = undefined;
3export fn entry() void {
4 _ = @Type(globalTypeInfo);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:4:15: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/reify_type_with_undefined.zig deleted-20
......@@ -1,20 +0,0 @@
1comptime {
2 _ = @Type(.{ .Array = .{ .len = 0, .child = u8, .sentinel = undefined } });
3}
4comptime {
5 _ = @Type(.{
6 .Struct = .{
7 .fields = undefined,
8 .decls = undefined,
9 .is_tuple = false,
10 .layout = .Auto,
11 },
12 });
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:16: error: use of undefined value here causes undefined behavior
20// tmp.zig:5:16: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn entry() void {
2 var damn = Container{
3 .not_optional = getOptional(),
4 };
5 _ = damn;
6}
7pub fn getOptional() ?i32 {
8 return 0;
9}
10pub const Container = struct {
11 not_optional: i32,
12};
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/compile_errors/stage1/obj/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn entry() void {
2 var damn = Container{
3 .not_optional = getOptional(i32),
4 };
5 _ = damn;
6}
7pub fn getOptional(comptime T: type) ?T {
8 return 0;
9}
10pub const Container = struct {
11 not_optional: i32,
12};
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:3:36: error: cannot convert optional to payload type. consider using `.?`, `orelse`, or `if`. expected type 'i32', found '?i32'
test/compile_errors/stage1/obj/return_from_defer_expression.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn testTrickyDefer() !void {
2 defer canFail() catch {};
3
4 defer try canFail();
5
6 const a = maybeInt() orelse return;
7}
8
9fn canFail() anyerror!void { }
10
11pub fn maybeInt() ?i32 {
12 return 0;
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(testTrickyDefer)); }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:4:11: error: 'try' not allowed inside defer expression
test/compile_errors/stage1/obj/returning_error_from_void_async_function.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() callconv(.Async) void {
5 return error.ShouldBeCompileError;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'
test/compile_errors/stage1/obj/runtime-known_async_function_called.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() void {
5 var ptr = afunc;
6 _ = ptr();
7}
8fn afunc() callconv(.Async) void {}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:12: error: function is not comptime-known; @asyncCall required
test/compile_errors/stage1/obj/runtime-known_function_called_with_async_keyword.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var ptr = afunc;
3 _ = async ptr();
4}
5
6fn afunc() callconv(.Async) void { }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:15: error: function is not comptime-known; @asyncCall required
test/compile_errors/stage1/obj/runtime_assignment_to_comptime_struct_type.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = struct {
2 Bar: u8,
3 Baz: type,
4};
5export fn f() void {
6 var x: u8 = 0;
7 const foo = Foo { .Bar = x, .Baz = u8 };
8 _ = foo;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:23: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/runtime_assignment_to_comptime_union_type.zig deleted-15
......@@ -1,15 +0,0 @@
1const Foo = union {
2 Bar: u8,
3 Baz: type,
4};
5export fn f() void {
6 var x: u8 = 0;
7 const foo = Foo { .Bar = x };
8 _ = foo;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:23: error: unable to evaluate constant expression
test/compile_errors/stage1/obj/runtime_cast_to_union_which_has_non-void_fields.zig deleted-20
......@@ -1,20 +0,0 @@
1const Letter = enum { A, B, C };
2const Value = union(Letter) {
3 A: i32,
4 B,
5 C,
6};
7export fn entry() void {
8 foo(Letter.A);
9}
10fn foo(l: Letter) void {
11 var x: Value = l;
12 _ = x;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields
20// tmp.zig:3:5: note: field 'A' has type 'i32'
test/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig deleted-17
......@@ -1,17 +0,0 @@
1const Struct = struct {
2 a: u32,
3};
4fn getIndex() usize {
5 return 2;
6}
7export fn entry() void {
8 const index = getIndex();
9 const field = @typeInfo(Struct).Struct.fields[index];
10 _ = field;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known
test/compile_errors/stage1/obj/saturating_arithmetic_does_not_allow_floats.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a() void {
2 _ = @as(f32, 1.0) +| @as(f32, 1.0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// error: invalid operands to binary expression: 'f32' and 'f32'
test/compile_errors/stage1/obj/saturating_shl_assign_does_not_allow_negative_rhs_at_comptime.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn a() void {
2 comptime {
3 var x = @as(i32, 1);
4 x <<|= @as(i32, -2);
5 }
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// error: shift by negative value -2
test/compile_errors/stage1/obj/saturating_shl_does_not_allow_negative_rhs_at_comptime.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a() void {
2 _ = @as(i32, 1) <<| @as(i32, -2);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// error: shift by negative value -2
test/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 foo();
3}
4fn foo() callconv(.Inline) void {
5 @setAlignStack(16);
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: @setAlignStack in inline function
test/compile_errors/stage1/obj/setAlignStack_in_naked_function.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() callconv(.Naked) void {
2 @setAlignStack(16);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @setAlignStack in naked function
test/compile_errors/stage1/obj/setAlignStack_outside_function.zig deleted-9
......@@ -1,9 +0,0 @@
1comptime {
2 @setAlignStack(16);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @setAlignStack outside function
test/compile_errors/stage1/obj/setAlignStack_set_twice.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 @setAlignStack(16);
3 @setAlignStack(16);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: alignstack set twice
11// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setAlignStack_too_big.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 @setAlignStack(511 + 1);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256
test/compile_errors/stage1/obj/setFloatMode_twice_for_same_scope.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn foo() void {
2 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
3 @setFloatMode(@import("std").builtin.FloatMode.Optimized);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: float mode set twice for same scope
11// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setRuntimeSafety_twice_for_same_scope.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn foo() void {
2 @setRuntimeSafety(false);
3 @setRuntimeSafety(false);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: runtime safety set twice for same scope
11// tmp.zig:2:5: note: first set here
test/compile_errors/stage1/obj/setting_a_section_on_a_local_variable.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() i32 {
2 var foo: i32 linksection(".text2") = 1234;
3 return foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:30: error: cannot set section of local variable 'foo'
test/compile_errors/stage1/obj/shift_amount_has_to_be_an_integer_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = 1 << &@as(u8, 10);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:21: error: shift amount has to be an integer type, but found '*const u8'
test/compile_errors/stage1/obj/shift_by_negative_comptime_integer.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a = 1 >> -1;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:18: error: shift by negative value -1
test/compile_errors/stage1/obj/shift_left_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a >>= 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_left_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a << 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_right_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a >>= 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shift_right_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a >> 2;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/shifting_RHS_is_log2_of_LHS_int_bit_width.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(x: u8, y: u8) u8 {
2 return x << y;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:17: error: expected type 'u3', found 'u8'
test/compile_errors/stage1/obj/shifting_without_int_type_or_comptime_known.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry(x: u8) u8 {
2 return 0x11 << x;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known
test/compile_errors/stage1/obj/shlExact_shifts_out_1_bits.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 const x = @shlExact(@as(u8, 0b01010101), 2);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: operation caused overflow
test/compile_errors/stage1/obj/shrExact_shifts_out_1_bits.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 const x = @shrExact(@as(u8, 0b10101010), 2);
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: exact shift shifted out 1 bits
test/compile_errors/stage1/obj/signed_integer_division.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a / b;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact
test/compile_errors/stage1/obj/signed_integer_remainder_division.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn foo(a: i32, b: i32) i32 {
2 return a % b;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod
test/compile_errors/stage1/obj/sizeOf_bad_type.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() usize {
2 return @sizeOf(@TypeOf(null));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:20: error: no size available for type '@Type(.Null)'
test/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn foo() void {
2 const bytes = [1]u8{ 0xfa } ** 16;
3 var value = @ptrCast(*const []const u8, &bytes).*;
4 _ = value;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted
test/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = []u8{};
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = []u8{1, 2};
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8'
test/compile_errors/stage1/obj/slice_sentinel_mismatch-1.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const y: [:1]const u8 = &[_:2]u8{ 1, 2 };
3 _ = y;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:37: error: expected type '[:1]const u8', found '*const [2:2]u8'
test/compile_errors/stage1/obj/slice_sentinel_mismatch-2.zig deleted-12
......@@ -1,12 +0,0 @@
1fn foo() [:0]u8 {
2 var x: []u8 = undefined;
3 return x;
4}
5comptime { _ = foo; }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:12: error: expected type '[:0]u8', found '[]u8'
12// tmp.zig:3:12: note: destination pointer requires a terminating '0' sentinel
test/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig deleted-10
......@@ -1,10 +0,0 @@
1var buf: *[1]u8 = undefined;
2export fn entry() void {
3 _ = buf[0..1];
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: non-zero length slice of undefined pointer
test/compile_errors/stage1/obj/slicing_single-item_pointer.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry(ptr: *i32) void {
2 const slice = ptr[0..2];
3 _ = slice;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:22: error: slice of single-item pointer
test/compile_errors/stage1/obj/specify_enum_tag_type_that_is_too_small.zig deleted-18
......@@ -1,18 +0,0 @@
1const Small = enum (u2) {
2 One,
3 Two,
4 Three,
5 Four,
6 Five,
7};
8
9export fn entry() void {
10 var x = Small.One;
11 _ = x;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'
test/compile_errors/stage1/obj/specify_non-integer_enum_tag_type.zig deleted-16
......@@ -1,16 +0,0 @@
1const Small = enum (f32) {
2 One,
3 Two,
4 Three,
5};
6
7export fn entry() void {
8 var x = Small.One;
9 _ = x;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:1:21: error: expected integer, found 'f32'
test/compile_errors/stage1/obj/src_outside_function.zig deleted-9
......@@ -1,9 +0,0 @@
1comptime {
2 @src();
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: @src outside function
test/compile_errors/stage1/obj/std.fmt_error_for_unused_arguments.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 @import("std").debug.print("{d} {d} {d} {d} {d}", .{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// ?:?:?: error: 10 unused arguments in '{d} {d} {d} {d} {d}'
test/compile_errors/stage1/obj/store_vector_pointer_with_unknown_runtime_index.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 var v: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
3
4 var i: u32 = 0;
5 storev(&v[i], 42);
6}
7
8fn storev(ptr: anytype, val: i32) void {
9 ptr.* = val;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32
test/compile_errors/stage1/obj/storing_runtime_value_in_compile_time_variable_then_using_it.zig deleted-49
......@@ -1,49 +0,0 @@
1const Mode = @import("std").builtin.Mode;
2
3fn Free(comptime filename: []const u8) TestCase {
4 return TestCase {
5 .filename = filename,
6 .problem_type = ProblemType.Free,
7 };
8}
9
10fn LibC(comptime filename: []const u8) TestCase {
11 return TestCase {
12 .filename = filename,
13 .problem_type = ProblemType.LinkLibC,
14 };
15}
16
17const TestCase = struct {
18 filename: []const u8,
19 problem_type: ProblemType,
20};
21
22const ProblemType = enum {
23 Free,
24 LinkLibC,
25};
26
27export fn entry() void {
28 const tests = [_]TestCase {
29 Free("001"),
30 Free("002"),
31 LibC("078"),
32 Free("116"),
33 Free("117"),
34 };
35
36 for ([_]Mode { Mode.Debug, Mode.ReleaseSafe, Mode.ReleaseFast }) |mode| {
37 _ = mode;
38 inline for (tests) |test_case| {
39 const foo = test_case.filename ++ ".zig";
40 _ = foo;
41 }
42 }
43}
44
45// error
46// backend=stage1
47// target=native
48//
49// tmp.zig:38:29: error: cannot store runtime value in compile time variable
test/compile_errors/stage1/obj/struct_depends_on_itself_via_optional_field.zig deleted-19
......@@ -1,19 +0,0 @@
1const LhsExpr = struct {
2 rhsExpr: ?AstObject,
3};
4const AstObject = union {
5 lhsExpr: LhsExpr,
6};
7export fn entry() void {
8 const lhsExpr = LhsExpr{ .rhsExpr = null };
9 const obj = AstObject{ .lhsExpr = lhsExpr };
10 _ = obj;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:1:17: error: struct 'LhsExpr' depends on itself
18// tmp.zig:5:5: note: while checking this field
19// tmp.zig:2:5: note: while checking this field
test/compile_errors/stage1/obj/struct_field_missing_type.zig deleted-13
......@@ -1,13 +0,0 @@
1const Letter = struct {
2 A,
3};
4export fn entry() void {
5 var a = Letter { .A = {} };
6 _ = a;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: struct field missing type
test/compile_errors/stage1/obj/struct_init_syntax_for_array.zig deleted-10
......@@ -1,10 +0,0 @@
1const foo = [3]u16{ .x = 1024 };
2comptime {
3 _ = foo;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:13: error: initializing array with struct syntax
test/compile_errors/stage1/obj/struct_with_declarations_unavailable_for_reify_type.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 _ = @Type(@typeInfo(struct { const foo = 1; }));
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: Type.Struct.decls must be empty for @Type
test/compile_errors/stage1/obj/struct_with_invalid_field.zig deleted-30
......@@ -1,30 +0,0 @@
1const std = @import("std",);
2const Allocator = std.mem.Allocator;
3const ArrayList = std.ArrayList;
4
5const HeaderWeight = enum {
6 H1, H2, H3, H4, H5, H6,
7};
8
9const MdText = ArrayList(u8);
10
11const MdNode = union(enum) {
12 Header: struct {
13 text: MdText,
14 weight: HeaderValue,
15 },
16};
17
18export fn entry() void {
19 const a = MdNode.Header {
20 .text = MdText.init(std.testing.allocator),
21 .weight = HeaderWeight.H1,
22 };
23 _ = a;
24}
25
26// error
27// backend=stage1
28// target=native
29//
30// tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'
test/compile_errors/stage1/obj/sub_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a -= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a - a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig deleted-12
......@@ -1,12 +0,0 @@
1const y = sub(10, 20);
2fn sub(a: u16, b: u16) u16 {
3 return a - b;
4}
5
6export fn entry() usize { return @sizeOf(@TypeOf(y)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:14: error: operation caused overflow
test/compile_errors/stage1/obj/sub_wrap_assign_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 a -%= a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/sub_wrap_on_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 var a: i64 = undefined;
3 _ = a -% a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:9: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/suspend_inside_suspend_block.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 _ = async foo();
3}
4fn foo() void {
5 suspend {
6 suspend {
7 }
8 }
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:6:9: error: cannot suspend inside suspend block
16// tmp.zig:5:5: note: other suspend block here
test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong.zig deleted-24
......@@ -1,24 +0,0 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 Number.Four => 4,
13 Number.Two => 2,
14 }
15}
16
17export fn entry() usize { return @sizeOf(@TypeOf(f)); }
18
19// error
20// backend=stage1
21// target=native
22//
23// tmp.zig:13:15: error: duplicate switch value
24// tmp.zig:10:15: note: other value here
test/compile_errors/stage1/obj/switch_expression-duplicate_enumeration_prong_when_else_present.zig deleted-25
......@@ -1,25 +0,0 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 Number.Four => 4,
13 Number.Two => 2,
14 else => 10,
15 }
16}
17
18export fn entry() usize { return @sizeOf(@TypeOf(f)); }
19
20// error
21// backend=stage1
22// target=native
23//
24// tmp.zig:13:15: error: duplicate switch value
25// tmp.zig:10:15: note: other value here
test/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig deleted-16
......@@ -1,16 +0,0 @@
1fn foo(x: u8) u8 {
2 return switch (x) {
3 0 ... 100 => @as(u8, 0),
4 101 ... 200 => 1,
5 201, 203 ... 207 => 2,
6 206 ... 255 => 3,
7 };
8}
9export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:6:9: error: duplicate switch value
16// tmp.zig:5:14: note: previous value here
test/compile_errors/stage1/obj/switch_expression-duplicate_type.zig deleted-17
......@@ -1,17 +0,0 @@
1fn foo(comptime T: type, x: T) u8 {
2 _ = x;
3 return switch (T) {
4 u32 => 0,
5 u64 => 1,
6 u32 => 2,
7 else => 3,
8 };
9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:9: error: duplicate switch value
17// tmp.zig:4:9: note: previous value here
test/compile_errors/stage1/obj/switch_expression-duplicate_type_struct_alias.zig deleted-21
......@@ -1,21 +0,0 @@
1const Test = struct {
2 bar: i32,
3};
4const Test2 = Test;
5fn foo(comptime T: type, x: T) u8 {
6 _ = x;
7 return switch (T) {
8 Test => 0,
9 u64 => 1,
10 Test2 => 2,
11 else => 3,
12 };
13}
14export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:10:9: error: duplicate switch value
21// tmp.zig:8:9: note: previous value here
test/compile_errors/stage1/obj/switch_expression-missing_enumeration_prong.zig deleted-21
......@@ -1,21 +0,0 @@
1const Number = enum {
2 One,
3 Two,
4 Three,
5 Four,
6};
7fn f(n: Number) i32 {
8 switch (n) {
9 Number.One => 1,
10 Number.Two => 2,
11 Number.Three => @as(i32, 3),
12 }
13}
14
15export fn entry() usize { return @sizeOf(@TypeOf(f)); }
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch
test/compile_errors/stage1/obj/switch_expression-multiple_else_prongs.zig deleted-16
......@@ -1,16 +0,0 @@
1fn f(x: u32) void {
2 const value: bool = switch (x) {
3 1234 => false,
4 else => true,
5 else => true,
6 };
7}
8export fn entry() void {
9 f(1234);
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:5:9: error: multiple else prongs in switch expression
test/compile_errors/stage1/obj/switch_expression-non_exhaustive_integer_prongs.zig deleted-12
......@@ -1,12 +0,0 @@
1fn foo(x: u8) void {
2 switch (x) {
3 0 => {},
4 }
5}
6export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:5: error: switch must handle all possibilities
test/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig deleted-13
......@@ -1,13 +0,0 @@
1fn foo(x: *u8) void {
2 switch (x) {
3 &y => {},
4 }
5}
6const y: u8 = 100;
7export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:5: error: else prong required when switching on type '*u8'
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig deleted-14
......@@ -1,14 +0,0 @@
1fn foo(x: bool) void {
2 switch (x) {
3 true => {},
4 false => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_enum.zig deleted-24
......@@ -1,24 +0,0 @@
1const TestEnum = enum{ T1, T2 };
2
3fn err(x: u8) TestEnum {
4 switch (x) {
5 0 => return TestEnum.T1,
6 else => return TestEnum.T2,
7 }
8}
9
10fn foo(x: u8) void {
11 switch (err(x)) {
12 TestEnum.T1 => {},
13 TestEnum.T2 => {},
14 else => {},
15 }
16}
17
18export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
19
20// error
21// backend=stage1
22// target=native
23//
24// tmp.zig:14:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_i8.zig deleted-17
......@@ -1,17 +0,0 @@
1fn foo(x: i8) void {
2 switch (x) {
3 -128...0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 4...127 => {},
8 else => {},
9 }
10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_range_u8.zig deleted-17
......@@ -1,17 +0,0 @@
1fn foo(x: u8) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 4...255 => {},
8 else => {},
9 }
10}
11export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:8:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u1.zig deleted-14
......@@ -1,14 +0,0 @@
1fn foo(x: u1) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 else => {},
6 }
7}
8export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:5:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_u2.zig deleted-16
......@@ -1,16 +0,0 @@
1fn foo(x: u2) void {
2 switch (x) {
3 0 => {},
4 1 => {},
5 2 => {},
6 3 => {},
7 else => {},
8 }
9}
10export fn entry() usize { return @sizeOf(@TypeOf(foo)); }
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:7:9: error: unreachable else prong, all cases already handled
test/compile_errors/stage1/obj/switch_on_enum_with_1_field_with_no_prongs.zig deleted-12
......@@ -1,12 +0,0 @@
1const Foo = enum { M };
2
3export fn entry() void {
4 var f = Foo.M;
5 switch (f) {}
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch
test/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig deleted-22
......@@ -1,22 +0,0 @@
1const Payload = union {
2 A: i32,
3 B: f64,
4 C: bool,
5};
6export fn entry() void {
7 const a = Payload { .A = 1234 };
8 foo(a);
9}
10fn foo(a: *const Payload) void {
11 switch (a.*) {
12 Payload.A => {},
13 else => unreachable,
14 }
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:11:14: error: switch on union which has no attached enum
22// tmp.zig:1:17: note: consider 'union(enum)' here
test/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig deleted-17
......@@ -1,17 +0,0 @@
1export fn entry() void {
2 Test(i32);
3}
4fn Test(comptime T: type) void {
5 const x = switch (T) {
6 []u8 => |x| x,
7 i32 => |x| x,
8 else => unreachable,
9 };
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:7:17: error: switch on type 'type' provides no expression parameter
test/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 var q: u8 = 0;
3 switch (q) {
4 1...2 => {},
5 0...255 => {},
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:9: error: duplicate switch value
test/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig deleted-16
......@@ -1,16 +0,0 @@
1const FloatInt = extern union {
2 Float: f32,
3 Int: i32,
4};
5export fn entry() void {
6 var fi = FloatInt{.Float = 123.45};
7 var tagName = @tagName(fi);
8 _ = tagName;
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:7:19: error: union has no associated enum
16// tmp.zig:1:18: note: declared here
test/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = 'a'.*[0..];
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'
test/compile_errors/stage1/obj/taking_bit_offset_of_void_field_in_struct.zig deleted-13
......@@ -1,13 +0,0 @@
1const Empty = struct {
2 val: void,
3};
4export fn foo() void {
5 const fieldOffset = @bitOffsetOf(Empty, "val",);
6 _ = fieldOffset;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset
test/compile_errors/stage1/obj/taking_byte_offset_of_void_field_in_struct.zig deleted-13
......@@ -1,13 +0,0 @@
1const Empty = struct {
2 val: void,
3};
4export fn foo() void {
5 const fieldOffset = @offsetOf(Empty, "val",);
6 _ = fieldOffset;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:5:42: error: zero-bit field 'val' in struct 'Empty' has no offset
test/compile_errors/stage1/obj/threadlocal_qualifier_on_const.zig deleted-10
......@@ -1,10 +0,0 @@
1threadlocal const x: i32 = 1234;
2export fn entry() i32 {
3 return x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:1: error: threadlocal variable cannot be constant
test/compile_errors/stage1/obj/top_level_decl_dependency_loop.zig deleted-12
......@@ -1,12 +0,0 @@
1const a : @TypeOf(b) = 0;
2const b : @TypeOf(a) = 0;
3export fn entry() void {
4 const c = a + b;
5 _ = c;
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:2:19: error: dependency loop detected
test/compile_errors/stage1/obj/truncate_sign_mismatch.zig deleted-25
......@@ -1,25 +0,0 @@
1export fn entry1() i8 {
2 var x: u32 = 10;
3 return @truncate(i8, x);
4}
5export fn entry2() u8 {
6 var x: i32 = -10;
7 return @truncate(u8, x);
8}
9export fn entry3() i8 {
10 comptime var x: u32 = 10;
11 return @truncate(i8, x);
12}
13export fn entry4() u8 {
14 comptime var x: i32 = -10;
15 return @truncate(u8, x);
16}
17
18// error
19// backend=stage1
20// target=native
21//
22// tmp.zig:3:26: error: expected signed integer type, found 'u32'
23// tmp.zig:7:26: error: expected unsigned integer type, found 'i32'
24// tmp.zig:11:26: error: expected signed integer type, found 'u32'
25// tmp.zig:15:26: error: expected unsigned integer type, found 'i32'
test/compile_errors/stage1/obj/truncate_undefined_value.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var z = @truncate(u8, @as(u16, undefined));
3 _ = z;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:27: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/try_in_function_with_non_error_return_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 try something();
3}
4fn something() anyerror!void { }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:5: error: expected type 'void', found 'anyerror'
test/compile_errors/stage1/obj/type_checking_function_pointers.zig deleted-13
......@@ -1,13 +0,0 @@
1fn a(b: fn (*const u8) void) void {
2 b('a');
3}
4fn c(d: u8) void {_ = d;}
5export fn entry() void {
6 a(c);
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'
test/compile_errors/stage1/obj/type_variables_must_be_constant.zig deleted-10
......@@ -1,10 +0,0 @@
1var foo = u8;
2export fn entry() foo {
3 return 1;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:1:1: error: variable of type 'type' must be constant
test/compile_errors/stage1/obj/undeclared_identifier.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn a() void {
2 return
3 b +
4 c;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/undeclared_identifier_error_should_mark_fn_as_impure.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn foo() void {
2 test_a_thing();
3}
4fn test_a_thing() void {
5 bad_fn_call();
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'
test/compile_errors/stage1/obj/undeclared_identifier_in_unanalyzed_branch.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn a() void {
2 if (false) {
3 lol_this_doesnt_exist = nonsense;
4 }
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: use of undeclared identifier 'lol_this_doesnt_exist'
test/compile_errors/stage1/obj/undefined_as_field_type_is_rejected.zig deleted-13
......@@ -1,13 +0,0 @@
1const Foo = struct {
2 a: undefined,
3};
4export fn entry1() void {
5 const foo: Foo = undefined;
6 _ = foo;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:8: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/undefined_function_call.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn a() void {
2 b();
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/underscore_is_not_a_declarable_symbol.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f1() usize {
2 var _: usize = 2;
3 return _;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_for.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn returns() void {
2 for ([_]void{}) |_, i| {
3 for ([_]void{}) |_, j| {
4 return _;
5 }
6 }
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn returns() void {
2 while (optionalReturn()) |_| {
3 while (optionalReturn()) |_| {
4 return _;
5 }
6 }
7}
8fn optionalReturn() ?u32 {
9 return 1;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:4:20: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/underscore_should_not_be_usable_inside_while_else.zig deleted-18
......@@ -1,18 +0,0 @@
1export fn returns() void {
2 while (optionalReturnError()) |_| {
3 while (optionalReturnError()) |_| {
4 return;
5 } else |_| {
6 if (_ == error.optionalReturnError) return;
7 }
8 }
9}
10fn optionalReturnError() !?u32 {
11 return error.optionalReturnError;
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:17: error: '_' used as an identifier without @"_" syntax
test/compile_errors/stage1/obj/union_auto-enum_value_already_taken.zig deleted-18
......@@ -1,18 +0,0 @@
1const MultipleChoice = union(enum(u32)) {
2 A = 20,
3 B = 40,
4 C = 60,
5 D = 1000,
6 E = 60,
7};
8export fn entry() void {
9 var x = MultipleChoice { .C = {} };
10 _ = x;
11}
12
13// error
14// backend=stage1
15// target=native
16//
17// tmp.zig:6:9: error: enum tag value 60 already taken
18// tmp.zig:4:9: note: other occurrence here
test/compile_errors/stage1/obj/union_enum_field_does_not_match_enum.zig deleted-22
......@@ -1,22 +0,0 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = union(Letter) {
7 A: i32,
8 B: f64,
9 C: bool,
10 D: bool,
11};
12export fn entry() void {
13 var a = Payload {.A = 1234};
14 _ = a;
15}
16
17// error
18// backend=stage1
19// target=native
20//
21// tmp.zig:10:5: error: enum field not found: 'D'
22// tmp.zig:1:16: note: enum declared here
test/compile_errors/stage1/obj/union_fields_with_value_assignments.zig deleted-14
......@@ -1,14 +0,0 @@
1const MultipleChoice = union {
2 A: i32 = 20,
3};
4export fn entry() void {
5 var x: MultipleChoice = undefined;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:24: error: explicitly valued tagged union missing integer tag type
14// tmp.zig:2:14: note: tag value specified here
test/compile_errors/stage1/obj/union_with_0_fields.zig deleted-7
......@@ -1,7 +0,0 @@
1const Foo = union {};
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:13: error: union declarations must have at least one tag
test/compile_errors/stage1/obj/union_with_specified_enum_omits_field.zig deleted-19
......@@ -1,19 +0,0 @@
1const Letter = enum {
2 A,
3 B,
4 C,
5};
6const Payload = union(Letter) {
7 A: i32,
8 B: f64,
9};
10export fn entry() usize {
11 return @sizeOf(Payload);
12}
13
14// error
15// backend=stage1
16// target=native
17//
18// tmp.zig:6:17: error: enum field missing: 'C'
19// tmp.zig:4:5: note: declared here
test/compile_errors/stage1/obj/union_with_too_small_explicit_signed_tag_type.zig deleted-16
......@@ -1,16 +0,0 @@
1const U = union(enum(i2)) {
2 A: u8,
3 B: u8,
4 C: u8,
5 D: u8,
6};
7export fn entry() void {
8 _ = U{ .D = 1 };
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:1:22: error: specified integer tag type cannot represent every field
16// tmp.zig:1:22: note: type i2 cannot fit values in range 0...3
test/compile_errors/stage1/obj/union_with_too_small_explicit_unsigned_tag_type.zig deleted-17
......@@ -1,17 +0,0 @@
1const U = union(enum(u2)) {
2 A: u8,
3 B: u8,
4 C: u8,
5 D: u8,
6 E: u8,
7};
8export fn entry() void {
9 _ = U{ .E = 1 };
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:1:22: error: specified integer tag type cannot represent every field
17// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
test/compile_errors/stage1/obj/unknown_length_pointer_to_opaque.zig deleted-7
......@@ -1,7 +0,0 @@
1export const T = [*]opaque {};
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:21: error: unknown-length pointer to opaque
test/compile_errors/stage1/obj/unreachable_code-double_break.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn a() void {
2 const b = blk: {
3 break :blk break :blk @as(u32, 1);
4 };
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: unreachable code
12// tmp.zig:3:20: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_code-nested_returns.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn a() i32 {
2 return return 1;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: unreachable code
10// tmp.zig:2:12: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_code.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn a() void {
2 return;
3 b();
4}
5
6fn b() void {}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:3:6: error: unreachable code
13// tmp.zig:2:5: note: control flow is diverted here
test/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig deleted-16
......@@ -1,16 +0,0 @@
1fn foo(comptime x: i32) i32 {
2 comptime {
3 if (x >= 0) return -x;
4 unreachable;
5 }
6}
7export fn entry() void {
8 _ = foo(-42);
9}
10
11// error
12// backend=stage1
13// target=native
14//
15// tmp.zig:4:9: error: reached unreachable code
16// tmp.zig:8:12: note: called from here
test/compile_errors/stage1/obj/unreachable_parameter.zig deleted-8
......@@ -1,8 +0,0 @@
1fn f(a: noreturn) void { _ = a; }
2export fn entry() void { f(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:9: error: parameter of type 'noreturn' not allowed
test/compile_errors/stage1/obj/unreachable_variable.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() void {
2 const a: noreturn = {};
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:25: error: expected type 'noreturn', found 'void'
test/compile_errors/stage1/obj/unreachable_with_return.zig deleted-8
......@@ -1,8 +0,0 @@
1fn a() noreturn {return;}
2export fn entry() void { a(); }
3
4// error
5// backend=stage1
6// target=native
7//
8// tmp.zig:1:18: error: expected type 'noreturn', found 'void'
test/compile_errors/stage1/obj/unsupported_modifier_at_start_of_asm_output_constraint.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 var bar: u32 = 3;
3 asm volatile ("" : [baz]"+r"(bar) : : "");
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215
test/compile_errors/stage1/obj/unused_variable_error_on_errdefer.zig deleted-13
......@@ -1,13 +0,0 @@
1fn foo() !void {
2 errdefer |a| unreachable;
3 return error.A;
4}
5export fn entry() void {
6 foo() catch unreachable;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:2:15: error: unused variable: 'a'
test/compile_errors/stage1/obj/use_anyopaque_as_return_type_of_fn_ptr.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const a: fn () anyopaque = undefined;
3 _ = a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:20: error: return type cannot be opaque
test/compile_errors/stage1/obj/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 var x: i32 = 1234;
3 var p: *i32 = &x;
4 var pp: *?*i32 = &p;
5 pp.* = null;
6 var y = p.*;
7 _ = y;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:4:23: error: expected type '*?*i32', found '**i32'
test/compile_errors/stage1/obj/use_invalid_number_literal_as_array_index.zig deleted-11
......@@ -1,11 +0,0 @@
1var v = 25;
2export fn entry() void {
3 var arr: [v]u8 = undefined;
4 _ = arr;
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:1: error: unable to infer variable type
test/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig deleted-13
......@@ -1,13 +0,0 @@
1const Cmd = struct {
2 exec: fn () void,
3};
4export fn entry() void {
5 const command = Cmd{ .exec = undefined };
6 command.exec();
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:6:12: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/use_of_undeclared_identifier.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn f() void {
2 b = 3;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: use of undeclared identifier 'b'
test/compile_errors/stage1/obj/using_an_unknown_len_ptr_type_instead_of_array.zig deleted-13
......@@ -1,13 +0,0 @@
1const resolutions = [*][*]const u8{
2 "[320 240 ]",
3 null,
4};
5comptime {
6 _ = resolutions;
7}
8
9// error
10// backend=stage1
11// target=native
12//
13// tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'
test/compile_errors/stage1/obj/using_invalid_types_in_function_call_raises_an_error.zig deleted-11
......@@ -1,11 +0,0 @@
1const MenuEffect = enum {};
2fn func(effect: MenuEffect) void { _ = effect; }
3export fn entry() void {
4 func(MenuEffect.ThisDoesNotExist);
5}
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:20: error: enum declarations must have at least one tag
test/compile_errors/stage1/obj/usingnamespace_with_wrong_type.zig deleted-7
......@@ -1,7 +0,0 @@
1usingnamespace void;
2
3// error
4// backend=stage1
5// target=native
6//
7// tmp.zig:1:1: error: expected struct, enum, or union; found 'void'
test/compile_errors/stage1/obj/variable_has_wrong_type.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn f() i32 {
2 const a = "a";
3 return a;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'
test/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var sp = asm volatile ("mov %[foo], sp"
3 : [bar] "=r" (-> usize),
4 );
5 _ = sp;
6}
7
8// error
9// backend=stage1
10// target=x86_64-linux-gnu
11//
12// tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs
test/compile_errors/stage1/obj/variable_initialization_compile_error_then_referenced.zig deleted-19
......@@ -1,19 +0,0 @@
1fn Undeclared() type {
2 return T;
3}
4fn Gen() type {
5 const X = Undeclared();
6 return struct {
7 x: X,
8 };
9}
10export fn entry() void {
11 const S = Gen();
12 _ = S;
13}
14
15// error
16// backend=stage1
17// target=native
18//
19// tmp.zig:2:12: error: use of undeclared identifier 'T'
test/compile_errors/stage1/obj/variable_with_type_noreturn.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry9() void {
2 var z: noreturn = return;
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:5: error: unreachable code
10// tmp.zig:2:23: note: control flow is diverted here
test/compile_errors/stage1/obj/vector_index_out_of_bounds.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 const x = @import("std").meta.Vector(3, f32){ 25, 75, 5, 0 };
3 _ = x;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:62: error: index 3 outside vector of size 3
test/compile_errors/stage1/obj/volatile_on_global_assembly.zig deleted-9
......@@ -1,9 +0,0 @@
1comptime {
2 asm volatile ("");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:9: error: volatile is meaningless on global assembly
test/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 _ = @wasmMemoryGrow(0, 1);
3 return;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only
test/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 _ = @wasmMemorySize(0);
3 return;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only
test/compile_errors/stage1/obj/while_expected_bool_got_error_union.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 while (bar()) {}
3}
4fn bar() anyerror!i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'
test/compile_errors/stage1/obj/while_expected_bool_got_optional.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 while (bar()) {}
3}
4fn bar() ?i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected type 'bool', found '?i32'
test/compile_errors/stage1/obj/while_expected_error_union_got_bool.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;} else |err| {_ = err;}
3}
4fn bar() bool { return true; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected error union type, found 'bool'
test/compile_errors/stage1/obj/while_expected_error_union_got_optional.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;} else |err| {_ = err;}
3}
4fn bar() ?i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected error union type, found '?i32'
test/compile_errors/stage1/obj/while_expected_optional_got_bool.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;}
3}
4fn bar() bool { return true; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected optional type, found 'bool'
test/compile_errors/stage1/obj/while_expected_optional_got_error_union.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn foo() void {
2 while (bar()) |x| {_ = x;}
3}
4fn bar() anyerror!i32 { return 1; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'
test/compile_errors/stage1/obj/while_loop_body_expression_ignored.zig deleted-22
......@@ -1,22 +0,0 @@
1fn returns() usize {
2 return 2;
3}
4export fn f1() void {
5 while (true) returns();
6}
7export fn f2() void {
8 var x: ?i32 = null;
9 while (x) |_| returns();
10}
11export fn f3() void {
12 var x: anyerror!i32 = error.Bad;
13 while (x) |_| returns() else |_| unreachable;
14}
15
16// error
17// backend=stage1
18// target=native
19//
20// tmp.zig:5:25: error: expression value is ignored
21// tmp.zig:9:26: error: expression value is ignored
22// tmp.zig:13:26: error: expression value is ignored
test/compile_errors/stage1/obj/write_to_const_global_variable.zig deleted-11
......@@ -1,11 +0,0 @@
1const x : i32 = 99;
2fn f() void {
3 x = 1;
4}
5export fn entry() void { f(); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:3:9: error: cannot assign to constant
test/compile_errors/stage1/obj/wrong_frame_type_used_for_async_call.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 var frame: @Frame(foo) = undefined;
3 frame = async bar();
4}
5fn foo() void {
6 suspend {}
7}
8fn bar() void {
9 suspend {}
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'
test/compile_errors/stage1/obj/wrong_function_type.zig deleted-11
......@@ -1,11 +0,0 @@
1const fns = [_]fn() void { a, b, c };
2fn a() i32 {return 0;}
3fn b() i32 {return 1;}
4fn c() i32 {return 2;}
5export fn entry() usize { return @sizeOf(@TypeOf(fns)); }
6
7// error
8// backend=stage1
9// target=native
10//
11// tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'
test/compile_errors/stage1/obj/wrong_initializer_for_union_payload_of_type_type.zig deleted-16
......@@ -1,16 +0,0 @@
1const U = union(enum) {
2 A: type,
3};
4const S = struct {
5 u: U,
6};
7export fn entry() void {
8 comptime var v: S = undefined;
9 v.u.A = U{ .A = i32 };
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:9:8: error: use of undefined value here causes undefined behavior
test/compile_errors/stage1/obj/wrong_number_of_arguments.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn a() void {
2 c(1);
3}
4fn c(d: i32, e: i32, f: i32) void { _ = d; _ = e; _ = f; }
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:6: error: expected 3 argument(s), found 1
test/compile_errors/stage1/obj/wrong_number_of_arguments_for_method_fn_call.zig deleted-14
......@@ -1,14 +0,0 @@
1const Foo = struct {
2 fn method(self: *const Foo, a: i32) void {_ = self; _ = a;}
3};
4fn f(foo: *const Foo) void {
5
6 foo.method(1, 2);
7}
8export fn entry() usize { return @sizeOf(@TypeOf(f)); }
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:6:15: error: expected 2 argument(s), found 3
test/compile_errors/stage1/obj/wrong_panic_signature_generic_function.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
2 _ = msg; _ = error_return_trace;
3 while (true) {}
4}
5const builtin = @import("std").builtin;
6
7// error
8// backend=stage1
9// target=native
10//
11// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,anytype) anytype'
12// note: only one of the functions is generic
test/compile_errors/stage1/obj/wrong_panic_signature_runtime_function.zig deleted-10
......@@ -1,10 +0,0 @@
1test "" {}
2
3pub fn panic() void {}
4
5
6// error
7// backend=stage1
8// target=native
9//
10// error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'
test/compile_errors/stage1/obj/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig deleted-12
......@@ -1,12 +0,0 @@
1const Derp = opaque {};
2extern fn bar(d: *Derp) void;
3export fn foo() void {
4 var x = @as(u8, 1);
5 bar(@ptrCast(*anyopaque, &x));
6}
7
8// error
9// backend=stage1
10// target=native
11//
12// tmp.zig:5:9: error: expected type '*Derp', found '*anyopaque'
test/compile_errors/stage1/obj/wrong_return_type_for_main.zig deleted-7
......@@ -1,7 +0,0 @@
1pub fn main() f32 { }
2
3// error
4// backend=stage1
5// target=native
6//
7// error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'
test/compile_errors/stage1/obj/wrong_size_to_an_array_literal.zig deleted-10
......@@ -1,10 +0,0 @@
1comptime {
2 const array = [2]u8{1, 2, 3};
3 _ = array;
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:2:31: error: index 2 outside array of size 2
test/compile_errors/stage1/obj/wrong_type_for_argument_tuple_to_asyncCall.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry1() void {
2 var frame: @Frame(foo) = undefined;
3 @asyncCall(&frame, {}, foo, {});
4}
5
6fn foo() i32 {
7 return 0;
8}
9
10// error
11// backend=stage1
12// target=native
13//
14// tmp.zig:3:33: error: expected tuple or struct, found 'void'
test/compile_errors/stage1/obj/wrong_type_for_reify_type.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() void {
2 _ = @Type(0);
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int'
test/compile_errors/stage1/obj/wrong_type_for_result_ptr_to_asyncCall.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 _ = async amain();
3}
4fn amain() i32 {
5 var frame: @Frame(foo) = undefined;
6 return await @asyncCall(&frame, false, foo, .{});
7}
8fn foo() i32 {
9 return 1234;
10}
11
12// error
13// backend=stage1
14// target=native
15//
16// tmp.zig:6:37: error: expected type '*i32', found 'bool'
test/compile_errors/stage1/obj/wrong_type_passed_to_panic.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var e = error.Foo;
3 @panic(e);
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'
test/compile_errors/stage1/obj/wrong_type_to_hasField.zig deleted-9
......@@ -1,9 +0,0 @@
1export fn entry() bool {
2 return @hasField(i32, "hi");
3}
4
5// error
6// backend=stage1
7// target=native
8//
9// tmp.zig:2:22: error: type 'i32' does not support @hasField
test/compile_errors/stage1/obj/wrong_types_given_to_atomic_order_args_in_cmpxchg.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 var x: i32 = 1234;
3 while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'
test/compile_errors/stage1/obj/wrong_types_given_to_export.zig deleted-10
......@@ -1,10 +0,0 @@
1fn entry() callconv(.C) void { }
2comptime {
3 @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
4}
5
6// error
7// backend=stage1
8// target=native
9//
10// tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'
test/compile_errors/stage1/test/access_invalid_typeInfo_decl.zig deleted-11
......@@ -1,11 +0,0 @@
1const A = B;
2test "Crash" {
3 _ = @typeInfo(@This()).Struct.decls[0];
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:1:11: error: use of undeclared identifier 'B'
test/compile_errors/stage1/test/alignCast_of_zero_sized_types.zig deleted-28
......@@ -1,28 +0,0 @@
1export fn foo() void {
2 const a: *void = undefined;
3 _ = @alignCast(2, a);
4}
5export fn bar() void {
6 const a: ?*void = undefined;
7 _ = @alignCast(2, a);
8}
9export fn baz() void {
10 const a: []void = undefined;
11 _ = @alignCast(2, a);
12}
13export fn qux() void {
14 const a = struct {
15 fn a(comptime b: u32) void { _ = b; }
16 }.a;
17 _ = @alignCast(2, a);
18}
19
20// error
21// backend=stage1
22// target=native
23// is_test=1
24//
25// tmp.zig:3:23: error: cannot adjust alignment of zero sized type '*void'
26// tmp.zig:7:23: error: cannot adjust alignment of zero sized type '?*void'
27// tmp.zig:11:23: error: cannot adjust alignment of zero sized type '[]void'
28// tmp.zig:17:23: error: cannot adjust alignment of zero sized type 'fn(u32) anytype'
test/compile_errors/stage1/test/bad_splat_type.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 const c = 4;
3 var v = @splat(4, c);
4 _ = v;
5}
6
7// error
8// backend=stage1
9// target=native
10// is_test=1
11//
12// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid
test/compile_errors/stage1/test/binary_OR_operator_on_error_sets.zig deleted-13
......@@ -1,13 +0,0 @@
1pub const A = error.A;
2pub const AB = A | error.B;
3export fn entry() void {
4 var x: AB = undefined;
5 _ = x;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'
test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-always_inline.zig deleted-11
......@@ -1,11 +0,0 @@
1pub export fn entry() void {
2 var call_me: fn () void = undefined;
3 @call(.{ .modifier = .always_inline }, call_me, .{});
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/test/call_rejects_non_comptime-known_fn-compile_time.zig deleted-11
......@@ -1,11 +0,0 @@
1pub export fn entry() void {
2 var call_me: fn () void = undefined;
3 @call(.{ .modifier = .compile_time }, call_me, .{});
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:5: error: the specified modifier requires a comptime-known function
test/compile_errors/stage1/test/cast_between_optional_T_where_T_is_not_a_pointer.zig deleted-15
......@@ -1,15 +0,0 @@
1pub const fnty1 = ?fn (i8) void;
2pub const fnty2 = ?fn (u64) void;
3export fn entry() void {
4 var a: fnty1 = undefined;
5 var b: fnty2 = undefined;
6 a = b;
7}
8
9// error
10// backend=stage1
11// target=native
12// is_test=1
13//
14// tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'
15// tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'
test/compile_errors/stage1/test/combination_of_nosuspend_and_async.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn entry() void {
2 nosuspend {
3 const bar = async foo();
4 suspend {}
5 resume bar;
6 }
7}
8fn foo() void {}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:4:9: error: suspend inside nosuspend block
16// tmp.zig:2:5: note: nosuspend block here
test/compile_errors/stage1/test/comparison_of_non-tagged_union_and_enum_literal.zig deleted-14
......@@ -1,14 +0,0 @@
1export fn entry() void {
2 const U = union { A: u32, B: u64 };
3 var u = U{ .A = 42 };
4 var ok = u == .A;
5 _ = ok;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types
14// tmp.zig:2:15: note: type U is not a tagged union
test/compile_errors/stage1/test/comptime_vector_overflow_shows_the_index.zig deleted-14
......@@ -1,14 +0,0 @@
1comptime {
2 var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
3 var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
4 var x = a + b;
5 _ = x;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:4:15: error: operation caused overflow
14// tmp.zig:4:15: note: when computing vector element at index 2
test/compile_errors/stage1/test/duplicate_field_in_anonymous_struct_literal.zig deleted-19
......@@ -1,19 +0,0 @@
1export fn entry() void {
2 const anon = .{
3 .inner = .{
4 .a = .{
5 .something = "text",
6 },
7 .a = .{},
8 },
9 };
10 _ = anon;
11}
12
13// error
14// backend=stage1
15// target=native
16// is_test=1
17//
18// tmp.zig:7:13: error: duplicate field
19// tmp.zig:4:13: note: other field here
test/compile_errors/stage1/test/error_in_struct_initializer_doesnt_crash_the_compiler.zig deleted-15
......@@ -1,15 +0,0 @@
1pub export fn entry() void {
2 const bitfield = struct {
3 e: u8,
4 e: u8,
5 };
6 var a = .{@sizeOf(bitfield)};
7 _ = a;
8}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:4:9: error: duplicate struct field: 'e'
test/compile_errors/stage1/test/errors_in_for_loop_bodies_are_propagated.zig deleted-11
......@@ -1,11 +0,0 @@
1pub export fn entry() void {
2 var arr: [100]u8 = undefined;
3 for (arr) |bits| _ = @popCount(bits);
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:26: error: expected 2 arguments, found 1
test/compile_errors/stage1/test/export_with_empty_name_string.zig deleted-11
......@@ -1,11 +0,0 @@
1pub export fn entry() void { }
2comptime {
3 @export(entry, .{ .name = "" });
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:5: error: exported symbol name cannot be empty
test/compile_errors/stage1/test/helpful_return_type_error_message.zig deleted-30
......@@ -1,30 +0,0 @@
1export fn foo() u32 {
2 return error.Ohno;
3}
4fn bar() !u32 {
5 return error.Ohno;
6}
7export fn baz() void {
8 try bar();
9}
10export fn qux() u32 {
11 return bar();
12}
13export fn quux() u32 {
14 var buf: u32 = 0;
15 buf = bar();
16}
17
18// error
19// backend=stage1
20// target=native
21// is_test=1
22//
23// tmp.zig:2:17: error: expected type 'u32', found 'error{Ohno}'
24// tmp.zig:1:17: note: function cannot return an error
25// tmp.zig:8:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set'
26// tmp.zig:7:17: note: function cannot return an error
27// tmp.zig:11:15: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
28// tmp.zig:10:17: note: function cannot return an error
29// tmp.zig:15:14: error: cannot convert error union to payload type. consider using `try`, `catch`, or `if`. expected type 'u32', found '@typeInfo(@typeInfo(@TypeOf(bar)).Fn.return_type.?).ErrorUnion.error_set!u32'
30// tmp.zig:14:5: note: cannot store an error in type 'u32'
test/compile_errors/stage1/test/int-float_conversion_to_comptime_int-float.zig deleted-16
......@@ -1,16 +0,0 @@
1export fn foo() void {
2 var a: f32 = 2;
3 _ = @floatToInt(comptime_int, a);
4}
5export fn bar() void {
6 var a: u32 = 2;
7 _ = @intToFloat(comptime_float, a);
8}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:3:35: error: unable to evaluate constant expression
16// tmp.zig:7:37: error: unable to evaluate constant expression
test/compile_errors/stage1/test/invalid_assignments.zig deleted-20
......@@ -1,20 +0,0 @@
1export fn entry1() void {
2 var a: []const u8 = "foo";
3 a[0..2] = "bar";
4}
5export fn entry2() void {
6 var a: u8 = 2;
7 a + 2 = 3;
8}
9export fn entry4() void {
10 2 + 2 = 3;
11}
12
13// error
14// backend=stage1
15// target=native
16// is_test=1
17//
18// tmp.zig:3:6: error: invalid left-hand side to assignment
19// tmp.zig:7:7: error: invalid left-hand side to assignment
20// tmp.zig:10:7: error: invalid left-hand side to assignment
test/compile_errors/stage1/test/invalid_float_casts.zig deleted-26
......@@ -1,26 +0,0 @@
1export fn foo() void {
2 var a: f32 = 2;
3 _ = @floatCast(comptime_float, a);
4}
5export fn bar() void {
6 var a: f32 = 2;
7 _ = @floatToInt(f32, a);
8}
9export fn baz() void {
10 var a: f32 = 2;
11 _ = @intToFloat(f32, a);
12}
13export fn qux() void {
14 var a: u32 = 2;
15 _ = @floatCast(f32, a);
16}
17
18// error
19// backend=stage1
20// target=native
21// is_test=1
22//
23// tmp.zig:3:36: error: unable to evaluate constant expression
24// tmp.zig:7:21: error: expected integer type, found 'f32'
25// tmp.zig:11:26: error: expected int type, found 'f32'
26// tmp.zig:15:25: error: expected float type, found 'u32'
test/compile_errors/stage1/test/invalid_int_casts.zig deleted-26
......@@ -1,26 +0,0 @@
1export fn foo() void {
2 var a: u32 = 2;
3 _ = @intCast(comptime_int, a);
4}
5export fn bar() void {
6 var a: u32 = 2;
7 _ = @intToFloat(u32, a);
8}
9export fn baz() void {
10 var a: u32 = 2;
11 _ = @floatToInt(u32, a);
12}
13export fn qux() void {
14 var a: f32 = 2;
15 _ = @intCast(u32, a);
16}
17
18// error
19// backend=stage1
20// target=native
21// is_test=1
22//
23// tmp.zig:3:32: error: unable to evaluate constant expression
24// tmp.zig:7:21: error: expected float type, found 'u32'
25// tmp.zig:11:26: error: expected float type, found 'u32'
26// tmp.zig:15:23: error: expected integer type, found 'f32'
test/compile_errors/stage1/test/invalid_non-exhaustive_enum_to_union.zig deleted-27
......@@ -1,27 +0,0 @@
1const E = enum(u8) {
2 a,
3 b,
4 _,
5};
6const U = union(E) {
7 a,
8 b,
9};
10export fn foo() void {
11 var e = @intToEnum(E, 15);
12 var u: U = e;
13 _ = u;
14}
15export fn bar() void {
16 const e = @intToEnum(E, 15);
17 var u: U = e;
18 _ = u;
19}
20
21// error
22// backend=stage1
23// target=native
24// is_test=1
25//
26// tmp.zig:12:16: error: runtime cast to union 'U' from non-exhaustive enum
27// tmp.zig:17:16: error: no tag by value 15
test/compile_errors/stage1/test/invalid_pointer_with_reify_type.zig deleted-19
......@@ -1,19 +0,0 @@
1export fn entry() void {
2 _ = @Type(.{ .Pointer = .{
3 .size = .One,
4 .is_const = false,
5 .is_volatile = false,
6 .alignment = 1,
7 .address_space = .generic,
8 .child = u8,
9 .is_allowzero = false,
10 .sentinel = &@as(u8, 0),
11 }});
12}
13
14// error
15// backend=stage1
16// target=native
17// is_test=1
18//
19// tmp.zig:2:16: error: sentinels are only allowed on slices and unknown-length pointers
test/compile_errors/stage1/test/nested_vectors.zig deleted-13
......@@ -1,13 +0,0 @@
1export fn entry() void {
2 const V1 = @import("std").meta.Vector(4, u8);
3 const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
4 var v: V2 = undefined;
5 _ = v;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid
test/compile_errors/stage1/test/non-exhaustive_enum_marker_assigned_a_value.zig deleted-20
......@@ -1,20 +0,0 @@
1const A = enum {
2 a,
3 b,
4 _ = 1,
5};
6const B = enum {
7 a,
8 b,
9 _,
10};
11comptime { _ = A; _ = B; }
12
13// error
14// backend=stage1
15// target=native
16// is_test=1
17//
18// tmp.zig:4:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value
19// tmp.zig:6:11: error: non-exhaustive enum missing integer tag type
20// tmp.zig:9:5: note: marked non-exhaustive here
test/compile_errors/stage1/test/non-exhaustive_enums.zig deleted-22
......@@ -1,22 +0,0 @@
1const B = enum(u1) {
2 a,
3 _,
4 b,
5};
6const C = enum(u1) {
7 a,
8 b,
9 _,
10};
11pub export fn entry() void {
12 _ = B;
13 _ = C;
14}
15
16// error
17// backend=stage1
18// target=native
19// is_test=1
20//
21// tmp.zig:3:5: error: '_' field of non-exhaustive enum must be last
22// tmp.zig:6:11: error: non-exhaustive enum specifies every value
test/compile_errors/stage1/test/not_an_enum_type.zig deleted-20
......@@ -1,20 +0,0 @@
1export fn entry() void {
2 var self: Error = undefined;
3 switch (self) {
4 InvalidToken => |x| return x.token,
5 ExpectedVarDeclOrFn => |x| return x.token,
6 }
7}
8const Error = union(enum) {
9 A: InvalidToken,
10 B: ExpectedVarDeclOrFn,
11};
12const InvalidToken = struct {};
13const ExpectedVarDeclOrFn = struct {};
14
15// error
16// backend=stage1
17// target=native
18// is_test=1
19//
20// tmp.zig:4:9: error: expected type '@typeInfo(Error).Union.tag_type.?', found 'type'
test/compile_errors/stage1/test/packed_struct_with_fields_of_not_allowed_types.zig deleted-74
......@@ -1,74 +0,0 @@
1const A = packed struct {
2 x: anyerror,
3};
4const B = packed struct {
5 x: [2]u24,
6};
7const C = packed struct {
8 x: [1]anyerror,
9};
10const D = packed struct {
11 x: [1]S,
12};
13const E = packed struct {
14 x: [1]U,
15};
16const F = packed struct {
17 x: ?anyerror,
18};
19const G = packed struct {
20 x: Enum,
21};
22export fn entry1() void {
23 var a: A = undefined;
24 _ = a;
25}
26export fn entry2() void {
27 var b: B = undefined;
28 _ = b;
29}
30export fn entry3() void {
31 var r: C = undefined;
32 _ = r;
33}
34export fn entry4() void {
35 var d: D = undefined;
36 _ = d;
37}
38export fn entry5() void {
39 var e: E = undefined;
40 _ = e;
41}
42export fn entry6() void {
43 var f: F = undefined;
44 _ = f;
45}
46export fn entry7() void {
47 var g: G = undefined;
48 _ = g;
49}
50const S = struct {
51 x: i32,
52};
53const U = struct {
54 A: i32,
55 B: u32,
56};
57const Enum = enum {
58 A,
59 B,
60};
61
62// error
63// backend=stage1
64// target=native
65// is_test=1
66//
67// tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
68// tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits (must be padded from 48 to 64 bits)
69// tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation
70// tmp.zig:11:5: error: non-packed, non-extern struct 'S' not allowed in packed struct; no guaranteed in-memory representation
71// tmp.zig:14:5: error: non-packed, non-extern struct 'U' not allowed in packed struct; no guaranteed in-memory representation
72// tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation
73// tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation
74// tmp.zig:57:14: note: enum declaration does not specify an integer tag type
test/compile_errors/stage1/test/ptrToInt_with_pointer_to_zero-sized_type.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var pointer: ?*u0 = null;
3 var x = @ptrToInt(pointer);
4 _ = x;
5}
6
7// error
8// backend=stage1
9// target=native
10// is_test=1
11//
12// tmp.zig:3:23: error: pointer to size 0 type has no address
test/compile_errors/stage1/test/reassign_to_array_parameter.zig deleted-13
......@@ -1,13 +0,0 @@
1fn reassign(a: [3]f32) void {
2 a = [3]f32{4, 5, 6};
3}
4export fn entry() void {
5 reassign(.{1, 2, 3});
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:2:15: error: cannot assign to constant
test/compile_errors/stage1/test/reassign_to_slice_parameter.zig deleted-13
......@@ -1,13 +0,0 @@
1pub fn reassign(s: []const u8) void {
2 s = s[0..];
3}
4export fn entry() void {
5 reassign("foo");
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:2:10: error: cannot assign to constant
test/compile_errors/stage1/test/reassign_to_struct_parameter.zig deleted-16
......@@ -1,16 +0,0 @@
1const S = struct {
2 x: u32,
3};
4fn reassign(s: S) void {
5 s = S{.x = 2};
6}
7export fn entry() void {
8 reassign(S{.x = 3});
9}
10
11// error
12// backend=stage1
13// target=native
14// is_test=1
15//
16// tmp.zig:5:10: error: cannot assign to constant
test/compile_errors/stage1/test/reference_to_const_data.zig deleted-30
......@@ -1,30 +0,0 @@
1export fn foo() void {
2 var ptr = &[_]u8{0,0,0,0};
3 ptr[1] = 2;
4}
5export fn bar() void {
6 var ptr = &@as(u32, 2);
7 ptr.* = 2;
8}
9export fn baz() void {
10 var ptr = &true;
11 ptr.* = false;
12}
13export fn qux() void {
14 const S = struct{
15 x: usize,
16 y: usize,
17 };
18 var ptr = &S{.x=1,.y=2};
19 ptr.x = 2;
20}
21
22// error
23// backend=stage1
24// target=native
25// is_test=1
26//
27// tmp.zig:3:14: error: cannot assign to constant
28// tmp.zig:7:13: error: cannot assign to constant
29// tmp.zig:11:13: error: cannot assign to constant
30// tmp.zig:19:13: error: cannot assign to constant
test/compile_errors/stage1/test/reify_typeOf_with_incompatible_arguments.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 var var_1: f32 = undefined;
3 var var_2: u32 = undefined;
4 _ = @TypeOf(var_1, var_2);
5}
6
7// error
8// backend=stage1
9// target=native
10// is_test=1
11//
12// tmp.zig:4:9: error: incompatible types: 'f32' and 'u32'
test/compile_errors/stage1/test/reify_typeOf_with_no_arguments.zig deleted-10
......@@ -1,10 +0,0 @@
1export fn entry() void {
2 _ = @TypeOf();
3}
4
5// error
6// backend=stage1
7// target=native
8// is_test=1
9//
10// tmp.zig:2:9: error: expected at least 1 argument, found 0
test/compile_errors/stage1/test/reject_extern_function_definitions_with_body.zig deleted-10
......@@ -1,10 +0,0 @@
1extern "c" fn definitelyNotInLibC(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5// error
6// backend=stage1
7// target=native
8// is_test=1
9//
10// tmp.zig:1:1: error: extern functions have no body
test/compile_errors/stage1/test/reject_extern_variables_with_initializers.zig deleted-8
......@@ -1,8 +0,0 @@
1extern var foo: int = 2;
2
3// error
4// backend=stage1
5// target=native
6// is_test=1
7//
8// tmp.zig:1:23: error: extern variables have no initializers
test/compile_errors/stage1/test/repeated_invalid_field_access_to_generic_function_returning_type_crashes_compiler_2655.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn A() type {
2 return Q;
3}
4test "1" {
5 _ = A().a;
6 _ = A().a;
7}
8
9// error
10// backend=stage1
11// target=native
12// is_test=1
13//
14// tmp.zig:2:12: error: use of undeclared identifier 'Q'
test/compile_errors/stage1/test/return_invalid_type_from_test.zig deleted-8
......@@ -1,8 +0,0 @@
1test "example" { return 1; }
2
3// error
4// backend=stage1
5// target=native
6// is_test=1
7//
8// tmp.zig:1:25: error: expected type 'void', found 'comptime_int'
test/compile_errors/stage1/test/shift_on_type_with_non-power-of-two_size.zig deleted-34
......@@ -1,34 +0,0 @@
1export fn entry() void {
2 const S = struct {
3 fn a() void {
4 var x: u24 = 42;
5 _ = x >> 24;
6 }
7 fn b() void {
8 var x: u24 = 42;
9 _ = x << 24;
10 }
11 fn c() void {
12 var x: u24 = 42;
13 _ = @shlExact(x, 24);
14 }
15 fn d() void {
16 var x: u24 = 42;
17 _ = @shrExact(x, 24);
18 }
19 };
20 S.a();
21 S.b();
22 S.c();
23 S.d();
24}
25
26// error
27// backend=stage1
28// target=native
29// is_test=1
30//
31// tmp.zig:5:19: error: RHS of shift is too large for LHS type
32// tmp.zig:9:19: error: RHS of shift is too large for LHS type
33// tmp.zig:13:17: error: RHS of shift is too large for LHS type
34// tmp.zig:17:17: error: RHS of shift is too large for LHS type
test/compile_errors/stage1/test/shuffle_with_selected_index_past_first_vector_length.zig deleted-15
......@@ -1,15 +0,0 @@
1export fn entry() void {
2 const v: @import("std").meta.Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
3 const x: @import("std").meta.Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
4 var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
5 _ = z;
6}
7
8// error
9// backend=stage1
10// target=native
11// is_test=1
12//
13// tmp.zig:4:39: error: mask index '4' has out-of-bounds selection
14// tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)
15// tmp.zig:4:30: note: selections from the second vector are specified with negative numbers
test/compile_errors/stage1/test/switch_ranges_endpoints_are_validated.zig deleted-16
......@@ -1,16 +0,0 @@
1pub export fn entry() void {
2 var x: i32 = 0;
3 switch (x) {
4 6...1 => {},
5 -1...-5 => {},
6 else => unreachable,
7 }
8}
9
10// error
11// backend=stage1
12// target=native
13// is_test=1
14//
15// tmp.zig:4:9: error: range start value is greater than the end value
16// tmp.zig:5:9: error: range start value is greater than the end value
test/compile_errors/stage1/test/switching_with_exhaustive_enum_has___prong_.zig deleted-19
......@@ -1,19 +0,0 @@
1const E = enum{
2 a,
3 b,
4};
5pub export fn entry() void {
6 var e: E = .b;
7 switch (e) {
8 .a => {},
9 .b => {},
10 _ => {},
11 }
12}
13
14// error
15// backend=stage1
16// target=native
17// is_test=1
18//
19// tmp.zig:7:5: error: switch on exhaustive enum has `_` prong
test/compile_errors/stage1/test/switching_with_non-exhaustive_enums.zig deleted-35
......@@ -1,35 +0,0 @@
1const E = enum(u8) {
2 a,
3 b,
4 _,
5};
6const U = union(E) {
7 a: i32,
8 b: u32,
9};
10pub export fn entry() void {
11 var e: E = .b;
12 switch (e) { // error: switch not handling the tag `b`
13 .a => {},
14 _ => {},
15 }
16 switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
17 .a => {},
18 .b => {},
19 }
20 var u = U{.a = 2};
21 switch (u) { // error: `_` prong not allowed when switching on tagged union
22 .a => {},
23 .b => {},
24 _ => {},
25 }
26}
27
28// error
29// backend=stage1
30// target=native
31// is_test=1
32//
33// tmp.zig:12:5: error: enumeration value 'E.b' not handled in switch
34// tmp.zig:16:5: error: switch on non-exhaustive enum must include `else` or `_` prong
35// tmp.zig:21:5: error: `_` prong not allowed when switching on tagged union
test/compile_errors/stage1/test/tagName_on_invalid_value_of_non-exhaustive_enum.zig deleted-11
......@@ -1,11 +0,0 @@
1test "enum" {
2 const E = enum(u8) {A, B, _};
3 _ = @tagName(@intToEnum(E, 5));
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:18: error: no tag by value 5
test/compile_errors/stage1/test/type_mismatch_in_C_prototype_with_varargs.zig deleted-14
......@@ -1,14 +0,0 @@
1const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void;
2extern fn fn_decl(fmt: [*:0]u8, ...) void;
3
4export fn main() void {
5 const x: fn_ty = fn_decl;
6 _ = x;
7}
8
9// error
10// backend=stage1
11// target=native
12// is_test=1
13//
14// tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'
test/compile_errors/stage1/test/type_mismatch_with_tuple_concatenation.zig deleted-11
......@@ -1,11 +0,0 @@
1export fn entry() void {
2 var x = .{};
3 x = x ++ .{ 1, 2, 3 };
4}
5
6// error
7// backend=stage1
8// target=native
9// is_test=1
10//
11// tmp.zig:3:11: error: expected type 'struct:2:14', found 'struct:3:11'
test/compile_errors/stage2/comptime_unreachable.zig deleted-7
......@@ -1,7 +0,0 @@
1pub export fn entry() void {
2 comptime unreachable;
3}
4
5// error
6//
7// :2:14: error: reached unreachable code
test/compile_errors/stage2/constant_inside_comptime_function_has_compile_error.zig deleted-21
......@@ -1,21 +0,0 @@
1const ContextAllocator = MemoryPool(usize);
2
3pub fn MemoryPool(comptime T: type) type {
4 const free_list_t = @compileError("aoeu",);
5 _ = T;
6
7 return struct {
8 free_list: free_list_t,
9 };
10}
11
12export fn entry() void {
13 var allocator: ContextAllocator = undefined;
14 _ = allocator;
15}
16
17// error
18// target=native
19//
20// :4:5: error: unreachable code
21// :4:25: note: control flow is diverted here
test/compile_errors/stage2/duplicate-unused_labels.zig deleted-31
......@@ -1,31 +0,0 @@
1comptime {
2 blk: { blk: while (false) {} }
3}
4comptime {
5 blk: while (false) { blk: for (@as([0]void, undefined)) |_| {} }
6}
7comptime {
8 blk: for (@as([0]void, undefined)) |_| { blk: {} }
9}
10comptime {
11 blk: {}
12}
13comptime {
14 blk: while(false) {}
15}
16comptime {
17 blk: for(@as([0]void, undefined)) |_| {}
18}
19
20// error
21// target=native
22//
23// :2:12: error: redefinition of label 'blk'
24// :2:5: note: previous definition here
25// :5:26: error: redefinition of label 'blk'
26// :5:5: note: previous definition here
27// :8:46: error: redefinition of label 'blk'
28// :8:5: note: previous definition here
29// :11:5: error: unused block label
30// :14:5: error: unused while loop label
31// :17:5: error: unused for loop label
test/compile_errors/stage2/embed_outside_package.zig deleted-8
......@@ -1,8 +0,0 @@
1export fn a() usize {
2 return @embedFile("/root/foo").len;
3}
4
5// error
6// target=native
7//
8//:2:23: error: embed of file outside package path: '/root/foo'
test/compile_errors/stage2/import_outside_package.zig deleted-8
......@@ -1,8 +0,0 @@
1export fn a() usize {
2 return @import("../../above.zig").len;
3}
4
5// error
6// target=native
7//
8// :2:20: error: import of file outside package path: '../../above.zig'
test/compile_errors/stage2/out_of_bounds_index.zig deleted-29
......@@ -1,29 +0,0 @@
1comptime {
2 var array = [_:0]u8{ 1, 2, 3, 4 };
3 var src_slice: [:0]u8 = &array;
4 var slice = src_slice[2..6];
5 _ = slice;
6}
7comptime {
8 var array = [_:0]u8{ 1, 2, 3, 4 };
9 var slice = array[2..6];
10 _ = slice;
11}
12comptime {
13 var array = [_]u8{ 1, 2, 3, 4 };
14 var slice = array[2..5];
15 _ = slice;
16}
17comptime {
18 var array = [_:0]u8{ 1, 2, 3, 4 };
19 var slice = array[3..2];
20 _ = slice;
21}
22
23// error
24// target=native
25//
26// :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
27// :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
28// :14:22: error: end index 5 out of bounds for array of length 4
29// :19:22: error: start index 3 is larger than end index 2
test/compile_errors/stage2/slice_of_null_pointer.zig deleted-11
......@@ -1,11 +0,0 @@
1comptime {
2 var x: [*c]u8 = null;
3 var runtime_len: usize = 0;
4 var y = x[0..runtime_len];
5 _ = y;
6}
7
8// error
9// target=native
10//
11// :4:14: error: slice of null pointer
test/compile_errors/stage2/struct_duplicate_field_name.zig deleted-16
......@@ -1,16 +0,0 @@
1const S = struct {
2 foo: u32,
3 foo: u32,
4};
5
6export fn entry() void {
7 const s: S = .{ .foo = 100 };
8 _ = s;
9}
10
11// error
12// target=native
13//
14// :3:5: error: duplicate struct field: 'foo'
15// :2:5: note: other field here
16// :1:11: note: struct declared here
test/compile_errors/stage2/union_access_of_inactive_field.zig deleted-15
......@@ -1,15 +0,0 @@
1const U = union {
2 a: void,
3 b: u64,
4};
5comptime {
6 var u: U = .{ .a = {} };
7 const v = u.b;
8 _ = v;
9}
10
11// error
12// target=native
13//
14// :7:16: error: access of union field 'b' while field 'a' is active
15// :1:11: note: union declared here
test/compile_errors/stage2/union_duplicate_enum_field.zig deleted-17
......@@ -1,17 +0,0 @@
1const E = enum { a, b };
2const U = union(E) {
3 a: u32,
4 a: u32,
5};
6
7export fn foo() void {
8 var u: U = .{ .a = 123 };
9 _ = u;
10}
11
12// error
13// target=native
14//
15// :4:5: error: duplicate union field: 'a'
16// :3:5: note: other field here
17// :2:11: note: union declared here
test/compile_errors/stage2/union_duplicate_field_definition.zig deleted-16
......@@ -1,16 +0,0 @@
1const U = union {
2 foo: u32,
3 foo: u32,
4};
5
6export fn entry() void {
7 const u: U = .{ .foo = 100 };
8 _ = u;
9}
10
11// error
12// target=native
13//
14// :3:5: error: duplicate union field: 'foo'
15// :2:5: note: other field here
16// :1:11: note: union declared here
test/compile_errors/stage2/union_enum_field_missing.zig deleted-21
......@@ -1,21 +0,0 @@
1const E = enum {
2 a,
3 b,
4 c,
5};
6
7const U = union(E) {
8 a: i32,
9 b: f64,
10};
11
12export fn entry() usize {
13 return @sizeOf(U);
14}
15
16// error
17// target=native
18//
19// :7:1: error: enum field(s) missing in union
20// :4:5: note: field 'c' missing, declared here
21// :1:11: note: enum declared here
test/compile_errors/stage2/union_extra_field.zig deleted-20
......@@ -1,20 +0,0 @@
1const E = enum {
2 a,
3 b,
4 c,
5};
6const U = union(E) {
7 a: i32,
8 b: f64,
9 c: f64,
10 d: f64,
11};
12export fn entry() usize {
13 return @sizeOf(U);
14}
15
16// error
17// target=native
18//
19// :6:1: error: enum 'tmp.E' has no field named 'd'
20// :1:11: note: enum declared here
test/compile_errors/stage2/union_runtime_coercion_from_enum.zig deleted-23
......@@ -1,23 +0,0 @@
1const E = enum {
2 a,
3 b,
4};
5const U = union(E) {
6 a: u32,
7 b: u64,
8};
9fn foo() E {
10 return E.b;
11}
12export fn doTheTest() u64 {
13 var u: U = foo();
14 return u.b;
15}
16
17// error
18// target=native
19//
20// :13:19: error: runtime coercion from enum 'tmp.E' to union 'tmp.U' which has non-void fields
21// :6:5: note: field 'a' has type 'u32'
22// :7:5: note: field 'b' has type 'u64'
23// :5:11: note: union declared here
test/incremental/aarch64-linux/conditional_branches.0.zig deleted-26
......@@ -1,26 +0,0 @@
1pub fn main() void {
2 foo(123);
3}
4
5fn foo(x: u64) void {
6 if (x > 42) {
7 print();
8 }
9}
10
11fn print() void {
12 asm volatile ("svc #0"
13 :
14 : [number] "{x8}" (64),
15 [arg1] "{x0}" (1),
16 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
17 [arg3] "{x2}" ("Hello, World!\n".len),
18 : "memory", "cc"
19 );
20}
21
22// run
23// target=aarch64-linux
24//
25// Hello, World!
26//
test/incremental/aarch64-linux/conditional_branches.1.zig deleted-25
......@@ -1,25 +0,0 @@
1pub fn main() void {
2 foo(true);
3}
4
5fn foo(x: bool) void {
6 if (x) {
7 print();
8 }
9}
10
11fn print() void {
12 asm volatile ("svc #0"
13 :
14 : [number] "{x8}" (64),
15 [arg1] "{x0}" (1),
16 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
17 [arg3] "{x2}" ("Hello, World!\n".len),
18 : "memory", "cc"
19 );
20}
21
22// run
23//
24// Hello, World!
25//
test/incremental/aarch64-linux/hello_world_with_updates.0.zig deleted-31
......@@ -1,31 +0,0 @@
1pub export fn _start() noreturn {
2 print();
3 exit(0);
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{x8}" (64),
10 [arg1] "{x0}" (1),
11 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{x2}" ("Hello, World!\n".len),
13 : "memory", "cc"
14 );
15}
16
17fn exit(ret: usize) noreturn {
18 asm volatile ("svc #0"
19 :
20 : [number] "{x8}" (93),
21 [arg1] "{x0}" (ret),
22 : "memory", "cc"
23 );
24 unreachable;
25}
26
27// run
28// target=aarch64-linux
29//
30// Hello, World!
31//
test/incremental/aarch64-linux/hello_world_with_updates.1.zig deleted-36
......@@ -1,36 +0,0 @@
1pub export fn _start() noreturn {
2 print();
3 print();
4 print();
5 print();
6 exit(0);
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{x8}" (64),
13 [arg1] "{x0}" (1),
14 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{x2}" ("Hello, World!\n".len),
16 : "memory", "cc"
17 );
18}
19
20fn exit(ret: usize) noreturn {
21 asm volatile ("svc #0"
22 :
23 : [number] "{x8}" (93),
24 [arg1] "{x0}" (ret),
25 : "memory", "cc"
26 );
27 unreachable;
28}
29
30// run
31//
32// Hello, World!
33// Hello, World!
34// Hello, World!
35// Hello, World!
36//
test/incremental/aarch64-linux/hello_world_with_updates.2.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{x8}" (64),
10 [arg1] "{x0}" (1),
11 [arg2] "{x1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{x2}" ("Hello, World!\n".len),
13 : "memory", "cc"
14 );
15}
16
17// run
18//
19// Hello, World!
20// Hello, World!
21//
test/incremental/aarch64-macos/hello_world_with_updates.0.zig deleted-5
......@@ -1,5 +0,0 @@
1// error
2// output_mode=Exe
3// target=aarch64-macos
4//
5// :107:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/aarch64-macos/hello_world_with_updates.1.zig deleted-5
......@@ -1,5 +0,0 @@
1pub export fn main() noreturn {}
2
3// error
4//
5// :1:32: error: expected noreturn, found void
test/incremental/aarch64-macos/hello_world_with_updates.2.zig deleted-19
......@@ -1,19 +0,0 @@
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/aarch64-macos/hello_world_with_updates.3.zig deleted-16
......@@ -1,16 +0,0 @@
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/aarch64-macos/hello_world_with_updates.4.zig deleted-22
......@@ -1,22 +0,0 @@
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/aarch64-macos/hello_world_with_updates.5.zig deleted-16
......@@ -1,16 +0,0 @@
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/aarch64-macos/hello_world_with_updates.6.zig deleted-18
......@@ -1,18 +0,0 @@
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/adding_numbers_at_runtime_and_comptime.0.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 if (a + b != 7) unreachable;
7}
8
9// run
10//
test/incremental/adding_numbers_at_runtime_and_comptime.1.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 if (x - 7 != 0) unreachable;
3}
4
5fn add(a: u32, b: u32) u32 {
6 return a + b;
7}
8
9const x = add(3, 4);
10
11// run
12//
test/incremental/adding_numbers_at_runtime_and_comptime.2.zig deleted-12
......@@ -1,12 +0,0 @@
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 return a + b + c;
9}
10
11// run
12//
test/incremental/ambiguous_reference.zig deleted-13
......@@ -1,13 +0,0 @@
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/arm-linux/arithmetic_operations.0.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 print(2, 4);
3 print(1, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a + b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19// target=arm-linux
20//
21// 12345612345678
test/incremental/arm-linux/arithmetic_operations.1.zig deleted-20
......@@ -1,20 +0,0 @@
1pub fn main() void {
2 print(10, 5);
3 print(4, 3);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a - b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 123451
test/incremental/arm-linux/arithmetic_operations.2.zig deleted-20
......@@ -1,20 +0,0 @@
1pub fn main() void {
2 print(8, 9);
3 print(3, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a & b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 12345678123
test/incremental/arm-linux/arithmetic_operations.3.zig deleted-20
......@@ -1,20 +0,0 @@
1pub fn main() void {
2 print(4, 2);
3 print(3, 7);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a | b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 1234561234567
test/incremental/arm-linux/arithmetic_operations.4.zig deleted-20
......@@ -1,20 +0,0 @@
1pub fn main() void {
2 print(42, 42);
3 print(3, 5);
4}
5
6fn print(a: u32, b: u32) void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg3] "{r2}" (a ^ b),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("123456789")),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// 123456
test/incremental/arm-linux/arithmetic_operations.5.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 var x: u32 = 1;
3 assert(x << 1 == 2);
4
5 x <<= 1;
6 assert(x << 2 == 8);
7 assert(x << 3 == 16);
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/incremental/arm-linux/arithmetic_operations.6.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 var a: u32 = 1024;
3 assert(a >> 1 == 512);
4
5 a >>= 1;
6 assert(a >> 2 == 128);
7 assert(a >> 3 == 64);
8 assert(a >> 4 == 32);
9 assert(a >> 5 == 16);
10 assert(a >> 6 == 8);
11 assert(a >> 7 == 4);
12 assert(a >> 8 == 2);
13 assert(a >> 9 == 1);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/incremental/arm-linux/errors.0.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 foo() catch print();
3}
4
5fn foo() anyerror!void {}
6
7fn print() void {
8 asm volatile ("svc #0"
9 :
10 : [number] "{r7}" (4),
11 [arg1] "{r0}" (1),
12 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
13 [arg3] "{r2}" ("Hello, World!\n".len),
14 : "memory"
15 );
16 return;
17}
18
19// run
20// target=arm-linux
21//
test/incremental/arm-linux/errors.1.zig deleted-24
......@@ -1,24 +0,0 @@
1pub fn main() void {
2 foo() catch print();
3}
4
5fn foo() anyerror!void {
6 return error.Test;
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{r7}" (4),
13 [arg1] "{r0}" (1),
14 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{r2}" ("Hello, World!\n".len),
16 : "memory"
17 );
18 return;
19}
20
21// run
22//
23// Hello, World!
24//
test/incremental/arm-linux/errors.2.zig deleted-27
......@@ -1,27 +0,0 @@
1pub fn main() void {
2 foo() catch |err| {
3 assert(err == error.Foo);
4 assert(err != error.Bar);
5 assert(err != error.Baz);
6 };
7 bar() catch |err| {
8 assert(err != error.Foo);
9 assert(err == error.Bar);
10 assert(err != error.Baz);
11 };
12}
13
14fn assert(ok: bool) void {
15 if (!ok) unreachable;
16}
17
18fn foo() anyerror!void {
19 return error.Foo;
20}
21
22fn bar() anyerror!void {
23 return error.Bar;
24}
25
26// run
27//
test/incremental/arm-linux/errors.3.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 foo() catch unreachable;
3}
4
5fn foo() anyerror!void {
6 try bar();
7}
8
9fn bar() anyerror!void {}
10
11// run
12//
test/incremental/arm-linux/function_pointers.zig deleted-44
......@@ -1,44 +0,0 @@
1const PrintFn = *const fn () void;
2
3pub fn main() void {
4 var printFn: PrintFn = stopSayingThat;
5 var i: u32 = 0;
6 while (i < 4) : (i += 1) printFn();
7
8 printFn = moveEveryZig;
9 printFn();
10}
11
12fn stopSayingThat() void {
13 asm volatile ("svc #0"
14 :
15 : [number] "{r7}" (4),
16 [arg1] "{r0}" (1),
17 [arg2] "{r1}" (@ptrToInt("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n")),
18 [arg3] "{r2}" ("Hello, my name is Inigo Montoya; you killed my father, prepare to die.\n".len),
19 : "memory"
20 );
21 return;
22}
23
24fn moveEveryZig() void {
25 asm volatile ("svc #0"
26 :
27 : [number] "{r7}" (4),
28 [arg1] "{r0}" (1),
29 [arg2] "{r1}" (@ptrToInt("All your codebase are belong to us\n")),
30 [arg3] "{r2}" ("All your codebase are belong to us\n".len),
31 : "memory"
32 );
33 return;
34}
35
36// run
37// target=arm-linux
38//
39// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
40// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
41// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
42// Hello, my name is Inigo Montoya; you killed my father, prepare to die.
43// All your codebase are belong to us
44//
test/incremental/arm-linux/hello_world_with_updates.0.zig deleted-32
......@@ -1,32 +0,0 @@
1pub export fn _start() noreturn {
2 print();
3 exit();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg1] "{r0}" (1),
11 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{r2}" (14),
13 : "memory"
14 );
15 return;
16}
17
18fn exit() noreturn {
19 asm volatile ("svc #0"
20 :
21 : [number] "{r7}" (1),
22 [arg1] "{r0}" (0),
23 : "memory"
24 );
25 unreachable;
26}
27
28// run
29// target=arm-linux
30//
31// Hello, World!
32//
test/incremental/arm-linux/hello_world_with_updates.1.zig deleted-37
......@@ -1,37 +0,0 @@
1pub export fn _start() noreturn {
2 print();
3 print();
4 print();
5 print();
6 exit();
7}
8
9fn print() void {
10 asm volatile ("svc #0"
11 :
12 : [number] "{r7}" (4),
13 [arg1] "{r0}" (1),
14 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
15 [arg3] "{r2}" (14),
16 : "memory"
17 );
18 return;
19}
20
21fn exit() noreturn {
22 asm volatile ("svc #0"
23 :
24 : [number] "{r7}" (1),
25 [arg1] "{r0}" (0),
26 : "memory"
27 );
28 unreachable;
29}
30
31// run
32//
33// Hello, World!
34// Hello, World!
35// Hello, World!
36// Hello, World!
37//
test/incremental/arm-linux/hello_world_with_updates.2.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 print();
3 print();
4}
5
6fn print() void {
7 asm volatile ("svc #0"
8 :
9 : [number] "{r7}" (4),
10 [arg1] "{r0}" (1),
11 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
12 [arg3] "{r2}" (14),
13 : "memory"
14 );
15 return;
16}
17
18// run
19//
20// Hello, World!
21// Hello, World!
22//
test/incremental/arm-linux/parameters_and_return_values.0.zig deleted-28
......@@ -1,28 +0,0 @@
1pub fn main() void {
2 print(id(14));
3}
4
5fn id(x: u32) u32 {
6 return x;
7}
8
9// TODO: The parameters to the asm statement in print() had to
10// be in a specific order because otherwise the write to r0
11// would overwrite the len parameter which resides in r0
12fn print(len: u32) void {
13 asm volatile ("svc #0"
14 :
15 : [number] "{r7}" (4),
16 [arg3] "{r2}" (len),
17 [arg1] "{r0}" (1),
18 [arg2] "{r1}" (@ptrToInt("Hello, World!\n")),
19 : "memory"
20 );
21 return;
22}
23
24// run
25// target=arm-linux
26//
27// Hello, World!
28//
test/incremental/arm-linux/parameters_and_return_values.1.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn main() void {
2 assert(add(1, 2, 3, 4, 5, 6) == 21);
3}
4
5fn add(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32) u32 {
6 return a + b + c + d + e + f;
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14//
test/incremental/arm-linux/print_u32s.zig deleted-40
......@@ -1,40 +0,0 @@
1pub fn main() void {
2 printNumberHex(0x00000000);
3 printNumberHex(0xaaaaaaaa);
4 printNumberHex(0xdeadbeef);
5 printNumberHex(0x31415926);
6}
7
8fn printNumberHex(x: u32) void {
9 var i: u5 = 28;
10 while (true) : (i -= 4) {
11 const digit = (x >> i) & 0xf;
12 asm volatile ("svc #0"
13 :
14 : [number] "{r7}" (4),
15 [arg1] "{r0}" (1),
16 [arg2] "{r1}" (@ptrToInt("0123456789abcdef") + digit),
17 [arg3] "{r2}" (1),
18 : "memory"
19 );
20
21 if (i == 0) break;
22 }
23 asm volatile ("svc #0"
24 :
25 : [number] "{r7}" (4),
26 [arg1] "{r0}" (1),
27 [arg2] "{r1}" (@ptrToInt("\n")),
28 [arg3] "{r2}" (1),
29 : "memory"
30 );
31}
32
33// run
34// target=arm-linux
35//
36// 00000000
37// aaaaaaaa
38// deadbeef
39// 31415926
40//
test/incremental/arm-linux/spilling_registers.0.zig deleted-38
......@@ -1,38 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l + d; // 227
18 const n = m + e; // 241
19 const o = n + f; // 265
20 const p = o + g; // 303
21 const q = p + h; // 365
22 const r = q + i; // 465
23 const s = r + j; // 575
24 const t = s + k; // 785
25 break :blk t;
26 };
27 const y = x + a; // 788
28 const z = y + a; // 791
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37// target=arm-linux
38//
test/incremental/arm-linux/spilling_registers.1.zig deleted-37
......@@ -1,37 +0,0 @@
1pub fn main() void {
2 assert(addMul(3, 4) == 357747496);
3}
4
5fn addMul(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l * d; // 2170
18 const n = m + e; // 2184
19 const o = n * f; // 52416
20 const p = o + g; // 52454
21 const q = p * h; // 3252148
22 const r = q + i; // 3252248
23 const s = r * j; // 357747280
24 const t = s + k; // 357747490
25 break :blk t;
26 };
27 const y = x + a; // 357747493
28 const z = y + a; // 357747496
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37//
test/incremental/bad_inferred_variable_type.zig deleted-9
......@@ -1,9 +0,0 @@
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/binary_operands.0.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var i: u8 = 5;
3 i += 20;
4 if (i != 25) unreachable;
5}
6
7// run
8// target=wasm32-wasi
9//
test/incremental/binary_operands.1.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 var i: i32 = 2147483647;
3 if (i +% 1 != -2147483648) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.10.zig deleted-13
......@@ -1,13 +0,0 @@
1pub fn main() void {
2 var i: u32 = 5;
3 i *= 7;
4 var result: u32 = foo(i, 10);
5 if (result != 350) unreachable;
6 return;
7}
8fn foo(x: u32, y: u32) u32 {
9 return x * y;
10}
11
12// run
13//
test/incremental/binary_operands.11.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var i: i32 = 2147483647;
3 const result = i *% 2;
4 if (result != -2) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.12.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 var i: u3 = 3;
3 if (i *% 3 != 1) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.13.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 var i: i4 = 3;
3 if (i *% 3 != 1) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.14.zig deleted-13
......@@ -1,13 +0,0 @@
1pub fn main() void {
2 var i: u32 = 352;
3 i /= 7; // i = 50
4 var result: u32 = foo(i, 7);
5 if (result != 7) unreachable;
6 return;
7}
8fn foo(x: u32, y: u32) u32 {
9 return x / y;
10}
11
12// run
13//
test/incremental/binary_operands.15.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i &= 6;
4 return i - 4;
5}
6
7// run
8//
test/incremental/binary_operands.16.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i |= 6;
4 return i - 7;
5}
6
7// run
8//
test/incremental/binary_operands.17.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i ^= 6;
4 return i - 3;
5}
6
7// run
8//
test/incremental/binary_operands.18.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b or false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.19.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b or false;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.2.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 var i: i4 = 7;
3 if (i +% 1 != 0) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.20.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b or true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.21.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b or true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.22.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b and false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.23.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b and false;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.24.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = false;
3 b = b and true;
4 if (b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.25.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 var b: bool = true;
3 b = b and true;
4 if (!b) unreachable;
5 return;
6}
7
8// run
9//
test/incremental/binary_operands.3.zig deleted-7
......@@ -1,7 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 255;
3 return i +% 1;
4}
5
6// run
7//
test/incremental/binary_operands.4.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i += 20;
4 var result: u8 = foo(i, 10);
5 return result - 35;
6}
7fn foo(x: u8, y: u8) u8 {
8 return x + y;
9}
10
11// run
12//
test/incremental/binary_operands.5.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 20;
3 i -= 5;
4 return i - 15;
5}
6
7// run
8//
test/incremental/binary_operands.6.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 var i: i32 = -2147483648;
3 if (i -% 1 != 2147483647) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.7.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 var i: i7 = -64;
3 if (i -% 1 != 63) unreachable;
4 return;
5}
6
7// run
8//
test/incremental/binary_operands.8.zig deleted-7
......@@ -1,7 +0,0 @@
1pub fn main() void {
2 var i: u4 = 0;
3 if (i -% 1 != 15) unreachable;
4}
5
6// run
7//
test/incremental/binary_operands.9.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 i -= 3;
4 var result: u8 = foo(i, 10);
5 return result - 8;
6}
7fn foo(x: u8, y: u8) u8 {
8 return y - x;
9}
10
11// run
12//
test/incremental/break_continue.0.zig deleted-9
......@@ -1,9 +0,0 @@
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 deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() void {
2 foo: while (true) {
3 break :foo;
4 }
5}
6
7// run
8//
test/incremental/break_continue.2.zig deleted-10
......@@ -1,10 +0,0 @@
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 deleted-10
......@@ -1,10 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-10
......@@ -1,10 +0,0 @@
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 deleted-10
......@@ -1,10 +0,0 @@
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 deleted-7
......@@ -1,7 +0,0 @@
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 deleted-16
......@@ -1,16 +0,0 @@
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 deleted-13
......@@ -1,13 +0,0 @@
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 deleted-17
......@@ -1,17 +0,0 @@
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 deleted-16
......@@ -1,16 +0,0 @@
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/double_ampersand.0.zig deleted-6
......@@ -1,6 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-7
......@@ -1,7 +0,0 @@
1pub fn main() void {
2 const b: u8 = 1;
3 _ = &&b;
4}
5
6// run
7//
test/incremental/enum_values.0.zig deleted-18
......@@ -1,18 +0,0 @@
1const Number = enum { One, Two, Three };
2
3pub fn main() void {
4 var number1 = Number.One;
5 var number2: Number = .Two;
6 if (false) {
7 number1;
8 number2;
9 }
10 const number3 = @intToEnum(Number, 2);
11 if (@enumToInt(number3) != 2) {
12 unreachable;
13 }
14 return;
15}
16
17// run
18//
test/incremental/enum_values.1.zig deleted-22
......@@ -1,22 +0,0 @@
1const Number = enum { One, Two, Three };
2
3pub fn main() void {
4 var number1 = Number.One;
5 var number2: Number = .Two;
6 const number3 = @intToEnum(Number, 2);
7 assert(number1 != number2);
8 assert(number2 != number3);
9 assert(@enumToInt(number1) == 0);
10 assert(@enumToInt(number2) == 1);
11 assert(@enumToInt(number3) == 2);
12 var x: Number = .Two;
13 assert(number2 == x);
14
15 return;
16}
17fn assert(val: bool) void {
18 if (!val) unreachable;
19}
20
21// run
22//
test/incremental/extern_variable_has_no_type.0.zig deleted-9
......@@ -1,9 +0,0 @@
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 deleted-8
......@@ -1,8 +0,0 @@
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_calls.0.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 foo();
3 bar();
4}
5fn foo() void {
6 bar();
7 bar();
8}
9fn bar() void {}
10
11// run
12//
test/incremental/function_calls.1.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 bar();
3 foo();
4 foo();
5 bar();
6 foo();
7 bar();
8}
9fn foo() void {
10 bar();
11}
12fn bar() void {}
13
14// run
15//
test/incremental/function_calls.2.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn main() void {
2 bar();
3 foo();
4 return;
5}
6fn foo() void {
7 bar();
8 bar();
9 bar();
10}
11fn bar() void {}
12
13// run
14//
test/incremental/function_calls.3.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 foo(10, 20);
3}
4fn foo(x: u8, y: u8) void {
5 _ = x;
6 _ = y;
7}
8
9// run
10//
test/incremental/function_redeclaration.zig deleted-14
......@@ -1,14 +0,0 @@
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 deleted-8
......@@ -1,8 +0,0 @@
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/inner_func_accessing_outer_var.zig deleted-15
......@@ -1,15 +0,0 @@
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 deleted-8
......@@ -1,8 +0,0 @@
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 deleted-7
......@@ -1,7 +0,0 @@
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/large_add_function.zig deleted-38
......@@ -1,38 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 const k = i + j; // 210
16 const l = k + c; // 217
17 const m = l + d; // 227
18 const n = m + e; // 241
19 const o = n + f; // 265
20 const p = o + g; // 303
21 const q = p + h; // 365
22 const r = q + i; // 465
23 const s = r + j; // 575
24 const t = s + k; // 785
25 break :blk t;
26 };
27 const y = x + a; // 788
28 const z = y + a; // 791
29 return z;
30}
31
32fn assert(ok: bool) void {
33 if (!ok) unreachable;
34}
35
36// run
37// target=aarch64-linux,aarch64-macos
38//
test/incremental/llvm/address_space_pointer_access_chaining_pointer_to_optional_array.zig deleted-12
......@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) ?[1]i32) *addrspace(.gs) i32 {
2 return &a.*.?[0];
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/address_spaces_pointer_access_chaining_array_pointer.zig deleted-12
......@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) [1]i32) *addrspace(.gs) i32 {
2 return &a[0];
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/address_spaces_pointer_access_chaining_complex.zig deleted-13
......@@ -1,13 +0,0 @@
1const A = struct { a: ?[1]i32 };
2fn entry(a: *addrspace(.gs) [1]A) *addrspace(.gs) i32 {
3 return &a[0].a.?[0];
4}
5pub fn main() void {
6 _ = entry;
7}
8
9// error
10// output_mode=Exe
11// backend=llvm
12// target=x86_64-linux,x86_64-macos
13//
test/incremental/llvm/address_spaces_pointer_access_chaining_struct_pointer.zig deleted-13
......@@ -1,13 +0,0 @@
1const A = struct { a: i32 };
2fn entry(a: *addrspace(.gs) A) *addrspace(.gs) i32 {
3 return &a.a;
4}
5pub fn main() void {
6 _ = entry;
7}
8
9// error
10// output_mode=Exe
11// backend=stage2,llvm
12// target=x86_64-linux,x86_64-macos
13//
test/incremental/llvm/any_typed_null_to_any_typed_optional.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() void {
2 var a: ?*anyopaque = undefined;
3 a = @as(?usize, null);
4}
5
6// error
7// output_mode=Exe
8// backend=stage2,llvm
9// target=x86_64-linux,x86_64-macos
10//
11// :3:21: error: expected *anyopaque, found ?usize
test/incremental/llvm/blocks.zig deleted-22
......@@ -1,22 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 const val: i32 = blk: {
7 var x: i32 = 1;
8 if (!ok) break :blk x + 9;
9 break :blk x + 19;
10 };
11 return val + 10;
12}
13
14pub fn main() void {
15 assert(foo(false) == 20);
16 assert(foo(true) == 30);
17}
18
19// run
20// backend=stage2,llvm
21// target=x86_64-linux,x86_64-macos
22//
test/incremental/llvm/dereferencing_though_multiple_pointers_with_address_spaces.zig deleted-12
......@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.fs) *addrspace(.gs) *i32) *i32 {
2 return a.*.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/f_segment_address_space_reading_and_writing.zig deleted-48
......@@ -1,48 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn setFs(value: c_ulong) void {
6 asm volatile (
7 \\syscall
8 :
9 : [number] "{rax}" (158),
10 [code] "{rdi}" (0x1002),
11 [val] "{rsi}" (value),
12 : "rcx", "r11", "memory"
13 );
14}
15
16fn getFs() c_ulong {
17 var result: c_ulong = undefined;
18 asm volatile (
19 \\syscall
20 :
21 : [number] "{rax}" (158),
22 [code] "{rdi}" (0x1003),
23 [ptr] "{rsi}" (@ptrToInt(&result)),
24 : "rcx", "r11", "memory"
25 );
26 return result;
27}
28
29var test_value: u64 = 12345;
30
31pub fn main() void {
32 const orig_fs = getFs();
33
34 setFs(@ptrToInt(&test_value));
35 assert(getFs() == @ptrToInt(&test_value));
36
37 var test_ptr = @intToPtr(*allowzero addrspace(.fs) u64, 0);
38 assert(test_ptr.* == 12345);
39 test_ptr.* = 98765;
40 assert(test_value == 98765);
41
42 setFs(orig_fs);
43}
44
45// run
46// backend=llvm
47// target=x86_64-linux
48//
test/incremental/llvm/for_loop.zig deleted-16
......@@ -1,16 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var x: u32 = 0;
7 for ("hello") |_| {
8 x += 1;
9 }
10 assert("hello".len == x);
11}
12
13// run
14// backend=stage2,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/incremental/llvm/hello_world.zig deleted-12
......@@ -1,12 +0,0 @@
1extern fn puts(s: [*:0]const u8) c_int;
2
3pub fn main() void {
4 _ = puts("hello world!");
5}
6
7// run
8// backend=llvm
9// target=x86_64-linux,x86_64-macos
10//
11// hello world!
12//
test/incremental/llvm/invalid_address_space_coercion.zig deleted-13
......@@ -1,13 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/invalid_pointer_keeps_address_space_when_taking_address_of_dereference.zig deleted-13
......@@ -1,13 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/nested_blocks.zig deleted-24
......@@ -1,24 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5fn foo(ok: bool) i32 {
6 var val: i32 = blk: {
7 const val2: i32 = another: {
8 if (!ok) break :blk 10;
9 break :another 10;
10 };
11 break :blk val2 + 10;
12 };
13 return val;
14}
15
16pub fn main() void {
17 assert(foo(false) == 10);
18 assert(foo(true) == 20);
19}
20
21// run
22// backend=stage2, llvm
23// target=x86_64-linux,x86_64-macos
24//
test/incremental/llvm/optionals.zig deleted-45
......@@ -1,45 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var opt_val: ?i32 = 10;
7 var null_val: ?i32 = null;
8
9 var val1: i32 = opt_val.?;
10 const val1_1: i32 = opt_val.?;
11 var ptr_val1 = &(opt_val.?);
12 const ptr_val1_1 = &(opt_val.?);
13
14 var val2: i32 = null_val orelse 20;
15 const val2_2: i32 = null_val orelse 20;
16
17 var value: i32 = 20;
18 var ptr_val2 = &(null_val orelse value);
19
20 const val3 = opt_val orelse 30;
21 var val3_var = opt_val orelse 30;
22
23 assert(val1 == 10);
24 assert(val1_1 == 10);
25 assert(ptr_val1.* == 10);
26 assert(ptr_val1_1.* == 10);
27
28 assert(val2 == 20);
29 assert(val2_2 == 20);
30 assert(ptr_val2.* == 20);
31
32 assert(val3 == 10);
33 assert(val3_var == 10);
34
35 (null_val orelse val2) = 1234;
36 assert(val2 == 1234);
37
38 (opt_val orelse val2) = 5678;
39 assert(opt_val.? == 5678);
40}
41
42// run
43// backend=llvm
44// target=x86_64-linux,x86_64-macos
45//
test/incremental/llvm/pointer_keeps_address_space.zig deleted-12
......@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/pointer_keeps_address_space_when_taking_address_of_dereference.zig deleted-12
......@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.gs) i32 {
2 return &a.*;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/pointer_to_explicit_generic_address_space_coerces_to_implicit_pointer.zig deleted-12
......@@ -1,12 +0,0 @@
1fn entry(a: *addrspace(.generic) i32) *i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/pointer_with_different_address_spaces.zig deleted-13
......@@ -1,13 +0,0 @@
1fn entry(a: *addrspace(.gs) i32) *addrspace(.fs) i32 {
2 return a;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:12: error: expected *addrspace(.fs) i32, found *addrspace(.gs) i32
test/incremental/llvm/pointers_with_different_address_spaces.zig deleted-13
......@@ -1,13 +0,0 @@
1fn entry(a: ?*addrspace(.gs) i32) *i32 {
2 return a.?;
3}
4pub fn main() void {
5 _ = entry;
6}
7
8// error
9// output_mode=Exe
10// backend=stage2,llvm
11// target=x86_64-linux,x86_64-macos
12//
13// :2:13: error: expected *i32, found *addrspace(.gs) i32
test/incremental/llvm/rem.zig deleted-15
......@@ -1,15 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4fn rem(lhs: i32, rhs: i32, expected: i32) bool {
5 return @rem(lhs, rhs) == expected;
6}
7pub fn main() void {
8 assert(rem(-5, 3, -2));
9 assert(rem(5, 3, 2));
10}
11
12// run
13// backend=stage2,llvm
14// target=x86_64-linux,x86_64-macos
15//
test/incremental/llvm/shift_right_plus_left.0.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i >> 1, 8);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10// backend=llvm
11// target=x86_64-linux,x86_64-macos
12//
test/incremental/llvm/shift_right_plus_left.1.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 var i: u32 = 16;
3 assert(i << 1, 32);
4}
5fn assert(a: u32, b: u32) void {
6 if (a != b) unreachable;
7}
8
9// run
10//
test/incremental/llvm/simple_addition_and_subtraction.zig deleted-20
......@@ -1,20 +0,0 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5pub fn main() void {
6 var a: i32 = -5;
7 const x = add(a, 7);
8 var y = add(2, 0);
9 y -= x;
10 assert(y == 0);
11}
12
13fn assert(ok: bool) void {
14 if (!ok) unreachable;
15}
16
17// run
18// backend=stage2,llvm
19// target=x86_64-linux,x86_64-macos
20//
test/incremental/llvm/simple_if_statement.zig deleted-16
......@@ -1,16 +0,0 @@
1fn add(a: i32, b: i32) i32 {
2 return a + b;
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9pub fn main() void {
10 assert(add(1, 2) == 3);
11}
12
13// run
14// backend=stage2,llvm
15// target=x86_64-linux,x86_64-macos
16//
test/incremental/llvm/while_loops.zig deleted-18
......@@ -1,18 +0,0 @@
1fn assert(ok: bool) void {
2 if (!ok) unreachable;
3}
4
5pub fn main() void {
6 var sum: u32 = 0;
7 var i: u32 = 0;
8 while (i < 5) : (i += 1) {
9 sum += i;
10 }
11 assert(sum == 10);
12 assert(i == 5);
13}
14
15// run
16// backend=stage2,llvm
17// target=x86_64-linux,x86_64-macos
18//
test/incremental/lower_unnamed_consts_structs.0.zig deleted-25
......@@ -1,25 +0,0 @@
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 deleted-35
......@@ -1,35 +0,0 @@
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 deleted-25
......@@ -1,25 +0,0 @@
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 deleted-18
......@@ -1,18 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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/multiplying_numbers_at_runtime_and_comptime.0.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() void {
2 mul(3, 4);
3}
4
5fn mul(a: u32, b: u32) void {
6 if (a * b != 12) unreachable;
7}
8
9// run
10// target=x86_64-linux,x86_64-macos
11//
test/incremental/multiplying_numbers_at_runtime_and_comptime.1.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 if (x - 12 != 0) unreachable;
3}
4
5fn mul(a: u32, b: u32) u32 {
6 return a * b;
7}
8
9const x = mul(3, 4);
10
11// run
12//
test/incremental/multiplying_numbers_at_runtime_and_comptime.2.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 var x: usize = 5;
3 const y = mul(2, 3, x);
4 if (y - 30 != 0) unreachable;
5}
6
7inline fn mul(a: usize, b: usize, c: usize) usize {
8 return a * b * c;
9}
10
11// run
12//
test/incremental/non_leaf_functions.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() void {
2 foo();
3}
4
5fn foo() void {
6 bar();
7}
8
9fn bar() void {}
10
11// run
12//
test/incremental/optional_payload.0.zig deleted-19
......@@ -1,19 +0,0 @@
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 deleted-17
......@@ -1,17 +0,0 @@
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 deleted-18
......@@ -1,18 +0,0 @@
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 deleted-18
......@@ -1,18 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 doNothing(0);
3}
4fn doNothing(arg: u0) void {
5 _ = arg;
6}
7
8// run
9//
test/incremental/plan9/exit.zig deleted-5
......@@ -1,5 +0,0 @@
1pub fn main() void {}
2
3// run
4// target=x86_64-plan9,aarch64-plan9
5//
test/incremental/plan9/hello_world_with_updates.0.zig deleted-28
......@@ -1,28 +0,0 @@
1pub fn main() void {
2 const str = "Hello World!\n";
3 asm volatile (
4 \\push $0
5 \\push %%r10
6 \\push %%r11
7 \\push $1
8 \\push $0
9 \\syscall
10 \\pop %%r11
11 \\pop %%r11
12 \\pop %%r11
13 \\pop %%r11
14 \\pop %%r11
15 :
16 // pwrite
17 : [syscall_number] "{rbp}" (51),
18 [hey] "{r11}" (@ptrToInt(str)),
19 [strlen] "{r10}" (str.len),
20 : "rcx", "rbp", "r11", "memory"
21 );
22}
23
24// run
25// target=x86_64-plan9
26//
27// Hello World
28//
test/incremental/plan9/hello_world_with_updates.1.zig deleted-10
......@@ -1,10 +0,0 @@
1const std = @import("std");
2pub fn main() void {
3 const str = "Hello World!\n";
4 _ = std.os.plan9.pwrite(1, str, str.len, 0);
5}
6
7// run
8//
9// Hello World
10//
test/incremental/recursive_fibonacci.zig deleted-24
......@@ -1,24 +0,0 @@
1pub fn main() void {
2 assert(fib(0) == 0);
3 assert(fib(1) == 1);
4 assert(fib(2) == 1);
5 assert(fib(3) == 2);
6 assert(fib(10) == 55);
7 assert(fib(20) == 6765);
8}
9
10fn fib(n: u32) u32 {
11 if (n < 2) {
12 return n;
13 } else {
14 return fib(n - 2) + fib(n - 1);
15 }
16}
17
18fn assert(ok: bool) void {
19 if (!ok) unreachable;
20}
21
22// run
23// target=arm-linux,x86_64-linux,x86_64-macos,wasm32-wasi
24//
test/incremental/recursive_inline_function.0.zig deleted-12
......@@ -1,12 +0,0 @@
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 deleted-16
......@@ -1,16 +0,0 @@
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 deleted-7
......@@ -1,7 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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 deleted-16
......@@ -1,16 +0,0 @@
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/riscv64-linux/hello_world_with_updates.0.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 print();
3}
4
5fn print() void {
6 asm volatile ("ecall"
7 :
8 : [number] "{a7}" (64),
9 [arg1] "{a0}" (1),
10 [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
11 [arg3] "{a2}" ("Hello, World!\n".len),
12 : "rcx", "r11", "memory"
13 );
14 return;
15}
16
17// run
18// target=riscv64-linux
19//
20// Hello, World!
21//
test/incremental/riscv64-linux/hello_world_with_updates.1.zig deleted-27
......@@ -1,27 +0,0 @@
1pub fn main() void {
2 print();
3 print();
4 print();
5 print();
6}
7
8fn print() void {
9 asm volatile ("ecall"
10 :
11 : [number] "{a7}" (64),
12 [arg1] "{a0}" (1),
13 [arg2] "{a1}" (@ptrToInt("Hello, World!\n")),
14 [arg3] "{a2}" ("Hello, World!\n".len),
15 : "rcx", "r11", "memory"
16 );
17 return;
18}
19
20// run
21// target=riscv64-linux
22//
23// Hello, World!
24// Hello, World!
25// Hello, World!
26// Hello, World!
27//
test/incremental/runtime_bitwise_and.zig deleted-16
......@@ -1,16 +0,0 @@
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 deleted-16
......@@ -1,16 +0,0 @@
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/save_function_return_values_in_callee_preserved_register.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 assert(foo() == 43);
3}
4
5fn foo() u32 {
6 return bar() + baz(42);
7}
8
9fn bar() u32 {
10 return 1;
11}
12
13fn baz(x: u32) u32 {
14 return x;
15}
16
17fn assert(ok: bool) void {
18 if (!ok) unreachable;
19}
20
21// run
22//
test/incremental/setting_an_address_space_on_a_local_variable.zig deleted-8
......@@ -1,8 +0,0 @@
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/sparcv9-linux/hello_world.zig deleted-27
......@@ -1,27 +0,0 @@
1const msg = "Hello, World!\n";
2
3pub export fn _start() noreturn {
4 asm volatile ("ta 0x6d"
5 :
6 : [number] "{g1}" (4),
7 [arg1] "{o0}" (1),
8 [arg2] "{o1}" (@ptrToInt(msg)),
9 [arg3] "{o2}" (msg.len),
10 : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
11 );
12
13 asm volatile ("ta 0x6d"
14 :
15 : [number] "{g1}" (1),
16 [arg1] "{o0}" (0),
17 : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
18 );
19
20 unreachable;
21}
22
23// run
24// target=sparcv9-linux
25//
26// Hello, World!
27//
test/incremental/try_in_comptime_in_struct_in_test.zig deleted-13
......@@ -1,13 +0,0 @@
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 deleted-13
......@@ -1,13 +0,0 @@
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 deleted-11
......@@ -1,11 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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 deleted-8
......@@ -1,8 +0,0 @@
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 deleted-7
......@@ -1,7 +0,0 @@
1comptime {
2 foo: while (true) {}
3}
4
5// error
6//
7// :2:5: error: unused while loop label
test/incremental/unused_labels.2.zig deleted-7
......@@ -1,7 +0,0 @@
1comptime {
2 foo: for ("foo") |_| {}
3}
4
5// error
6//
7// :2:5: error: unused for loop label
test/incremental/unused_labels.3.zig deleted-8
......@@ -1,8 +0,0 @@
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/unused_vars.zig deleted-7
......@@ -1,7 +0,0 @@
1pub fn main() void {
2 const x = 1;
3}
4
5// error
6//
7// :2:11: error: unused local constant
test/incremental/variable_shadowing.0.zig deleted-9
......@@ -1,9 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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 deleted-13
......@@ -1,13 +0,0 @@
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 deleted-10
......@@ -1,10 +0,0 @@
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 deleted-10
......@@ -1,10 +0,0 @@
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 deleted-10
......@@ -1,10 +0,0 @@
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 deleted-13
......@@ -1,13 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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 deleted-9
......@@ -1,9 +0,0 @@
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
test/incremental/wasm-wasi/conditions.0.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i > @as(u8, 4)) {
4 i += 10;
5 }
6 return i - 15;
7}
8
9// run
10// target=wasm32-wasi
11//
test/incremental/wasm-wasi/conditions.1.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else {
6 i = 2;
7 }
8 return i - 2;
9}
10
11// run
12//
test/incremental/wasm-wasi/conditions.2.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 5;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else if (i == @as(u8, 5)) {
6 i = 20;
7 }
8 return i - 20;
9}
10
11// run
12//
test/incremental/wasm-wasi/conditions.3.zig deleted-16
......@@ -1,16 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 11;
3 if (i < @as(u8, 4)) {
4 i += 10;
5 } else {
6 if (i > @as(u8, 10)) {
7 i += 20;
8 } else {
9 i = 20;
10 }
11 }
12 return i - 31;
13}
14
15// run
16//
test/incremental/wasm-wasi/conditions.4.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 assert(foo(true) != @as(i32, 30));
3}
4
5fn assert(ok: bool) void {
6 if (!ok) unreachable;
7}
8
9fn foo(ok: bool) i32 {
10 const x = if (ok) @as(i32, 20) else @as(i32, 10);
11 return x;
12}
13
14// run
15//
test/incremental/wasm-wasi/conditions.5.zig deleted-20
......@@ -1,20 +0,0 @@
1pub fn main() void {
2 assert(foo(false) == @as(i32, 20));
3 assert(foo(true) == @as(i32, 30));
4}
5
6fn assert(ok: bool) void {
7 if (!ok) unreachable;
8}
9
10fn foo(ok: bool) i32 {
11 const val: i32 = blk: {
12 var x: i32 = 1;
13 if (!ok) break :blk x + @as(i32, 9);
14 break :blk x + @as(i32, 19);
15 };
16 return val + 10;
17}
18
19// run
20//
test/incremental/wasm-wasi/error_unions.0.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 var e1 = error.Foo;
3 var e2 = error.Bar;
4 assert(e1 != e2);
5 assert(e1 == error.Foo);
6 assert(e2 == error.Bar);
7}
8
9fn assert(b: bool) void {
10 if (!b) unreachable;
11}
12
13// run
14// target=wasm32-wasi
15//
test/incremental/wasm-wasi/error_unions.1.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var e: anyerror!u8 = 5;
3 const i = e catch 10;
4 return i - 5;
5}
6
7// run
8//
test/incremental/wasm-wasi/error_unions.2.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var e: anyerror!u8 = error.Foo;
3 const i = e catch 10;
4 return i - 10;
5}
6
7// run
8//
test/incremental/wasm-wasi/error_unions.3.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 69;
4 return i - 5;
5}
6
7fn foo() anyerror!u8 {
8 return 5;
9}
10
11// run
12//
test/incremental/wasm-wasi/error_unions.4.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 69;
4 return i - 69;
5}
6
7fn foo() anyerror!u8 {
8 return error.Bruh;
9}
10
11// run
12//
test/incremental/wasm-wasi/error_unions.5.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var e = foo();
3 const i = e catch 42;
4 return i - 42;
5}
6
7fn foo() anyerror!u8 {
8 return error.Dab;
9}
10
11// run
12//
test/incremental/wasm-wasi/locals.0.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn main() void {
2 var i: u8 = 5;
3 var y: f32 = 42.0;
4 var x: u8 = 10;
5 if (false) {
6 y;
7 x;
8 }
9 if (i != 5) unreachable;
10}
11
12// run
13// target=wasm32-wasi
14//
test/incremental/wasm-wasi/locals.1.zig deleted-17
......@@ -1,17 +0,0 @@
1pub fn main() void {
2 var i: u8 = 5;
3 var y: f32 = 42.0;
4 _ = y;
5 var x: u8 = 10;
6 foo(i, x);
7 i = x;
8 if (i != 10) unreachable;
9}
10fn foo(x: u8, y: u8) void {
11 _ = y;
12 var i: u8 = 10;
13 i = x;
14}
15
16// run
17//
test/incremental/wasm-wasi/optionals.0.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var x: ?u8 = 5;
3 var y: u8 = 0;
4 if (x) |val| {
5 y = val;
6 }
7 return y - 5;
8}
9
10// run
11// target=wasm32-wasi
12//
test/incremental/wasm-wasi/optionals.1.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() u8 {
2 var x: ?u8 = null;
3 var y: u8 = 0;
4 if (x) |val| {
5 y = val;
6 }
7 return y;
8}
9
10// run
11//
test/incremental/wasm-wasi/optionals.2.zig deleted-7
......@@ -1,7 +0,0 @@
1pub fn main() u8 {
2 var x: ?u8 = 5;
3 return x.? - 5;
4}
5
6// run
7//
test/incremental/wasm-wasi/optionals.3.zig deleted-8
......@@ -1,8 +0,0 @@
1pub fn main() u8 {
2 var x: u8 = 5;
3 var y: ?u8 = x;
4 return y.? - 5;
5}
6
7// run
8//
test/incremental/wasm-wasi/optionals.4.zig deleted-13
......@@ -1,13 +0,0 @@
1pub fn main() u8 {
2 var val: ?u8 = 5;
3 while (val) |*v| {
4 v.* -= 1;
5 if (v.* == 2) {
6 val = null;
7 }
8 }
9 return 0;
10}
11
12// run
13//
test/incremental/wasm-wasi/pointers.0.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn main() u8 {
2 var x: u8 = 0;
3
4 foo(&x);
5 return x - 2;
6}
7
8fn foo(x: *u8) void {
9 x.* = 2;
10}
11
12// run
13// target=wasm32-wasi
14//
test/incremental/wasm-wasi/pointers.1.zig deleted-18
......@@ -1,18 +0,0 @@
1pub fn main() u8 {
2 var x: u8 = 0;
3
4 foo(&x);
5 bar(&x);
6 return x - 4;
7}
8
9fn foo(x: *u8) void {
10 x.* = 2;
11}
12
13fn bar(x: *u8) void {
14 x.* += 2;
15}
16
17// run
18//
test/incremental/wasm-wasi/structs.0.zig deleted-10
......@@ -1,10 +0,0 @@
1const Example = struct { x: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };
5 return example.x - 5;
6}
7
8// run
9// target=wasm32-wasi
10//
test/incremental/wasm-wasi/structs.1.zig deleted-10
......@@ -1,10 +0,0 @@
1const Example = struct { x: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };
5 example.x = 10;
6 return example.x - 10;
7}
8
9// run
10//
test/incremental/wasm-wasi/structs.2.zig deleted-9
......@@ -1,9 +0,0 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5 return example.y + example.x - 15;
6}
7
8// run
9//
test/incremental/wasm-wasi/structs.3.zig deleted-12
......@@ -1,12 +0,0 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5 var example2: Example = .{ .x = 10, .y = 20 };
6
7 example = example2;
8 return example.y + example.x - 30;
9}
10
11// run
12//
test/incremental/wasm-wasi/structs.4.zig deleted-11
......@@ -1,11 +0,0 @@
1const Example = struct { x: u8, y: u8 };
2
3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };
5
6 example = .{ .x = 10, .y = 20 };
7 return example.y + example.x - 30;
8}
9
10// run
11//
test/incremental/wasm-wasi/switch.0.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() u8 {
2 var val: u8 = 1;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 2;
11}
12
13// run
14// target=wasm32-wasi
15//
test/incremental/wasm-wasi/switch.1.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn main() u8 {
2 var val: u8 = 2;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 3;
11}
12
13// run
14//
test/incremental/wasm-wasi/switch.2.zig deleted-14
......@@ -1,14 +0,0 @@
1pub fn main() u8 {
2 var val: u8 = 10;
3 var a: u8 = switch (val) {
4 0, 1 => 2,
5 2 => 3,
6 3 => 4,
7 else => 5,
8 };
9
10 return a - 5;
11}
12
13// run
14//
test/incremental/wasm-wasi/switch.3.zig deleted-15
......@@ -1,15 +0,0 @@
1const MyEnum = enum { One, Two, Three };
2
3pub fn main() u8 {
4 var val: MyEnum = .Two;
5 var a: u8 = switch (val) {
6 .One => 1,
7 .Two => 2,
8 .Three => 3,
9 };
10
11 return a - 2;
12}
13
14// run
15//
test/incremental/wasm-wasi/while_loops.0.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 5)) {
4 i += 1;
5 }
6
7 return i - 5;
8}
9
10// run
11// target=wasm32-wasi
12//
test/incremental/wasm-wasi/while_loops.1.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;
5 i += x;
6 }
7 return i - 10;
8}
9
10// run
11//
test/incremental/wasm-wasi/while_loops.2.zig deleted-12
......@@ -1,12 +0,0 @@
1pub fn main() u8 {
2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;
5 i += x;
6 if (i == @as(u8, 5)) break;
7 }
8 return i - 5;
9}
10
11// run
12//
test/incremental/x86_64-linux/assert_function.0.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 assert(a + b == 7);
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14// target=x86_64-linux
15//
test/incremental/x86_64-linux/assert_function.1.zig deleted-17
......@@ -1,17 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 assert(e == 14);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-linux/assert_function.10.zig deleted-27
......@@ -1,27 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 116);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 break :blk j;
16 };
17 const y = x + a; // 113
18 const z = y + a; // 116
19 return z;
20}
21
22pub fn assert(ok: bool) void {
23 if (!ok) unreachable; // assertion failure
24}
25
26// run
27//
test/incremental/x86_64-linux/assert_function.11.zig deleted-66
......@@ -1,66 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 1221);
3 assert(mul(3, 4) == 21609);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = j + k; // 320
18 const m = l + c; // 327
19 const n = m + d; // 337
20 const o = n + e; // 351
21 const p = o + f; // 375
22 const q = p + g; // 413
23 const r = q + h; // 475
24 const s = r + i; // 575
25 const t = s + j; // 685
26 const u = t + k; // 895
27 const v = u + l; // 1215
28 break :blk v;
29 };
30 const y = x + a; // 1218
31 const z = y + a; // 1221
32 return z;
33}
34
35fn mul(a: u32, b: u32) u32 {
36 const x: u32 = blk: {
37 const c = a * a * a * a; // 81
38 const d = a * a * a * b; // 108
39 const e = a * a * b * a; // 108
40 const f = a * a * b * b; // 144
41 const g = a * b * a * a; // 108
42 const h = a * b * a * b; // 144
43 const i = a * b * b * a; // 144
44 const j = a * b * b * b; // 192
45 const k = b * a * a * a; // 108
46 const l = b * a * a * b; // 144
47 const m = b * a * b * a; // 144
48 const n = b * a * b * b; // 192
49 const o = b * b * a * a; // 144
50 const p = b * b * a * b; // 192
51 const q = b * b * b * a; // 192
52 const r = b * b * b * b; // 256
53 const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
54 break :blk s;
55 };
56 const y = x * a; // 7203
57 const z = y * a; // 21609
58 return z;
59}
60
61pub fn assert(ok: bool) void {
62 if (!ok) unreachable; // assertion failure
63}
64
65// run
66//
test/incremental/x86_64-linux/assert_function.12.zig deleted-47
......@@ -1,47 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3 assert(add(4, 3) == 79);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = if (a < b) blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = k + c; // 217
18 const m = l + d; // 227
19 const n = m + e; // 241
20 const o = n + f; // 265
21 const p = o + g; // 303
22 const q = p + h; // 365
23 const r = q + i; // 465
24 const s = r + j; // 575
25 const t = s + k; // 785
26 break :blk t;
27 } else blk: {
28 const t = b + b + a; // 10
29 const c = a + t; // 14
30 const d = c + t; // 24
31 const e = d + t; // 34
32 const f = e + t; // 44
33 const g = f + t; // 54
34 const h = c + g; // 68
35 break :blk h + b; // 71
36 };
37 const y = x + a; // 788, 75
38 const z = y + a; // 791, 79
39 return z;
40}
41
42pub fn assert(ok: bool) void {
43 if (!ok) unreachable; // assertion failure
44}
45
46// run
47//
test/incremental/x86_64-linux/assert_function.13.zig deleted-19
......@@ -1,19 +0,0 @@
1pub fn main() void {
2 const ignore =
3 \\ cool thx
4 \\
5 ;
6 _ = ignore;
7 add('ぁ', '\x03');
8}
9
10fn add(a: u32, b: u32) void {
11 assert(a + b == 12356);
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-linux/assert_function.14.zig deleted-17
......@@ -1,17 +0,0 @@
1pub fn main() void {
2 add(aa, bb);
3}
4
5const aa = 'ぁ';
6const bb = '\x03';
7
8fn add(a: u32, b: u32) void {
9 assert(a + b == 12356);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-linux/assert_function.15.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 assert("hello"[0] == 'h');
3}
4
5pub fn assert(ok: bool) void {
6 if (!ok) unreachable; // assertion failure
7}
8
9// run
10//
test/incremental/x86_64-linux/assert_function.16.zig deleted-11
......@@ -1,11 +0,0 @@
1const hello = "hello".*;
2pub fn main() void {
3 assert(hello[1] == 'e');
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-linux/assert_function.17.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 assert(i == 0xFFEEDDCCBBAA9988);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-linux/assert_function.18.zig deleted-35
......@@ -1,35 +0,0 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 for ("hello") |_| print();
7}
8
9fn print() void {
10 switch (builtin.os.tag) {
11 .linux => {
12 asm volatile ("syscall"
13 :
14 : [number] "{rax}" (1),
15 [arg1] "{rdi}" (1),
16 [arg2] "{rsi}" (@ptrToInt("hello\n")),
17 [arg3] "{rdx}" (6),
18 : "rcx", "r11", "memory"
19 );
20 },
21 .macos => {
22 _ = write(1, @ptrToInt("hello\n"), 6);
23 },
24 else => unreachable,
25 }
26}
27
28// run
29//
30// hello
31// hello
32// hello
33// hello
34// hello
35//
test/incremental/x86_64-linux/assert_function.2.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 assert(i == 100);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/incremental/x86_64-linux/assert_function.3.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 const j = i + d; // 110
14 assert(j == 110);
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-linux/assert_function.4.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 return a + b;
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/incremental/x86_64-linux/assert_function.5.zig deleted-19
......@@ -1,19 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 var x: u32 = undefined;
8 x = 0;
9 x += a;
10 x += b;
11 return x;
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-linux/assert_function.6.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 const a: u32 = 2;
3 const b: ?u32 = a;
4 const c = b.?;
5 if (c != 2) unreachable;
6}
7
8// run
9//
test/incremental/x86_64-linux/assert_function.7.zig deleted-28
......@@ -1,28 +0,0 @@
1pub fn main() void {
2 var i: u32 = 0;
3 while (i < 4) : (i += 1) print();
4 assert(i == 4);
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("hello\n")),
13 [arg3] "{rdx}" (6),
14 : "rcx", "r11", "memory"
15 );
16}
17
18pub fn assert(ok: bool) void {
19 if (!ok) unreachable; // assertion failure
20}
21
22// run
23//
24// hello
25// hello
26// hello
27// hello
28//
test/incremental/x86_64-linux/assert_function.8.zig deleted-24
......@@ -1,24 +0,0 @@
1pub fn main() void {
2 var i: u32 = 0;
3 inline while (i < 4) : (i += 1) print();
4 assert(i == 4);
5}
6
7fn print() void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("hello\n")),
13 [arg3] "{rdx}" (6),
14 : "rcx", "r11", "memory"
15 );
16}
17
18pub fn assert(ok: bool) void {
19 if (!ok) unreachable; // assertion failure
20}
21
22// error
23//
24// :3:21: error: unable to resolve comptime value
test/incremental/x86_64-linux/assert_function.9.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 20);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 break :blk e;
11 };
12 const y = x + a; // 17
13 const z = y + a; // 20
14 return z;
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-linux/comptime_var.0.zig deleted-12
......@@ -1,12 +0,0 @@
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
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/incremental/x86_64-linux/comptime_var.1.zig deleted-13
......@@ -1,13 +0,0 @@
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/x86_64-linux/comptime_var.2.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 comptime var len: u32 = 5;
3 print(len);
4 len += 9;
5 print(len);
6}
7
8fn print(len: usize) void {
9 asm volatile ("syscall"
10 :
11 : [number] "{rax}" (1),
12 [arg1] "{rdi}" (1),
13 [arg2] "{rsi}" (@ptrToInt("Hello, World!\n")),
14 [arg3] "{rdx}" (len),
15 : "rcx", "r11", "memory"
16 );
17}
18
19// run
20//
21// HelloHello, World!
22//
test/incremental/x86_64-linux/comptime_var.3.zig deleted-10
......@@ -1,10 +0,0 @@
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: reached unreachable code
test/incremental/x86_64-linux/comptime_var.4.zig deleted-9
......@@ -1,9 +0,0 @@
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/x86_64-linux/comptime_var.5.zig deleted-15
......@@ -1,15 +0,0 @@
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/x86_64-linux/comptime_var.6.zig deleted-20
......@@ -1,20 +0,0 @@
1pub fn main() void {
2 comptime var i: u64 = 2;
3 inline while (i < 6) : (i += 1) {
4 print(i);
5 }
6}
7fn print(len: usize) void {
8 asm volatile ("syscall"
9 :
10 : [number] "{rax}" (1),
11 [arg1] "{rdi}" (1),
12 [arg2] "{rsi}" (@ptrToInt("Hello")),
13 [arg3] "{rdx}" (len),
14 : "rcx", "r11", "memory"
15 );
16}
17
18// run
19//
20// HeHelHellHello
test/incremental/x86_64-linux/hello_world_with_updates.0.zig deleted-5
......@@ -1,5 +0,0 @@
1// error
2// output_mode=Exe
3// target=x86_64-linux
4//
5// :107:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/x86_64-linux/hello_world_with_updates.1.zig deleted-5
......@@ -1,5 +0,0 @@
1pub export fn _start() noreturn {}
2
3// error
4//
5// :1:34: error: expected noreturn, found void
test/incremental/x86_64-linux/hello_world_with_updates.2.zig deleted-32
......@@ -1,32 +0,0 @@
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/x86_64-linux/hello_world_with_updates.3.zig deleted-20
......@@ -1,20 +0,0 @@
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/x86_64-linux/hello_world_with_updates.4.zig deleted-20
......@@ -1,20 +0,0 @@
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/x86_64-linux/hello_world_with_updates.5.zig deleted-22
......@@ -1,22 +0,0 @@
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/x86_64-linux/inline_assembly.0.zig deleted-16
......@@ -1,16 +0,0 @@
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/x86_64-linux/inline_assembly.1.zig deleted-15
......@@ -1,15 +0,0 @@
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/x86_64-linux/inline_assembly.2.zig deleted-12
......@@ -1,12 +0,0 @@
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/x86_64-linux/inline_assembly.3.zig deleted-12
......@@ -1,12 +0,0 @@
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/x86_64-linux/only_1_function_and_it_gets_updated.0.zig deleted-13
......@@ -1,13 +0,0 @@
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/x86_64-linux/only_1_function_and_it_gets_updated.1.zig deleted-12
......@@ -1,12 +0,0 @@
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/x86_64-macos/assert_function.0.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 assert(a + b == 7);
7}
8
9pub fn assert(ok: bool) void {
10 if (!ok) unreachable; // assertion failure
11}
12
13// run
14// target=x86_64-macos
15//
test/incremental/x86_64-macos/assert_function.1.zig deleted-17
......@@ -1,17 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 assert(e == 14);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-macos/assert_function.10.zig deleted-27
......@@ -1,27 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 116);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 const f = d + e; // 24
11 const g = e + f; // 38
12 const h = f + g; // 62
13 const i = g + h; // 100
14 const j = i + d; // 110
15 break :blk j;
16 };
17 const y = x + a; // 113
18 const z = y + a; // 116
19 return z;
20}
21
22pub fn assert(ok: bool) void {
23 if (!ok) unreachable; // assertion failure
24}
25
26// run
27//
test/incremental/x86_64-macos/assert_function.11.zig deleted-66
......@@ -1,66 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 1221);
3 assert(mul(3, 4) == 21609);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = j + k; // 320
18 const m = l + c; // 327
19 const n = m + d; // 337
20 const o = n + e; // 351
21 const p = o + f; // 375
22 const q = p + g; // 413
23 const r = q + h; // 475
24 const s = r + i; // 575
25 const t = s + j; // 685
26 const u = t + k; // 895
27 const v = u + l; // 1215
28 break :blk v;
29 };
30 const y = x + a; // 1218
31 const z = y + a; // 1221
32 return z;
33}
34
35fn mul(a: u32, b: u32) u32 {
36 const x: u32 = blk: {
37 const c = a * a * a * a; // 81
38 const d = a * a * a * b; // 108
39 const e = a * a * b * a; // 108
40 const f = a * a * b * b; // 144
41 const g = a * b * a * a; // 108
42 const h = a * b * a * b; // 144
43 const i = a * b * b * a; // 144
44 const j = a * b * b * b; // 192
45 const k = b * a * a * a; // 108
46 const l = b * a * a * b; // 144
47 const m = b * a * b * a; // 144
48 const n = b * a * b * b; // 192
49 const o = b * b * a * a; // 144
50 const p = b * b * a * b; // 192
51 const q = b * b * b * a; // 192
52 const r = b * b * b * b; // 256
53 const s = c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r; // 2401
54 break :blk s;
55 };
56 const y = x * a; // 7203
57 const z = y * a; // 21609
58 return z;
59}
60
61pub fn assert(ok: bool) void {
62 if (!ok) unreachable; // assertion failure
63}
64
65// run
66//
test/incremental/x86_64-macos/assert_function.12.zig deleted-47
......@@ -1,47 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 791);
3 assert(add(4, 3) == 79);
4}
5
6fn add(a: u32, b: u32) u32 {
7 const x: u32 = if (a < b) blk: {
8 const c = a + b; // 7
9 const d = a + c; // 10
10 const e = d + b; // 14
11 const f = d + e; // 24
12 const g = e + f; // 38
13 const h = f + g; // 62
14 const i = g + h; // 100
15 const j = i + d; // 110
16 const k = i + j; // 210
17 const l = k + c; // 217
18 const m = l + d; // 227
19 const n = m + e; // 241
20 const o = n + f; // 265
21 const p = o + g; // 303
22 const q = p + h; // 365
23 const r = q + i; // 465
24 const s = r + j; // 575
25 const t = s + k; // 785
26 break :blk t;
27 } else blk: {
28 const t = b + b + a; // 10
29 const c = a + t; // 14
30 const d = c + t; // 24
31 const e = d + t; // 34
32 const f = e + t; // 44
33 const g = f + t; // 54
34 const h = c + g; // 68
35 break :blk h + b; // 71
36 };
37 const y = x + a; // 788, 75
38 const z = y + a; // 791, 79
39 return z;
40}
41
42pub fn assert(ok: bool) void {
43 if (!ok) unreachable; // assertion failure
44}
45
46// run
47//
test/incremental/x86_64-macos/assert_function.13.zig deleted-19
......@@ -1,19 +0,0 @@
1pub fn main() void {
2 const ignore =
3 \\ cool thx
4 \\
5 ;
6 _ = ignore;
7 add('ぁ', '\x03');
8}
9
10fn add(a: u32, b: u32) void {
11 assert(a + b == 12356);
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-macos/assert_function.14.zig deleted-17
......@@ -1,17 +0,0 @@
1pub fn main() void {
2 add(aa, bb);
3}
4
5const aa = 'ぁ';
6const bb = '\x03';
7
8fn add(a: u32, b: u32) void {
9 assert(a + b == 12356);
10}
11
12pub fn assert(ok: bool) void {
13 if (!ok) unreachable; // assertion failure
14}
15
16// run
17//
test/incremental/x86_64-macos/assert_function.15.zig deleted-10
......@@ -1,10 +0,0 @@
1pub fn main() void {
2 assert("hello"[0] == 'h');
3}
4
5pub fn assert(ok: bool) void {
6 if (!ok) unreachable; // assertion failure
7}
8
9// run
10//
test/incremental/x86_64-macos/assert_function.16.zig deleted-11
......@@ -1,11 +0,0 @@
1const hello = "hello".*;
2pub fn main() void {
3 assert(hello[1] == 'e');
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-macos/assert_function.17.zig deleted-11
......@@ -1,11 +0,0 @@
1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 assert(i == 0xFFEEDDCCBBAA9988);
4}
5
6pub fn assert(ok: bool) void {
7 if (!ok) unreachable; // assertion failure
8}
9
10// run
11//
test/incremental/x86_64-macos/assert_function.18.zig deleted-35
......@@ -1,35 +0,0 @@
1const builtin = @import("builtin");
2
3extern "c" fn write(usize, usize, usize) usize;
4
5pub fn main() void {
6 for ("hello") |_| print();
7}
8
9fn print() void {
10 switch (builtin.os.tag) {
11 .linux => {
12 asm volatile ("syscall"
13 :
14 : [number] "{rax}" (1),
15 [arg1] "{rdi}" (1),
16 [arg2] "{rsi}" (@ptrToInt("hello\n")),
17 [arg3] "{rdx}" (6),
18 : "rcx", "r11", "memory"
19 );
20 },
21 .macos => {
22 _ = write(1, @ptrToInt("hello\n"), 6);
23 },
24 else => unreachable,
25 }
26}
27
28// run
29//
30// hello
31// hello
32// hello
33// hello
34// hello
35//
test/incremental/x86_64-macos/assert_function.2.zig deleted-21
......@@ -1,21 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 assert(i == 100);
14}
15
16pub fn assert(ok: bool) void {
17 if (!ok) unreachable; // assertion failure
18}
19
20// run
21//
test/incremental/x86_64-macos/assert_function.3.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 add(3, 4);
3}
4
5fn add(a: u32, b: u32) void {
6 const c = a + b; // 7
7 const d = a + c; // 10
8 const e = d + b; // 14
9 const f = d + e; // 24
10 const g = e + f; // 38
11 const h = f + g; // 62
12 const i = g + h; // 100
13 const j = i + d; // 110
14 assert(j == 110);
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-macos/assert_function.4.zig deleted-15
......@@ -1,15 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 return a + b;
8}
9
10pub fn assert(ok: bool) void {
11 if (!ok) unreachable; // assertion failure
12}
13
14// run
15//
test/incremental/x86_64-macos/assert_function.5.zig deleted-19
......@@ -1,19 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 7);
3 assert(add(20, 10) == 30);
4}
5
6fn add(a: u32, b: u32) u32 {
7 var x: u32 = undefined;
8 x = 0;
9 x += a;
10 x += b;
11 return x;
12}
13
14pub fn assert(ok: bool) void {
15 if (!ok) unreachable; // assertion failure
16}
17
18// run
19//
test/incremental/x86_64-macos/assert_function.6.zig deleted-9
......@@ -1,9 +0,0 @@
1pub fn main() void {
2 const a: u32 = 2;
3 const b: ?u32 = a;
4 const c = b.?;
5 if (c != 2) unreachable;
6}
7
8// run
9//
test/incremental/x86_64-macos/assert_function.7.zig deleted-23
......@@ -1,23 +0,0 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 var i: u32 = 0;
5 while (i < 4) : (i += 1) print();
6 assert(i == 4);
7}
8
9fn print() void {
10 _ = write(1, @ptrToInt("hello\n"), 6);
11}
12
13pub fn assert(ok: bool) void {
14 if (!ok) unreachable; // assertion failure
15}
16
17// run
18//
19// hello
20// hello
21// hello
22// hello
23//
test/incremental/x86_64-macos/assert_function.8.zig deleted-19
......@@ -1,19 +0,0 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 var i: u32 = 0;
5 inline while (i < 4) : (i += 1) print();
6 assert(i == 4);
7}
8
9fn print() void {
10 _ = write(1, @ptrToInt("hello\n"), 6);
11}
12
13pub fn assert(ok: bool) void {
14 if (!ok) unreachable; // assertion failure
15}
16
17// error
18//
19// :5:21: error: unable to resolve comptime value
test/incremental/x86_64-macos/assert_function.9.zig deleted-22
......@@ -1,22 +0,0 @@
1pub fn main() void {
2 assert(add(3, 4) == 20);
3}
4
5fn add(a: u32, b: u32) u32 {
6 const x: u32 = blk: {
7 const c = a + b; // 7
8 const d = a + c; // 10
9 const e = d + b; // 14
10 break :blk e;
11 };
12 const y = x + a; // 17
13 const z = y + a; // 20
14 return z;
15}
16
17pub fn assert(ok: bool) void {
18 if (!ok) unreachable; // assertion failure
19}
20
21// run
22//
test/incremental/x86_64-macos/comptime_var.0.zig deleted-12
......@@ -1,12 +0,0 @@
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-macos
10//
11// :4:21: error: store to comptime variable depends on runtime condition
12// :4:11: note: runtime condition here
test/incremental/x86_64-macos/comptime_var.1.zig deleted-13
......@@ -1,13 +0,0 @@
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/x86_64-macos/comptime_var.2.zig deleted-17
......@@ -1,17 +0,0 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 comptime var len: u32 = 5;
5 print(len);
6 len += 9;
7 print(len);
8}
9
10fn print(len: usize) void {
11 _ = write(1, @ptrToInt("Hello, World!\n"), len);
12}
13
14// run
15//
16// HelloHello, World!
17//
test/incremental/x86_64-macos/comptime_var.3.zig deleted-10
......@@ -1,10 +0,0 @@
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: reached unreachable code
test/incremental/x86_64-macos/comptime_var.4.zig deleted-9
......@@ -1,9 +0,0 @@
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/x86_64-macos/comptime_var.5.zig deleted-15
......@@ -1,15 +0,0 @@
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/x86_64-macos/comptime_var.6.zig deleted-15
......@@ -1,15 +0,0 @@
1extern "c" fn write(usize, usize, usize) usize;
2
3pub fn main() void {
4 comptime var i: u64 = 2;
5 inline while (i < 6) : (i += 1) {
6 print(i);
7 }
8}
9fn print(len: usize) void {
10 _ = write(1, @ptrToInt("Hello"), len);
11}
12
13// run
14//
15// HeHelHellHello
test/incremental/x86_64-macos/hello_world_with_updates.0.zig deleted-5
......@@ -1,5 +0,0 @@
1// error
2// output_mode=Exe
3// target=x86_64-macos
4//
5// :107:9: error: struct 'tmp.tmp' has no member named 'main'
test/incremental/x86_64-macos/hello_world_with_updates.1.zig deleted-5
......@@ -1,5 +0,0 @@
1pub export fn main() noreturn {}
2
3// error
4//
5// :1:32: error: expected noreturn, found void
test/incremental/x86_64-macos/hello_world_with_updates.2.zig deleted-19
......@@ -1,19 +0,0 @@
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/x86_64-macos/hello_world_with_updates.3.zig deleted-16
......@@ -1,16 +0,0 @@
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/x86_64-macos/hello_world_with_updates.4.zig deleted-22
......@@ -1,22 +0,0 @@
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/x86_64-macos/hello_world_with_updates.5.zig deleted-16
......@@ -1,16 +0,0 @@
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/x86_64-macos/hello_world_with_updates.6.zig deleted-18
......@@ -1,18 +0,0 @@
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//