authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-11 07:27:31+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 09:56:51+00:00
log21fa187abc2a06c9bd5cfe4355c5edbfb3177f6b
treeaab7cc16498184bac0fd8b6d5443f7bd606e7bf8
parent2c1acb618027939c0812bc87a432b51632127717
signaturelock-open Commit is signed but in an unrecognized format.

test: update cases to silence 'var is never mutated' errors


290 files changed, 695 insertions(+), 513 deletions(-)

test/cases/adding_numbers_at_runtime_and_comptime.2.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var x: usize = 3;2 var x: usize = 3;
3 _ = &x;
3 const y = add(1, 2, x);4 const y = add(1, 2, x);
4 if (y - 6 != 0) unreachable;5 if (y - 6 != 0) unreachable;
5}6}
test/cases/array_in_anon_struct.zig+1
...@@ -2,6 +2,7 @@ const std = @import("std");...@@ -2,6 +2,7 @@ const std = @import("std");
22
3noinline fn outer() u32 {3noinline fn outer() u32 {
4 var a: u32 = 42;4 var a: u32 = 42;
5 _ = &a;
5 return inner(.{6 return inner(.{
6 .unused = a,7 .unused = a,
7 .value = [1]u32{0},8 .value = [1]u32{0},
test/cases/assert_function.17.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: u64 = 0xFFEEDDCCBBAA9988;2 var i: u64 = 0xFFEEDDCCBBAA9988;
3 _ = &i;
3 assert(i == 0xFFEEDDCCBBAA9988);4 assert(i == 0xFFEEDDCCBBAA9988);
4}5}
56
test/cases/bad_inferred_variable_type.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var x = null;2 var x = null;
3 _ = x;3 _ = &x;
4}4}
55
6// error6// error
test/cases/binary_operands.1.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: i32 = 2147483647;2 var i: i32 = 2147483647;
3 _ = &i;
3 if (i +% 1 != -2147483648) unreachable;4 if (i +% 1 != -2147483648) unreachable;
4 return;5 return;
5}6}
test/cases/binary_operands.10.zig+1
...@@ -2,6 +2,7 @@ pub fn main() void {...@@ -2,6 +2,7 @@ pub fn main() void {
2 var i: u32 = 5;2 var i: u32 = 5;
3 i *= 7;3 i *= 7;
4 var result: u32 = foo(i, 10);4 var result: u32 = foo(i, 10);
5 _ = &result;
5 if (result != 350) unreachable;6 if (result != 350) unreachable;
6 return;7 return;
7}8}
test/cases/binary_operands.11.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: i32 = 2147483647;2 var i: i32 = 2147483647;
3 _ = &i;
3 const result = i *% 2;4 const result = i *% 2;
4 if (result != -2) unreachable;5 if (result != -2) unreachable;
5 return;6 return;
test/cases/binary_operands.12.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: u3 = 3;2 var i: u3 = 3;
3 _ = &i;
3 if (i *% 3 != 1) unreachable;4 if (i *% 3 != 1) unreachable;
4 return;5 return;
5}6}
test/cases/binary_operands.13.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: i4 = 3;2 var i: i4 = 3;
3 _ = &i;
3 if (i *% 3 != -7) unreachable;4 if (i *% 3 != -7) unreachable;
4 return;5 return;
5}6}
test/cases/binary_operands.14.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub fn main() void {1pub fn main() void {
2 var i: u32 = 352;2 var i: u32 = 352;
3 i /= 7; // i = 503 i /= 7; // i = 50
4 var result: u32 = foo(i, 7);4 const result: u32 = foo(i, 7);
5 if (result != 7) unreachable;5 if (result != 7) unreachable;
6 return;6 return;
7}7}
test/cases/binary_operands.2.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: i4 = 7;2 var i: i4 = 7;
3 _ = &i;
3 if (i +% 1 != -8) unreachable;4 if (i +% 1 != -8) unreachable;
4 return;5 return;
5}6}
test/cases/binary_operands.3.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var i: u8 = 255;2 var i: u8 = 255;
3 _ = &i;
3 return i +% 1;4 return i +% 1;
4}5}
56
test/cases/binary_operands.4.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var i: u8 = 5;2 var i: u8 = 5;
3 i += 20;3 i += 20;
4 var result: u8 = foo(i, 10);4 const result: u8 = foo(i, 10);
5 return result - 35;5 return result - 35;
6}6}
7fn foo(x: u8, y: u8) u8 {7fn foo(x: u8, y: u8) u8 {
test/cases/binary_operands.6.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: i32 = -2147483648;2 var i: i32 = -2147483648;
3 _ = &i;
3 if (i -% 1 != 2147483647) unreachable;4 if (i -% 1 != 2147483647) unreachable;
4 return;5 return;
5}6}
test/cases/binary_operands.7.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: i7 = -64;2 var i: i7 = -64;
3 _ = &i;
3 if (i -% 1 != 63) unreachable;4 if (i -% 1 != 63) unreachable;
4 return;5 return;
5}6}
test/cases/binary_operands.8.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var i: u4 = 0;2 var i: u4 = 0;
3 _ = &i;
3 if (i -% 1 != 15) unreachable;4 if (i -% 1 != 15) unreachable;
4}5}
56
test/cases/binary_operands.9.zig+1
...@@ -2,6 +2,7 @@ pub fn main() u8 {...@@ -2,6 +2,7 @@ pub fn main() u8 {
2 var i: u8 = 5;2 var i: u8 = 5;
3 i -= 3;3 i -= 3;
4 var result: u8 = foo(i, 10);4 var result: u8 = foo(i, 10);
5 _ = &result;
5 return result - 8;6 return result - 8;
6}7}
7fn foo(x: u8, y: u8) u8 {8fn foo(x: u8, y: u8) u8 {
test/cases/comparison_of_non-tagged_union_and_enum_literal.zig+2-1
...@@ -2,7 +2,8 @@ export fn entry() void {...@@ -2,7 +2,8 @@ export fn entry() void {
2 const U = union { A: u32, B: u64 };2 const U = union { A: u32, B: u64 };
3 var u = U{ .A = 42 };3 var u = U{ .A = 42 };
4 var ok = u == .A;4 var ok = u == .A;
5 _ = ok;5 _ = &u;
6 _ = &ok;
6}7}
78
8// error9// error
test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig+1-1
...@@ -6,7 +6,7 @@ const S2 = struct {...@@ -6,7 +6,7 @@ const S2 = struct {
6};6};
7pub export fn entry() void {7pub export fn entry() void {
8 var s: S1 = undefined;8 var s: S1 = undefined;
9 _ = s;9 _ = &s;
10}10}
1111
12// error12// error
test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const Foo = struct { a: u32 };1const Foo = struct { a: u32 };
2export fn a() void {2export fn a() void {
3 const T = [*c]Foo;3 const T = [*c]Foo;
4 var t: T = undefined;4 const t: T = undefined;
5 _ = t;5 _ = t;
6}6}
77
test/cases/compile_errors/C_pointer_to_anyopaque.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn a() void {1export fn a() void {
2 var x: *anyopaque = undefined;2 var x: *anyopaque = undefined;
3 var y: [*c]anyopaque = x;3 var y: [*c]anyopaque = x;
4 _ = y;4 _ = .{ &x, &y };
5}5}
66
7// error7// error
test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig+2-2
...@@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 {...@@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 {
7 return st.get;7 return st.get;
8}8}
9export fn entry() void {9export fn entry() void {
10 var func = outer(10);10 const func = outer(10);
11 var x = func(3);11 const x = func(3);
12 _ = x;12 _ = x;
13}13}
1414
test/cases/compile_errors/add_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: i64 = undefined;2 const a: i64 = undefined;
3 _ = a + a;3 _ = a + a;
4}4}
55
test/cases/compile_errors/alignment_of_enum_field_specified.zig+1-1
...@@ -6,7 +6,7 @@ const Number = enum {...@@ -6,7 +6,7 @@ const Number = enum {
6// zig fmt: on6// zig fmt: on
77
8export fn entry1() void {8export fn entry1() void {
9 var x: Number = undefined;9 const x: Number = undefined;
10 _ = x;10 _ = x;
11}11}
1212
test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig+6-6
...@@ -1,17 +1,17 @@...@@ -1,17 +1,17 @@
1export fn entry1() void {1export fn entry1() void {
2 var f: f32 = 54.0 / 5;2 const f: f32 = 54.0 / 5;
3 _ = f;3 _ = f;
4}4}
5export fn entry2() void {5export fn entry2() void {
6 var f: f32 = 54 / 5.0;6 const f: f32 = 54 / 5.0;
7 _ = f;7 _ = f;
8}8}
9export fn entry3() void {9export fn entry3() void {
10 var f: f32 = 55.0 / 5;10 const f: f32 = 55.0 / 5;
11 _ = f;11 _ = f;
12}12}
13export fn entry4() void {13export fn entry4() void {
14 var f: f32 = 55 / 5.0;14 const f: f32 = 55 / 5.0;
15 _ = f;15 _ = f;
16}16}
1717
...@@ -19,5 +19,5 @@ export fn entry4() void {...@@ -19,5 +19,5 @@ export fn entry4() void {
19// backend=stage219// backend=stage2
20// target=native20// target=native
21//21//
22// :2:23: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4'22// :2:25: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4'
23// :6:21: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4'23// :6:23: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4'
test/cases/compile_errors/and_on_undefined_value.zig+2-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1comptime {1comptime {
2 var a: bool = undefined;2 var a: bool = undefined;
3 _ = &a;
3 _ = a and a;4 _ = a and a;
4}5}
56
...@@ -7,4 +8,4 @@ comptime {...@@ -7,4 +8,4 @@ comptime {
7// backend=stage28// backend=stage2
8// target=native9// target=native
9//10//
10// :3:9: error: use of undefined value here causes undefined behavior11// :4:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/array_access_of_non_array.zig+1-1
...@@ -3,7 +3,7 @@ export fn f() void {...@@ -3,7 +3,7 @@ export fn f() void {
3 bad[0] = bad[0];3 bad[0] = bad[0];
4}4}
5export fn g() void {5export fn g() void {
6 var bad: bool = undefined;6 const bad: bool = undefined;
7 _ = bad[0];7 _ = bad[0];
8}8}
99
test/cases/compile_errors/array_access_of_type.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn foo() void {1export fn foo() void {
2 var b: u8[40] = undefined;2 var b: u8[40] = undefined;
3 _ = b;3 _ = &b;
4}4}
55
6// error6// error
test/cases/compile_errors/array_access_with_non_integer_index.zig+3-1
...@@ -2,11 +2,13 @@ export fn f() void {...@@ -2,11 +2,13 @@ export fn f() void {
2 var array = "aoeu";2 var array = "aoeu";
3 var bad = false;3 var bad = false;
4 array[bad] = array[bad];4 array[bad] = array[bad];
5 _ = &bad;
5}6}
6export fn g() void {7export fn g() void {
7 var array = "aoeu";8 var array = "aoeu";
8 var bad = false;9 var bad = false;
9 _ = array[bad];10 _ = array[bad];
11 _ = .{ &array, &bad };
10}12}
1113
12// error14// error
...@@ -14,4 +16,4 @@ export fn g() void {...@@ -14,4 +16,4 @@ export fn g() void {
14// target=native16// target=native
15//17//
16// :4:11: error: expected type 'usize', found 'bool'18// :4:11: error: expected type 'usize', found 'bool'
17// :9:15: error: expected type 'usize', found 'bool'19// :10:15: error: expected type 'usize', found 'bool'
test/cases/compile_errors/array_init_invalid_elem_count.zig+6-6
...@@ -2,27 +2,27 @@ const V = @Vector(8, u8);...@@ -2,27 +2,27 @@ const V = @Vector(8, u8);
2const A = [8]u8;2const A = [8]u8;
3comptime {3comptime {
4 var v: V = V{1};4 var v: V = V{1};
5 _ = v;5 _ = &v;
6}6}
7comptime {7comptime {
8 var v: V = V{};8 var v: V = V{};
9 _ = v;9 _ = &v;
10}10}
11comptime {11comptime {
12 var a: A = A{1};12 var a: A = A{1};
13 _ = a;13 _ = &a;
14}14}
15comptime {15comptime {
16 var a: A = A{};16 var a: A = A{};
17 _ = a;17 _ = &a;
18}18}
19pub export fn entry1() void {19pub export fn entry1() void {
20 var bla: V = .{ 1, 2, 3, 4 };20 var bla: V = .{ 1, 2, 3, 4 };
21 _ = bla;21 _ = &bla;
22}22}
23pub export fn entry2() void {23pub export fn entry2() void {
24 var bla: A = .{ 1, 2, 3, 4 };24 var bla: A = .{ 1, 2, 3, 4 };
25 _ = bla;25 _ = &bla;
26}26}
27const S = struct {27const S = struct {
28 list: [2]u8 = .{0},28 list: [2]u8 = .{0},
test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var a = &b;2 var a = &b;
3 _ = a;3 _ = &a;
4}4}
5inline fn b() void {}5inline fn b() void {}
66
test/cases/compile_errors/assign_local_bad_coercion.zig+1-1
...@@ -9,7 +9,7 @@ export fn constEntry() u32 {...@@ -9,7 +9,7 @@ export fn constEntry() u32 {
99
10export fn varEntry() u32 {10export fn varEntry() u32 {
11 var x: u32 = g();11 var x: u32 = g();
12 return x;12 return (&x).*;
13}13}
1414
15// error15// error
test/cases/compile_errors/assign_too_big_number_to_u16.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn foo() void {1export fn foo() void {
2 var vga_mem: u16 = 0xB8000;2 const vga_mem: u16 = 0xB8000;
3 _ = vga_mem;3 _ = vga_mem;
4}4}
55
...@@ -7,4 +7,4 @@ export fn foo() void {...@@ -7,4 +7,4 @@ export fn foo() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:24: error: type 'u16' cannot represent integer value '753664'10// :2:26: error: type 'u16' cannot represent integer value '753664'
test/cases/compile_errors/assigning_to_struct_or_union_fields_that_are_not_optionals_with_a_function_that_returns_an_optional.zig+2-2
...@@ -10,8 +10,8 @@ const S = struct {...@@ -10,8 +10,8 @@ const S = struct {
10export fn entry() void {10export fn entry() void {
11 var u = U{ .Ye = maybe(false) };11 var u = U{ .Ye = maybe(false) };
12 var s = S{ .num = maybe(false) };12 var s = S{ .num = maybe(false) };
13 _ = u;13 _ = &u;
14 _ = s;14 _ = &s;
15}15}
1616
17// error17// error
test/cases/compile_errors/async/Frame_of_generic_function.zig+2-2
...@@ -1,10 +1,10 @@...@@ -1,10 +1,10 @@
1export fn entry() void {1export fn entry() void {
2 var frame: @Frame(func) = undefined;2 var frame: @Frame(func) = undefined;
3 _ = frame;3 _ = &frame;
4}4}
5fn func(comptime T: type) void {5fn func(comptime T: type) void {
6 var x: T = undefined;6 var x: T = undefined;
7 _ = x;7 _ = &x;
8}8}
99
10// error10// error
test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig+1-1
...@@ -3,7 +3,7 @@ export fn entry() void {...@@ -3,7 +3,7 @@ export fn entry() void {
3}3}
4fn amain() callconv(.Async) void {4fn amain() callconv(.Async) void {
5 var x: [@sizeOf(@Frame(amain))]u8 = undefined;5 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
6 _ = x;6 _ = &x;
7}7}
88
9// error9// error
test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig+1-1
...@@ -6,7 +6,7 @@ fn amain() callconv(.Async) void {...@@ -6,7 +6,7 @@ fn amain() callconv(.Async) void {
6}6}
7fn other() void {7fn other() void {
8 var x: [@sizeOf(@Frame(amain))]u8 = undefined;8 var x: [@sizeOf(@Frame(amain))]u8 = undefined;
9 _ = x;9 _ = &x;
10}10}
1111
12// error12// error
test/cases/compile_errors/async/bad_alignment_in_asynccall.zig+1
...@@ -2,6 +2,7 @@ export fn entry() void {...@@ -2,6 +2,7 @@ export fn entry() void {
2 var ptr: fn () callconv(.Async) void = func;2 var ptr: fn () callconv(.Async) void = func;
3 var bytes: [64]u8 = undefined;3 var bytes: [64]u8 = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});4 _ = @asyncCall(&bytes, {}, ptr, .{});
5 _ = &ptr;
5}6}
6fn func() callconv(.Async) void {}7fn func() callconv(.Async) void {}
78
test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig+1-1
...@@ -5,7 +5,7 @@ export fn a() void {...@@ -5,7 +5,7 @@ export fn a() void {
5export fn b() void {5export fn b() void {
6 const f = async func();6 const f = async func();
7 var x: anyframe = &f;7 var x: anyframe = &f;
8 _ = x;8 _ = &x;
9}9}
10fn func() void {10fn func() void {
11 suspend {}11 suspend {}
test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig+4-4
...@@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 {...@@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 {
12 frame = null;12 frame = null;
1313
14 if (x == 0) return 0;14 if (x == 0) return 0;
15 var child = rangeSumIndirect(x - 1);15 const child = rangeSumIndirect(x - 1);
16 return child + 1;16 return child + 1;
17}17}
1818
...@@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 {...@@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 {
23 frame = null;23 frame = null;
2424
25 if (x == 0) return 0;25 if (x == 0) return 0;
26 var child = rangeSum(x - 1);26 const child = rangeSum(x - 1);
27 return child + 1;27 return child + 1;
28}28}
2929
...@@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 {...@@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 {
32// target=native32// target=native
33//33//
34// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself34// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
35// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here35// tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here
36// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here36// tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn entry() void {1export fn entry() void {
2 var frame = async func();2 var frame = async func();
3 var result = await frame;3 var result = await frame;
4 _ = result;4 _ = &result;
5}5}
6fn func() void {6fn func() void {
7 suspend {}7 suspend {}
test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig+1
...@@ -2,6 +2,7 @@ export fn entry() void {...@@ -2,6 +2,7 @@ export fn entry() void {
2 var ptr = afunc;2 var ptr = afunc;
3 var bytes: [100]u8 align(16) = undefined;3 var bytes: [100]u8 align(16) = undefined;
4 _ = @asyncCall(&bytes, {}, ptr, .{});4 _ = @asyncCall(&bytes, {}, ptr, .{});
5 _ = &ptr;
5}6}
6fn afunc() void {}7fn afunc() void {}
78
test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig+3-3
...@@ -1,17 +1,17 @@...@@ -1,17 +1,17 @@
1export fn a() void {1export fn a() void {
2 var x: anyframe = undefined;2 var x: anyframe = undefined;
3 var y: anyframe->i32 = x;3 var y: anyframe->i32 = x;
4 _ = y;4 _ = .{ &x, &y };
5}5}
6export fn b() void {6export fn b() void {
7 var x: i32 = undefined;7 var x: i32 = undefined;
8 var y: anyframe->i32 = x;8 var y: anyframe->i32 = x;
9 _ = y;9 _ = .{ &x, &y };
10}10}
11export fn c() void {11export fn c() void {
12 var x: @Frame(func) = undefined;12 var x: @Frame(func) = undefined;
13 var y: anyframe->i32 = &x;13 var y: anyframe->i32 = &x;
14 _ = y;14 _ = .{ &x, &y };
15}15}
16fn func() void {}16fn func() void {}
1717
test/cases/compile_errors/async/runtime-known_async_function_called.zig+1
...@@ -4,6 +4,7 @@ export fn entry() void {...@@ -4,6 +4,7 @@ export fn entry() void {
4fn amain() void {4fn amain() void {
5 var ptr = afunc;5 var ptr = afunc;
6 _ = ptr();6 _ = ptr();
7 _ = &ptr;
7}8}
8fn afunc() callconv(.Async) void {}9fn afunc() callconv(.Async) void {}
910
test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1export fn entry() void {1export fn entry() void {
2 var ptr = afunc;2 var ptr = afunc;
3 _ = async ptr();3 _ = async ptr();
4 _ = &ptr;
4}5}
56
6fn afunc() callconv(.Async) void {}7fn afunc() callconv(.Async) void {}
test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig+2-2
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1export fn entry(byte: u8) void {1export fn entry() void {
2 const w: i32 = 1234;2 const w: i32 = 1234;
3 var x: *const i32 = &w;3 var x: *const i32 = &w;
4 var y: *[1]i32 = x;4 var y: *[1]i32 = x;
5 y[0] += 1;5 y[0] += 1;
6 _ = byte;6 _ = &x;
7}7}
88
9// error9// error
test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn a() void {1export fn a() void {
2 var x: [10]u8 = undefined;2 var x: [10]u8 = undefined;
3 var y: []align(16) u8 = &x;3 const y: []align(16) u8 = &x;
4 _ = y;4 _ = y;
5}5}
66
...@@ -8,5 +8,5 @@ export fn a() void {...@@ -8,5 +8,5 @@ export fn a() void {
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :3:29: error: expected type '[]align(16) u8', found '*[10]u8'11// :3:31: error: expected type '[]align(16) u8', found '*[10]u8'
12// :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16'12// :3:31: note: pointer alignment '1' cannot cast into pointer alignment '16'
test/cases/compile_errors/bad_alignment_type.zig+4-4
...@@ -1,9 +1,9 @@...@@ -1,9 +1,9 @@
1export fn entry1() void {1export fn entry1() void {
2 var x: []align(true) i32 = undefined;2 const x: []align(true) i32 = undefined;
3 _ = x;3 _ = x;
4}4}
5export fn entry2() void {5export fn entry2() void {
6 var x: *align(@as(f64, 12.34)) i32 = undefined;6 const x: *align(@as(f64, 12.34)) i32 = undefined;
7 _ = x;7 _ = x;
8}8}
99
...@@ -11,5 +11,5 @@ export fn entry2() void {...@@ -11,5 +11,5 @@ export fn entry2() void {
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :2:20: error: expected type 'u32', found 'bool'14// :2:22: error: expected type 'u32', found 'bool'
15// :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32'15// :6:21: error: fractional component prevents float value '12.34' from coercion to type 'u32'
test/cases/compile_errors/bad_usage_of_call.zig+3-2
...@@ -11,7 +11,7 @@ export fn entry4() void {...@@ -11,7 +11,7 @@ export fn entry4() void {
11 @call(.never_inline, bar, .{});11 @call(.never_inline, bar, .{});
12}12}
13export fn entry5(c: bool) void {13export fn entry5(c: bool) void {
14 var baz = if (c) &baz1 else &baz2;14 const baz = if (c) &baz1 else &baz2;
15 @call(.compile_time, baz, .{});15 @call(.compile_time, baz, .{});
16}16}
17export fn entry6() void {17export fn entry6() void {
...@@ -22,6 +22,7 @@ export fn entry7() void {...@@ -22,6 +22,7 @@ export fn entry7() void {
22}22}
23pub export fn entry() void {23pub export fn entry() void {
24 var call_me: *const fn () void = undefined;24 var call_me: *const fn () void = undefined;
25 _ = &call_me;
25 @call(.always_inline, call_me, .{});26 @call(.always_inline, call_me, .{});
26}27}
2728
...@@ -45,4 +46,4 @@ noinline fn dummy2() void {}...@@ -45,4 +46,4 @@ noinline fn dummy2() void {}
45// :15:26: error: modifier 'compile_time' requires a comptime-known function46// :15:26: error: modifier 'compile_time' requires a comptime-known function
46// :18:9: error: 'always_inline' call of noinline function47// :18:9: error: 'always_inline' call of noinline function
47// :21:9: error: 'always_inline' call of noinline function48// :21:9: error: 'always_inline' call of noinline function
48// :25:27: error: modifier 'always_inline' requires a comptime-known function49// :26:27: error: modifier 'always_inline' requires a comptime-known function
test/cases/compile_errors/binary_OR_operator_on_error_sets.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub const A = error.A;1pub const A = error.A;
2pub const AB = A | error.B;2pub const AB = A | error.B;
3export fn entry() void {3export fn entry() void {
4 var x: AB = undefined;4 const x: AB = undefined;
5 _ = x;5 _ = x;
6}6}
77
test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry(byte: u8) void {1export fn entry(byte: u8) void {
2 var oops: u7 = @bitCast(byte);2 const oops: u7 = @bitCast(byte);
3 _ = oops;3 _ = oops;
4}4}
55
...@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {...@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits10// :2:22: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
test/cases/compile_errors/bitCast_with_different_sizes_inside_an_expression.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf);2 const f: f32 = 1.0;
3 const foo = (@as(u8, @bitCast(f)) == 0xf);
3 _ = foo;4 _ = foo;
4}5}
56
...@@ -7,4 +8,4 @@ export fn entry() void {...@@ -7,4 +8,4 @@ export fn entry() void {
7// backend=stage28// backend=stage2
8// target=native9// target=native
9//10//
10// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits11// :3:26: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits
test/cases/compile_errors/branch_in_comptime_only_scope_uses_condbr_inline.zig+5-3
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub export fn entry1() void {1pub export fn entry1() void {
2 var x: u32 = 3;2 var x: u32 = 3;
3 _ = &x;
3 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{4 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
4 if (x > 1) 1 else -1,5 if (x > 1) 1 else -1,
5 });6 });
...@@ -7,6 +8,7 @@ pub export fn entry1() void {...@@ -7,6 +8,7 @@ pub export fn entry1() void {
78
8pub export fn entry2() void {9pub export fn entry2() void {
9 var y: ?i8 = -1;10 var y: ?i8 = -1;
11 _ = &y;
10 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{12 _ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
11 y orelse 1,13 y orelse 1,
12 });14 });
...@@ -16,6 +18,6 @@ pub export fn entry2() void {...@@ -16,6 +18,6 @@ pub export fn entry2() void {
16// backend=stage218// backend=stage2
17// target=native19// target=native
18//20//
19// :4:15: error: unable to evaluate comptime expression21// :5:15: error: unable to evaluate comptime expression
20// :4:13: note: operation is runtime due to this operand22// :5:13: note: operation is runtime due to this operand
21// :11:11: error: unable to evaluate comptime expression23// :13:11: error: unable to evaluate comptime expression
test/cases/compile_errors/break_void_result_location.zig+3-2
...@@ -10,6 +10,7 @@ export fn f2() void {...@@ -10,6 +10,7 @@ export fn f2() void {
10}10}
11export fn f3() void {11export fn f3() void {
12 var t: bool = true;12 var t: bool = true;
13 _ = &t;
13 const x: usize = while (t) {14 const x: usize = while (t) {
14 break;15 break;
15 };16 };
...@@ -28,5 +29,5 @@ export fn f4() void {...@@ -28,5 +29,5 @@ export fn f4() void {
28//29//
29// :2:22: error: expected type 'usize', found 'void'30// :2:22: error: expected type 'usize', found 'void'
30// :7:9: error: expected type 'usize', found 'void'31// :7:9: error: expected type 'usize', found 'void'
31// :14:9: error: expected type 'usize', found 'void'32// :15:9: error: expected type 'usize', found 'void'
32// :20:9: error: expected type 'usize', found 'void'33// :21:9: error: expected type 'usize', found 'void'
test/cases/compile_errors/c_pointer_to_void.zig+3-3
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var a: [*c]void = undefined;2 const a: [*c]void = undefined;
3 _ = a;3 _ = a;
4}4}
55
...@@ -7,5 +7,5 @@ export fn entry() void {...@@ -7,5 +7,5 @@ export fn entry() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:16: error: C pointers cannot point to non-C-ABI-compatible type 'void'10// :2:18: error: C pointers cannot point to non-C-ABI-compatible type 'void'
11// :2:16: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'11// :2:18: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig+3-3
...@@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void;...@@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {4export fn entry1() void {
5 var a: F1 = undefined;5 const a: F1 = undefined;
6 _ = a;6 _ = a;
7}7}
8export fn entry2() void {8export fn entry2() void {
9 var a: F2 = undefined;9 const a: F2 = undefined;
10 _ = a;10 _ = a;
11}11}
12export fn entry3() void {12export fn entry3() void {
13 var a: F3 = undefined;13 const a: F3 = undefined;
14 _ = a;14 _ = a;
15}15}
1616
test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig+5-3
...@@ -4,6 +4,7 @@ export fn entry1() void {...@@ -4,6 +4,7 @@ export fn entry1() void {
4 var a: fnty1 = undefined;4 var a: fnty1 = undefined;
5 var b: fnty2 = undefined;5 var b: fnty2 = undefined;
6 a = b;6 a = b;
7 _ = &b;
7}8}
89
9pub const fnty3 = ?*const fn (u63) void;10pub const fnty3 = ?*const fn (u63) void;
...@@ -11,6 +12,7 @@ export fn entry2() void {...@@ -11,6 +12,7 @@ export fn entry2() void {
11 var a: fnty3 = undefined;12 var a: fnty3 = undefined;
12 var b: fnty2 = undefined;13 var b: fnty2 = undefined;
13 a = b;14 a = b;
15 _ = &b;
14}16}
1517
16// error18// error
...@@ -21,6 +23,6 @@ export fn entry2() void {...@@ -21,6 +23,6 @@ export fn entry2() void {
21// :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void'23// :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void'
22// :6:9: note: parameter 0 'u64' cannot cast into 'i8'24// :6:9: note: parameter 0 'u64' cannot cast into 'i8'
23// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values25// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
24// :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'26// :14:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
25// :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'27// :14:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
26// :13:9: note: parameter 0 'u64' cannot cast into 'u63'28// :14:9: note: parameter 0 'u64' cannot cast into 'u63'
test/cases/compile_errors/cast_error_union_of_global_error_set_to_error_union_of_smaller_error_set.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const SmallErrorSet = error{A};1const SmallErrorSet = error{A};
2export fn entry() void {2export fn entry() void {
3 var x: SmallErrorSet!i32 = foo();3 const x: SmallErrorSet!i32 = foo();
4 _ = x;4 _ = x;
5}5}
6fn foo() anyerror!i32 {6fn foo() anyerror!i32 {
...@@ -11,5 +11,5 @@ fn foo() anyerror!i32 {...@@ -11,5 +11,5 @@ fn foo() anyerror!i32 {
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :3:35: error: expected type 'error{A}!i32', found 'anyerror!i32'14// :3:37: error: expected type 'error{A}!i32', found 'anyerror!i32'
15// :3:35: note: global error set cannot cast into a smaller set15// :3:37: note: global error set cannot cast into a smaller set
test/cases/compile_errors/cast_global_error_set_to_error_set.zig+3-3
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const SmallErrorSet = error{A};1const SmallErrorSet = error{A};
2export fn entry() void {2export fn entry() void {
3 var x: SmallErrorSet = foo();3 const x: SmallErrorSet = foo();
4 _ = x;4 _ = x;
5}5}
6fn foo() anyerror {6fn foo() anyerror {
...@@ -11,5 +11,5 @@ fn foo() anyerror {...@@ -11,5 +11,5 @@ fn foo() anyerror {
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :3:31: error: expected type 'error{A}', found 'anyerror'14// :3:33: error: expected type 'error{A}', found 'anyerror'
15// :3:31: note: global error set cannot cast into a smaller set15// :3:33: note: global error set cannot cast into a smaller set
test/cases/compile_errors/catch_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: anyerror!bool = undefined;2 const a: anyerror!bool = undefined;
3 if (a catch false) {}3 if (a catch false) {}
4}4}
55
test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig+2-2
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var x: ?[3]i32 = undefined;2 const x: ?[3]i32 = undefined;
3 var y: [3]i32 = undefined;3 const y: [3]i32 = undefined;
4 _ = (x == y);4 _ = (x == y);
5}5}
66
test/cases/compile_errors/comparison_operators_with_undefined_value.zig+6-6
...@@ -1,36 +1,36 @@...@@ -1,36 +1,36 @@
1// operator ==1// operator ==
2comptime {2comptime {
3 var a: i64 = undefined;3 const a: i64 = undefined;
4 var x: i32 = 0;4 var x: i32 = 0;
5 if (a == a) x += 1;5 if (a == a) x += 1;
6}6}
7// operator !=7// operator !=
8comptime {8comptime {
9 var a: i64 = undefined;9 const a: i64 = undefined;
10 var x: i32 = 0;10 var x: i32 = 0;
11 if (a != a) x += 1;11 if (a != a) x += 1;
12}12}
13// operator >13// operator >
14comptime {14comptime {
15 var a: i64 = undefined;15 const a: i64 = undefined;
16 var x: i32 = 0;16 var x: i32 = 0;
17 if (a > a) x += 1;17 if (a > a) x += 1;
18}18}
19// operator <19// operator <
20comptime {20comptime {
21 var a: i64 = undefined;21 const a: i64 = undefined;
22 var x: i32 = 0;22 var x: i32 = 0;
23 if (a < a) x += 1;23 if (a < a) x += 1;
24}24}
25// operator >=25// operator >=
26comptime {26comptime {
27 var a: i64 = undefined;27 const a: i64 = undefined;
28 var x: i32 = 0;28 var x: i32 = 0;
29 if (a >= a) x += 1;29 if (a >= a) x += 1;
30}30}
31// operator <=31// operator <=
32comptime {32comptime {
33 var a: i64 = undefined;33 const a: i64 = undefined;
34 var x: i32 = 0;34 var x: i32 = 0;
35 if (a <= a) x += 1;35 if (a <= a) x += 1;
36}36}
test/cases/compile_errors/compile_error_in_struct_init_expression.zig+1-1
...@@ -3,7 +3,7 @@ const Foo = struct {...@@ -3,7 +3,7 @@ const Foo = struct {
3 b: i32,3 b: i32,
4};4};
5export fn entry() void {5export fn entry() void {
6 var x = Foo{6 const x: Foo = .{
7 .b = 5,7 .b = 5,
8 };8 };
9 _ = x;9 _ = x;
test/cases/compile_errors/compile_time_null_ptr_cast.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var opt_ptr: ?*i32 = null;2 const opt_ptr: ?*i32 = null;
3 const ptr: *i32 = @ptrCast(opt_ptr);3 const ptr: *i32 = @ptrCast(opt_ptr);
4 _ = ptr;4 _ = ptr;
5}5}
test/cases/compile_errors/compile_time_undef_ptr_cast.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1comptime {1comptime {
2 var undef_ptr: *i32 = undefined;2 var undef_ptr: *i32 = undefined;
3 const ptr: *i32 = @ptrCast(undef_ptr);3 const ptr: *i32 = @ptrCast(undef_ptr);
4 _ = &undef_ptr;
4 _ = ptr;5 _ = ptr;
5}6}
67
test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig+1-1
...@@ -6,7 +6,7 @@ const Value = union(Letter) {...@@ -6,7 +6,7 @@ const Value = union(Letter) {
6};6};
7export fn entry() void {7export fn entry() void {
8 var x: Value = Letter.A;8 var x: Value = Letter.A;
9 _ = x;9 _ = &x;
10}10}
1111
12// error12// error
test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: usize = undefined;2 var p: usize = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 inline while (q) {5 inline while (q) {
5 if (p == 11) continue;6 if (p == 11) continue;
...@@ -11,5 +12,5 @@ export fn entry() void {...@@ -11,5 +12,5 @@ export fn entry() void {
11// backend=stage212// backend=stage2
12// target=native13// target=native
13//14//
14// :5:22: error: comptime control flow inside runtime block15// :6:22: error: comptime control flow inside runtime block
15// :5:15: note: runtime control flow here16// :6:15: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: anyerror!i32 = undefined;2 var p: anyerror!i32 = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 inline while (q) {5 inline while (q) {
5 if (p) |_| continue else |_| {}6 if (p) |_| continue else |_| {}
...@@ -11,5 +12,5 @@ export fn entry() void {...@@ -11,5 +12,5 @@ export fn entry() void {
11// backend=stage212// backend=stage2
12// target=native13// target=native
13//14//
14// :5:20: error: comptime control flow inside runtime block15// :6:20: error: comptime control flow inside runtime block
15// :5:13: note: runtime control flow here16// :6:13: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: ?i32 = undefined;2 var p: ?i32 = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 inline while (q) {5 inline while (q) {
5 if (p) |_| continue;6 if (p) |_| continue;
...@@ -11,5 +12,5 @@ export fn entry() void {...@@ -11,5 +12,5 @@ export fn entry() void {
11// backend=stage212// backend=stage2
12// target=native13// target=native
13//14//
14// :5:20: error: comptime control flow inside runtime block15// :6:20: error: comptime control flow inside runtime block
15// :5:13: note: runtime control flow here16// :6:13: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: i32 = undefined;2 var p: i32 = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 inline while (q) {5 inline while (q) {
5 switch (p) {6 switch (p) {
...@@ -14,5 +15,5 @@ export fn entry() void {...@@ -14,5 +15,5 @@ export fn entry() void {
14// backend=stage215// backend=stage2
15// target=native16// target=native
16//17//
17// :6:19: error: comptime control flow inside runtime block18// :7:19: error: comptime control flow inside runtime block
18// :5:17: note: runtime control flow here19// :6:17: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: usize = undefined;2 var p: usize = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 outer: inline while (q) {5 outer: inline while (q) {
5 while (p == 11) continue :outer;6 while (p == 11) continue :outer;
...@@ -11,5 +12,5 @@ export fn entry() void {...@@ -11,5 +12,5 @@ export fn entry() void {
11// backend=stage212// backend=stage2
12// target=native13// target=native
13//14//
14// :5:25: error: comptime control flow inside runtime block15// :6:25: error: comptime control flow inside runtime block
15// :5:18: note: runtime control flow here16// :6:18: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: anyerror!usize = undefined;2 var p: anyerror!usize = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 outer: inline while (q) {5 outer: inline while (q) {
5 while (p) |_| {6 while (p) |_| {
...@@ -13,5 +14,5 @@ export fn entry() void {...@@ -13,5 +14,5 @@ export fn entry() void {
13// backend=stage214// backend=stage2
14// target=native15// target=native
15//16//
16// :6:13: error: comptime control flow inside runtime block17// :7:13: error: comptime control flow inside runtime block
17// :5:16: note: runtime control flow here18// :6:16: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var p: ?usize = undefined;2 var p: ?usize = undefined;
3 _ = &p;
3 comptime var q = true;4 comptime var q = true;
4 outer: inline while (q) {5 outer: inline while (q) {
5 while (p) |_| continue :outer;6 while (p) |_| continue :outer;
...@@ -11,5 +12,5 @@ export fn entry() void {...@@ -11,5 +12,5 @@ export fn entry() void {
11// backend=stage212// backend=stage2
12// target=native13// target=native
13//14//
14// :5:23: error: comptime control flow inside runtime block15// :6:23: error: comptime control flow inside runtime block
15// :5:16: note: runtime control flow here16// :6:16: note: runtime control flow here
test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var a = false;2 var a = false;
3 _ = &a;
3 const arr1 = .{ 1, 2, 3 };4 const arr1 = .{ 1, 2, 3 };
4 loop: inline for (arr1) |val1| {5 loop: inline for (arr1) |val1| {
5 _ = val1;6 _ = val1;
...@@ -17,5 +18,5 @@ pub export fn entry() void {...@@ -17,5 +18,5 @@ pub export fn entry() void {
17// backend=stage218// backend=stage2
18// target=native19// target=native
19//20//
20// :9:30: error: comptime control flow inside runtime block21// :10:30: error: comptime control flow inside runtime block
21// :6:13: note: runtime control flow here22// :7:13: note: runtime control flow here
test/cases/compile_errors/comptime_if_inside_runtime_for.zig+4-3
...@@ -1,8 +1,9 @@...@@ -1,8 +1,9 @@
1export fn entry() void {1export fn entry() void {
2 var x: u32 = 0;2 var x: u32 = 0;
3 _ = &x;
3 for (0..1, 1..2) |_, _| {4 for (0..1, 1..2) |_, _| {
4 var y = x + if (x == 0) 1 else 0;5 var y = x + if (x == 0) 1 else 0;
5 _ = y;6 _ = &y;
6 }7 }
7}8}
89
...@@ -10,5 +11,5 @@ export fn entry() void {...@@ -10,5 +11,5 @@ export fn entry() void {
10// backend=stage211// backend=stage2
11// target=native12// target=native
12//13//
13// :4:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow14// :5:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow
14// :3:10: note: runtime control flow here15// :4:10: note: runtime control flow here
test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1comptime {1comptime {
2 var a: []u8 = undefined;2 var a: []u8 = undefined;
3 var b = a[0..10];3 var b = a[0..10];
4 _ = b;4 _ = &b;
5}5}
66
7// error7// error
test/cases/compile_errors/comptime_struct_field_no_init_value.zig+1-1
...@@ -3,7 +3,7 @@ const Foo = struct {...@@ -3,7 +3,7 @@ const Foo = struct {
3};3};
4export fn entry() void {4export fn entry() void {
5 var f: Foo = undefined;5 var f: Foo = undefined;
6 _ = f;6 _ = &f;
7}7}
88
9// error9// error
test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig+1-1
...@@ -2,7 +2,7 @@ comptime {...@@ -2,7 +2,7 @@ comptime {
2 var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };2 var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
3 var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };3 var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
4 var x = a + b;4 var x = a + b;
5 _ = x;5 _ = .{ &a, &b, &x };
6}6}
77
8// error8// error
test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig+2-4
...@@ -1,9 +1,7 @@...@@ -1,9 +1,7 @@
1const ContextAllocator = MemoryPool(usize);1const ContextAllocator = MemoryPool(usize);
22
3pub fn MemoryPool(comptime T: type) type {3pub fn MemoryPool(comptime T: type) type {
4 const free_list_t = @compileError(4 const free_list_t = @compileError("aoeu");
5 "aoeu",
6 );
7 _ = T;5 _ = T;
86
9 return struct {7 return struct {
...@@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type {...@@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type {
12}10}
1311
14export fn entry() void {12export fn entry() void {
15 var allocator: ContextAllocator = undefined;13 const allocator: ContextAllocator = undefined;
16 _ = allocator;14 _ = allocator;
17}15}
1816
test/cases/compile_errors/deref_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: *u8 = undefined;2 const a: *u8 = undefined;
3 _ = a.*;3 _ = a.*;
4}4}
55
test/cases/compile_errors/deref_slice_and_get_len_field.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1export fn entry() void {1export fn entry() void {
2 var a: []u8 = undefined;2 var a: []u8 = undefined;
3 _ = a.*.len;3 _ = a.*.len;
4 _ = &a;
4}5}
56
6// error7// error
test/cases/compile_errors/dereference_an_array.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1var s_buffer: [10]u8 = undefined;1var s_buffer: [10]u8 = undefined;
2pub fn pass(in: []u8) []u8 {2pub fn pass(in: []u8) []u8 {
3 var out = &s_buffer;3 var out = &s_buffer;
4 _ = &out;
4 out.*.* = in[0];5 out.*.* = in[0];
5 return out.*[0..1];6 return out.*[0..1];
6}7}
...@@ -13,4 +14,4 @@ export fn entry() usize {...@@ -13,4 +14,4 @@ export fn entry() usize {
13// backend=stage214// backend=stage2
14// target=native15// target=native
15//16//
16// :4:10: error: cannot dereference non-pointer type '[10]u8'17// :5:10: error: cannot dereference non-pointer type '[10]u8'
test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig+1-1
...@@ -16,7 +16,7 @@ comptime {...@@ -16,7 +16,7 @@ comptime {
16 _ = payload_ptr.*;16 _ = payload_ptr.*;
17}17}
18comptime {18comptime {
19 var val: u8 = 15;19 const val: u8 = 15;
20 var err_union: anyerror!u8 = val;20 var err_union: anyerror!u8 = val;
2121
22 const payload_ptr = &(err_union catch unreachable);22 const payload_ptr = &(err_union catch unreachable);
test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig+2-2
...@@ -8,11 +8,11 @@ const Bar = union {...@@ -8,11 +8,11 @@ const Bar = union {
8};8};
9export fn a() void {9export fn a() void {
10 var foo: Foo = undefined;10 var foo: Foo = undefined;
11 _ = foo;11 _ = &foo;
12}12}
13export fn b() void {13export fn b() void {
14 var bar: Bar = undefined;14 var bar: Bar = undefined;
15 _ = bar;15 _ = &bar;
16}16}
17export fn c() void {17export fn c() void {
18 const baz = &@as(O, undefined);18 const baz = &@as(O, undefined);
test/cases/compile_errors/div_on_undefined_value.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1comptime {1comptime {
2 var a: i64 = undefined;2 var a: i64 = undefined;
3 _ = a / a;3 _ = a / a;
4 _ = &a;
4}5}
56
6// error7// error
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig+4-3
...@@ -11,12 +11,13 @@ pub export fn entry2() void {...@@ -11,12 +11,13 @@ pub export fn entry2() void {
11fn func(_: ?*anyopaque) void {}11fn func(_: ?*anyopaque) void {}
12pub export fn entry3() void {12pub export fn entry3() void {
13 var x: *?*usize = undefined;13 var x: *?*usize = undefined;
1414 _ = &x;
15 const ptr: *const anyopaque = x;15 const ptr: *const anyopaque = x;
16 _ = ptr;16 _ = ptr;
17}17}
18export fn entry4() void {18export fn entry4() void {
19 var a: []*u32 = undefined;19 var a: []*u32 = undefined;
20 _ = &a;
20 var b: []anyopaque = undefined;21 var b: []anyopaque = undefined;
21 b = a;22 b = a;
22}23}
...@@ -32,5 +33,5 @@ export fn entry4() void {...@@ -32,5 +33,5 @@ export fn entry4() void {
32// :11:12: note: parameter type declared here33// :11:12: note: parameter type declared here
33// :15:35: error: expected type '*const anyopaque', found '*?*usize'34// :15:35: error: expected type '*const anyopaque', found '*?*usize'
34// :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque'35// :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque'
35// :21:9: error: expected type '[]anyopaque', found '[]*u32'36// :22:9: error: expected type '[]anyopaque', found '[]*u32'
36// :21:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'37// :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'
test/cases/compile_errors/empty_switch_on_an_integer.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var x: u32 = 0;2 const x: u32 = 0;
3 switch (x) {}3 switch (x) {}
4}4}
55
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1pub export fn entry() void {1pub export fn entry() void {
2 const E = enum(comptime_int) { a, b, c, _ };2 const E = enum(comptime_int) { a, b, c, _ };
3 var e: E = .a;3 var e: E = .a;
4 _ = e;4 _ = &e;
5}5}
66
7// error7// error
test/cases/compile_errors/enum_field_value_references_enum.zig+1-1
...@@ -3,7 +3,7 @@ pub const Foo = enum(c_int) {...@@ -3,7 +3,7 @@ pub const Foo = enum(c_int) {
3 C = D,3 C = D,
4};4};
5export fn entry() void {5export fn entry() void {
6 var s: Foo = Foo.E;6 const s: Foo = Foo.E;
7 _ = s;7 _ = s;
8}8}
9const D = 1;9const D = 1;
test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig+2-2
...@@ -3,7 +3,7 @@ const Foo = enum(u32) {...@@ -3,7 +3,7 @@ const Foo = enum(u32) {
3 B = 11,3 B = 11,
4};4};
5export fn entry() void {5export fn entry() void {
6 var x: Foo = @enumFromInt(0);6 const x: Foo = @enumFromInt(0);
7 _ = x;7 _ = x;
8}8}
99
...@@ -11,5 +11,5 @@ export fn entry() void {...@@ -11,5 +11,5 @@ export fn entry() void {
11// backend=stage211// backend=stage2
12// target=native12// target=native
13//13//
14// :6:18: error: enum 'tmp.Foo' has no tag with value '0'14// :6:20: error: enum 'tmp.Foo' has no tag with value '0'
15// :1:13: note: enum declared here15// :1:13: note: enum declared here
test/cases/compile_errors/enum_value_already_taken.zig+1-1
...@@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) {...@@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) {
6 E = 60,6 E = 60,
7};7};
8export fn entry() void {8export fn entry() void {
9 var x = MultipleChoice.C;9 const x = MultipleChoice.C;
10 _ = x;10 _ = x;
11}11}
1212
test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig+1-1
...@@ -4,7 +4,7 @@ pub export fn entry() void {...@@ -4,7 +4,7 @@ pub export fn entry() void {
4 e: u8,4 e: u8,
5 };5 };
6 var a = .{@sizeOf(bitfield)};6 var a = .{@sizeOf(bitfield)};
7 _ = a;7 _ = &a;
8}8}
99
10// error10// error
test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1comptime {1comptime {
2 const z = i32!i32;2 const z = i32!i32;
3 var x: z = undefined;3 const x: z = undefined;
4 _ = x;4 _ = x;
5}5}
66
test/cases/compile_errors/error_when_evaluating_return_type.zig+1-1
...@@ -6,7 +6,7 @@ const Foo = struct {...@@ -6,7 +6,7 @@ const Foo = struct {
6 }6 }
7};7};
8export fn entry() void {8export fn entry() void {
9 var rule_set = try Foo.init();9 const rule_set = try Foo.init();
10 _ = rule_set;10 _ = rule_set;
11}11}
1212
test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig+3-2
...@@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) {...@@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) {
11}11}
12pub export fn entry() void {12pub export fn entry() void {
13 var a: u8 = 1;13 var a: u8 = 1;
14 _ = &a;
14 _ = foo(a, fn () void);15 _ = foo(a, fn () void);
15}16}
16// error17// error
17// backend=stage218// backend=stage2
18// target=native19// target=native
19//20//
20// :14:13: error: unable to resolve comptime value21// :15:13: error: unable to resolve comptime value
21// :14:13: note: argument to function being called at comptime must be comptime-known22// :15:13: note: argument to function being called at comptime must be comptime-known
22// :9:38: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type23// :9:38: note: expression is evaluated at comptime because the generic function was instantiated with a comptime-only return type
test/cases/compile_errors/explicit_error_set_cast_known_at_comptime_violates_error_sets.zig+3-3
...@@ -1,8 +1,8 @@...@@ -1,8 +1,8 @@
1const Set1 = error{ A, B };1const Set1 = error{ A, B };
2const Set2 = error{ A, C };2const Set2 = error{ A, C };
3comptime {3comptime {
4 var x = Set1.B;4 const x = Set1.B;
5 var y: Set2 = @errorCast(x);5 const y: Set2 = @errorCast(x);
6 _ = y;6 _ = y;
7}7}
88
...@@ -10,4 +10,4 @@ comptime {...@@ -10,4 +10,4 @@ comptime {
10// backend=stage210// backend=stage2
11// target=native11// target=native
12//12//
13// :5:19: error: 'error.B' not a member of error set 'error{C,A}'13// :5:21: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig+2-2
...@@ -7,7 +7,7 @@ const Small = enum(u2) {...@@ -7,7 +7,7 @@ const Small = enum(u2) {
77
8export fn entry() void {8export fn entry() void {
9 var y = @as(f32, 3);9 var y = @as(f32, 3);
10 var x: Small = @enumFromInt(y);10 const x: Small = @enumFromInt((&y).*);
11 _ = x;11 _ = x;
12}12}
1313
...@@ -15,4 +15,4 @@ export fn entry() void {...@@ -15,4 +15,4 @@ export fn entry() void {
15// backend=stage215// backend=stage2
16// target=native16// target=native
17//17//
18// :10:33: error: expected integer type, found 'f32'18// :10:39: error: expected integer type, found 'f32'
test/cases/compile_errors/extern_union_field_missing_type.zig+1-1
...@@ -2,7 +2,7 @@ const Letter = extern union {...@@ -2,7 +2,7 @@ const Letter = extern union {
2 A,2 A,
3};3};
4export fn entry() void {4export fn entry() void {
5 var a = Letter{ .A = {} };5 const a: Letter = .{ .A = {} };
6 _ = a;6 _ = a;
7}7}
88
test/cases/compile_errors/extern_union_given_enum_tag_type.zig+1-1
...@@ -9,7 +9,7 @@ const Payload = extern union(Letter) {...@@ -9,7 +9,7 @@ const Payload = extern union(Letter) {
9 C: bool,9 C: bool,
10};10};
11export fn entry() void {11export fn entry() void {
12 var a = Payload{ .A = 1234 };12 const a: Payload = .{ .A = 1234 };
13 _ = a;13 _ = a;
14}14}
1515
test/cases/compile_errors/field_access_of_slices.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var slice: []i32 = undefined;2 var slice: []i32 = undefined;
3 _ = &slice;
3 const info = @TypeOf(slice).unknown;4 const info = @TypeOf(slice).unknown;
4 _ = info;5 _ = info;
5}6}
...@@ -8,5 +9,5 @@ export fn entry() void {...@@ -8,5 +9,5 @@ export fn entry() void {
8// backend=stage29// backend=stage2
9// target=native10// target=native
10//11//
11// :3:32: error: type '[]i32' has no members12// :4:32: error: type '[]i32' has no members
12// :3:32: note: slice values have 'len' and 'ptr' members13// :4:32: note: slice values have 'len' and 'ptr' members
test/cases/compile_errors/for.zig+4-3
...@@ -17,6 +17,7 @@ export fn c() void {...@@ -17,6 +17,7 @@ export fn c() void {
17 for (buf) |*byte| {17 for (buf) |*byte| {
18 _ = byte;18 _ = byte;
19 }19 }
20 _ = &buf;
20}21}
21export fn d() void {22export fn d() void {
22 const x: [*]const u8 = "hello";23 const x: [*]const u8 = "hello";
...@@ -39,6 +40,6 @@ export fn d() void {...@@ -39,6 +40,6 @@ export fn d() void {
39// :10:14: note: for loop operand must be a range, array, slice, tuple, or vector40// :10:14: note: for loop operand must be a range, array, slice, tuple, or vector
40// :17:16: error: pointer capture of non pointer type '[10]u8'41// :17:16: error: pointer capture of non pointer type '[10]u8'
41// :17:10: note: consider using '&' here42// :17:10: note: consider using '&' here
42// :24:5: error: unbounded for loop43// :25:5: error: unbounded for loop
43// :24:10: note: type '[*]const u8' has no upper bound44// :25:10: note: type '[*]const u8' has no upper bound
44// :24:18: note: type '[*]const u8' has no upper bound45// :25:18: note: type '[*]const u8' has no upper bound
test/cases/compile_errors/for_loop_body_expression_ignored.zig+1-1
...@@ -7,7 +7,7 @@ export fn f1() void {...@@ -7,7 +7,7 @@ export fn f1() void {
7export fn f2() void {7export fn f2() void {
8 var x: anyerror!i32 = error.Bad;8 var x: anyerror!i32 = error.Bad;
9 for ("hello") |_| returns() else unreachable;9 for ("hello") |_| returns() else unreachable;
10 _ = x;10 _ = &x;
11}11}
12export fn f3() void {12export fn f3() void {
13 for ("hello") |_| {} else true;13 for ("hello") |_| {} else true;
test/cases/compile_errors/function_ptr_alignment.zig+5-5
...@@ -1,24 +1,24 @@...@@ -1,24 +1,24 @@
1comptime {1comptime {
2 var a: *align(2) @TypeOf(foo) = undefined;2 var a: *align(2) @TypeOf(foo) = undefined;
3 _ = a;3 _ = &a;
4}4}
5fn foo() void {}5fn foo() void {}
66
7comptime {7comptime {
8 var a: *align(1) fn () void = undefined;8 var a: *align(1) fn () void = undefined;
9 _ = a;9 _ = &a;
10}10}
11comptime {11comptime {
12 var a: *align(2) fn () align(2) void = undefined;12 var a: *align(2) fn () align(2) void = undefined;
13 _ = a;13 _ = &a;
14}14}
15comptime {15comptime {
16 var a: *align(2) fn () void = undefined;16 var a: *align(2) fn () void = undefined;
17 _ = a;17 _ = &a;
18}18}
19comptime {19comptime {
20 var a: *align(1) fn () align(2) void = undefined;20 var a: *align(1) fn () align(2) void = undefined;
21 _ = a;21 _ = &a;
22}22}
2323
24// error24// error
test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig+2-1
...@@ -3,6 +3,7 @@ const std = @import("std");...@@ -3,6 +3,7 @@ const std = @import("std");
3pub export fn entry() void {3pub export fn entry() void {
4 var ohnoes: *usize = undefined;4 var ohnoes: *usize = undefined;
5 _ = sliceAsBytes(ohnoes);5 _ = sliceAsBytes(ohnoes);
6 _ = &ohnoes;
6}7}
7fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {}8fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {}
89
...@@ -10,4 +11,4 @@ fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {...@@ -10,4 +11,4 @@ fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {
10// backend=llvm11// backend=llvm
11// target=native12// target=native
12//13//
13// :7:63: error: expected type 'type', found 'bool'14// :8:63: error: expected type 'type', found 'bool'
test/cases/compile_errors/generic_method_call_with_invalid_param.zig+5-4
...@@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void {...@@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void {
11export fn callComptimeBoolMethodWithRuntimeBool() void {11export fn callComptimeBoolMethodWithRuntimeBool() void {
12 const s = S{};12 const s = S{};
13 var arg = true;13 var arg = true;
14 _ = &arg;
14 s.comptimeBoolMethod(arg);15 s.comptimeBoolMethod(arg);
15}16}
1617
...@@ -25,8 +26,8 @@ const S = struct {...@@ -25,8 +26,8 @@ const S = struct {
25// target=native26// target=native
26//27//
27// :3:18: error: expected type 'bool', found 'void'28// :3:18: error: expected type 'bool', found 'void'
28// :18:43: note: parameter type declared here
29// :8:18: error: expected type 'void', found 'bool'
30// :19:43: note: parameter type declared here29// :19:43: note: parameter type declared here
31// :14:26: error: runtime-known argument passed to comptime parameter30// :8:18: error: expected type 'void', found 'bool'
32// :20:57: note: declared comptime here31// :20:43: note: parameter type declared here
32// :15:26: error: runtime-known argument passed to comptime parameter
33// :21:57: note: declared comptime here
test/cases/compile_errors/ignored_expression_in_while_continuation.zig+6-4
...@@ -3,10 +3,12 @@ export fn a() void {...@@ -3,10 +3,12 @@ export fn a() void {
3}3}
4export fn b() void {4export fn b() void {
5 var x: anyerror!i32 = 1234;5 var x: anyerror!i32 = 1234;
6 _ = &x;
6 while (x) |_| : (bad()) {} else |_| {}7 while (x) |_| : (bad()) {} else |_| {}
7}8}
8export fn c() void {9export fn c() void {
9 var x: ?i32 = 1234;10 var x: ?i32 = 1234;
11 _ = &x;
10 while (x) |_| : (bad()) {}12 while (x) |_| : (bad()) {}
11}13}
12fn bad() anyerror!void {14fn bad() anyerror!void {
...@@ -19,7 +21,7 @@ fn bad() anyerror!void {...@@ -19,7 +21,7 @@ fn bad() anyerror!void {
19//21//
20// :2:24: error: error is ignored22// :2:24: error: error is ignored
21// :2:24: note: consider using 'try', 'catch', or 'if'23// :2:24: note: consider using 'try', 'catch', or 'if'
22// :6:25: error: error is ignored24// :7:25: error: error is ignored
23// :6:25: note: consider using 'try', 'catch', or 'if'25// :7:25: note: consider using 'try', 'catch', or 'if'
24// :10:25: error: error is ignored26// :12:25: error: error is ignored
25// :10:25: note: consider using 'try', 'catch', or 'if'27// :12:25: note: consider using 'try', 'catch', or 'if'
test/cases/compile_errors/implicit_cast_between_C_pointer_and_Zig_pointer-bad_const-align-child.zig+6-6
...@@ -1,32 +1,32 @@...@@ -1,32 +1,32 @@
1export fn a() void {1export fn a() void {
2 var x: [*c]u8 = undefined;2 var x: [*c]u8 = undefined;
3 var y: *align(4) u8 = x;3 var y: *align(4) u8 = x;
4 _ = y;4 _ = .{ &x, &y };
5}5}
6export fn b() void {6export fn b() void {
7 var x: [*c]const u8 = undefined;7 var x: [*c]const u8 = undefined;
8 var y: *u8 = x;8 var y: *u8 = x;
9 _ = y;9 _ = .{ &x, &y };
10}10}
11export fn c() void {11export fn c() void {
12 var x: [*c]u8 = undefined;12 var x: [*c]u8 = undefined;
13 var y: *u32 = x;13 var y: *u32 = x;
14 _ = y;14 _ = .{ &x, &y };
15}15}
16export fn d() void {16export fn d() void {
17 var y: *align(1) u32 = undefined;17 var y: *align(1) u32 = undefined;
18 var x: [*c]u32 = y;18 var x: [*c]u32 = y;
19 _ = x;19 _ = .{ &x, &y };
20}20}
21export fn e() void {21export fn e() void {
22 var y: *const u8 = undefined;22 var y: *const u8 = undefined;
23 var x: [*c]u8 = y;23 var x: [*c]u8 = y;
24 _ = x;24 _ = .{ &x, &y };
25}25}
26export fn f() void {26export fn f() void {
27 var y: *u8 = undefined;27 var y: *u8 = undefined;
28 var x: [*c]u32 = y;28 var x: [*c]u32 = y;
29 _ = x;29 _ = .{ &x, &y };
30}30}
3131
32// error32// error
test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig+1-1
...@@ -7,7 +7,7 @@ export fn entry() void {...@@ -7,7 +7,7 @@ export fn entry() void {
7export fn entry2() void {7export fn entry2() void {
8 var x1: f64 = 1.0;8 var x1: f64 = 1.0;
9 var y2: f32 = x1;9 var y2: f32 = x1;
10 _ = y2;10 _ = .{ &x1, &y2 };
11}11}
1212
13// error13// error
test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig+3-3
...@@ -4,7 +4,7 @@ export fn entry() void {...@@ -4,7 +4,7 @@ export fn entry() void {
4 foo(Set1.B);4 foo(Set1.B);
5}5}
6fn foo(set1: Set1) void {6fn foo(set1: Set1) void {
7 var x: Set2 = set1;7 const x: Set2 = set1;
8 _ = x;8 _ = x;
9}9}
1010
...@@ -12,5 +12,5 @@ fn foo(set1: Set1) void {...@@ -12,5 +12,5 @@ fn foo(set1: Set1) void {
12// backend=stage212// backend=stage2
13// target=native13// target=native
14//14//
15// :7:19: error: expected type 'error{C,A}', found 'error{A,B}'15// :7:21: error: expected type 'error{C,A}', found 'error{A,B}'
16// :7:19: note: 'error.B' not a member of destination error set16// :7:21: note: 'error.B' not a member of destination error set
test/cases/compile_errors/implicit_casting_C_pointers_which_would_mess_up_null_semantics.zig+9-4
...@@ -4,6 +4,9 @@ export fn entry() void {...@@ -4,6 +4,9 @@ export fn entry() void {
4 var ptr_opt_many_ptr = &opt_many_ptr;4 var ptr_opt_many_ptr = &opt_many_ptr;
5 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;5 var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
6 ptr_opt_many_ptr = c_ptr;6 ptr_opt_many_ptr = c_ptr;
7 _ = &slice;
8 _ = &ptr_opt_many_ptr;
9 _ = &c_ptr;
7}10}
8export fn entry2() void {11export fn entry2() void {
9 var buf: [4]u8 = "aoeu".*;12 var buf: [4]u8 = "aoeu".*;
...@@ -11,7 +14,9 @@ export fn entry2() void {...@@ -11,7 +14,9 @@ export fn entry2() void {
11 var opt_many_ptr: [*]u8 = slice.ptr;14 var opt_many_ptr: [*]u8 = slice.ptr;
12 var ptr_opt_many_ptr = &opt_many_ptr;15 var ptr_opt_many_ptr = &opt_many_ptr;
13 var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;16 var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
14 _ = c_ptr;17 _ = &slice;
18 _ = &ptr_opt_many_ptr;
19 _ = &c_ptr;
15}20}
1621
17// error22// error
...@@ -21,6 +26,6 @@ export fn entry2() void {...@@ -21,6 +26,6 @@ export fn entry2() void {
21// :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'26// :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
22// :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'27// :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
23// :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'28// :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
24// :13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'29// :16:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
25// :13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'30// :16:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
26// :13:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'31// :16:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'
test/cases/compile_errors/implicit_casting_null_c_pointer_to_zig_pointer.zig+3-2
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1comptime {1comptime {
2 var c_ptr: [*c]u8 = 0;2 var c_ptr: [*c]u8 = 0;
3 var zig_ptr: *u8 = c_ptr;3 const zig_ptr: *u8 = c_ptr;
4 _ = &c_ptr;
4 _ = zig_ptr;5 _ = zig_ptr;
5}6}
67
...@@ -8,4 +9,4 @@ comptime {...@@ -8,4 +9,4 @@ comptime {
8// backend=stage29// backend=stage2
9// target=native10// target=native
10//11//
11// :3:24: error: null pointer casted to type '*u8'12// :3:26: error: null pointer casted to type '*u8'
test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig+1-1
...@@ -7,7 +7,7 @@ const Small = enum(u2) {...@@ -7,7 +7,7 @@ const Small = enum(u2) {
77
8export fn entry() void {8export fn entry() void {
9 var x: u2 = Small.Two;9 var x: u2 = Small.Two;
10 _ = x;10 _ = &x;
11}11}
1212
13// error13// error
test/cases/compile_errors/incompatible sub-byte fields.zig +4-3
...@@ -11,6 +11,7 @@ export fn entry() void {...@@ -11,6 +11,7 @@ export fn entry() void {
11 var a = A{ .a = 2, .b = 2 };11 var a = A{ .a = 2, .b = 2 };
12 var b = B{ .q = 22, .a = 3, .b = 2 };12 var b = B{ .q = 22, .a = 3, .b = 2 };
13 var t: usize = 0;13 var t: usize = 0;
14 _ = &t;
14 const ptr = switch (t) {15 const ptr = switch (t) {
15 0 => &a.a,16 0 => &a.a,
16 1 => &b.a,17 1 => &b.a,
...@@ -24,6 +25,6 @@ export fn entry() void {...@@ -24,6 +25,6 @@ export fn entry() void {
24// backend=stage225// backend=stage2
25// target=native26// target=native
26//27//
27// :14:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'28// :15:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'
28// :15:14: note: type '*align(1:0:1) u2' here29// :16:14: note: type '*align(1:0:1) u2' here
29// :16:14: note: type '*align(2:8:2) u2' here30// :17:14: note: type '*align(2:8:2) u2' here
test/cases/compile_errors/incompatible_sentinels.zig+2-2
...@@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 {...@@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 {
8}8}
9export fn entry3() void {9export fn entry3() void {
10 var array: [2:0]u8 = [_:255]u8{ 1, 2 };10 var array: [2:0]u8 = [_:255]u8{ 1, 2 };
11 _ = array;11 _ = &array;
12}12}
13export fn entry4() void {13export fn entry4() void {
14 var array: [2:0]u8 = [_]u8{ 1, 2 };14 var array: [2:0]u8 = [_]u8{ 1, 2 };
15 _ = array;15 _ = &array;
16}16}
1717
18// error18// error
test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var a: *u32 = undefined;2 var a: *u32 = undefined;
3 _ = *a;3 _ = *a;
4 _ = &a;
4}5}
56
6// error7// error
test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig+4-4
...@@ -1,17 +1,17 @@...@@ -1,17 +1,17 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };2 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
3 var slice: []u8 = &buf;3 const slice: []u8 = &buf;
4 const a: u32 = 1234;4 const a: u32 = 1234;
5 @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a)));5 @memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a)));
6}6}
7pub export fn entry1() void {7pub export fn entry1() void {
8 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };8 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
9 var ptr: *u8 = &buf[0];9 const ptr: *u8 = &buf[0];
10 @memcpy(ptr, 0);10 @memcpy(ptr, 0);
11}11}
12pub export fn entry2() void {12pub export fn entry2() void {
13 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };13 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
14 var ptr: *u8 = &buf[0];14 const ptr: *u8 = &buf[0];
15 @memset(ptr, 0);15 @memset(ptr, 0);
16}16}
17pub export fn non_matching_lengths() void {17pub export fn non_matching_lengths() void {
...@@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void {...@@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void {
29 @memcpy(&buf1, &buf2);29 @memcpy(&buf1, &buf2);
30}30}
31pub export fn memset_array() void {31pub export fn memset_array() void {
32 var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };32 const buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
33 @memcpy(buf, 1);33 @memcpy(buf, 1);
34}34}
3535
test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1const array = [_]u8{};1const array = [_]u8{};
2export fn foo() void {2export fn foo() void {
3 var index: usize = 0;3 var index: usize = 0;
4 _ = &index;
4 const pointer = &array[index];5 const pointer = &array[index];
5 _ = pointer;6 _ = pointer;
6}7}
...@@ -9,4 +10,4 @@ export fn foo() void {...@@ -9,4 +10,4 @@ export fn foo() void {
9// backend=stage210// backend=stage2
10// target=native11// target=native
11//12//
12// :4:27: error: indexing into empty array is not allowed13// :5:27: error: indexing into empty array is not allowed
test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig+1-1
...@@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void {...@@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void {
6}6}
7pub export fn entry() void {7pub export fn entry() void {
8 var value: u64 = 0;8 var value: u64 = 0;
9 acceptRuntime(value);9 acceptRuntime((&value).*);
10}10}
1111
12// error12// error
test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig+6-4
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1export fn foo() void {1export fn foo() void {
2 var a: f32 = 2;2 var a: f32 = 2;
3 _ = &a;
3 _ = @as(comptime_int, @intFromFloat(a));4 _ = @as(comptime_int, @intFromFloat(a));
4}5}
5export fn bar() void {6export fn bar() void {
6 var a: u32 = 2;7 var a: u32 = 2;
8 _ = &a;
7 _ = @as(comptime_float, @floatFromInt(a));9 _ = @as(comptime_float, @floatFromInt(a));
8}10}
911
...@@ -11,7 +13,7 @@ export fn bar() void {...@@ -11,7 +13,7 @@ export fn bar() void {
11// backend=stage213// backend=stage2
12// target=native14// target=native
13//15//
14// :3:41: error: unable to resolve comptime value16// :4:41: error: unable to resolve comptime value
15// :3:41: note: value being casted to 'comptime_int' must be comptime-known17// :4:41: note: value being casted to 'comptime_int' must be comptime-known
16// :7:43: error: unable to resolve comptime value18// :9:43: error: unable to resolve comptime value
17// :7:43: note: value being casted to 'comptime_float' must be comptime-known19// :9:43: note: value being casted to 'comptime_float' must be comptime-known
test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var b: *i32 = @ptrFromInt(0);2 const b: *i32 = @ptrFromInt(0);
3 _ = b;3 _ = b;
4}4}
55
...@@ -7,4 +7,4 @@ export fn entry() void {...@@ -7,4 +7,4 @@ export fn entry() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:31: error: pointer type '*i32' does not allow address zero10// :2:33: error: pointer type '*i32' does not allow address zero
test/cases/compile_errors/int_to_err_global_invalid_number.zig+1-1
...@@ -5,7 +5,7 @@ const Set1 = error{...@@ -5,7 +5,7 @@ const Set1 = error{
5comptime {5comptime {
6 var x: u16 = 3;6 var x: u16 = 3;
7 var y = @errorFromInt(x);7 var y = @errorFromInt(x);
8 _ = y;8 _ = .{ &x, &y };
9}9}
1010
11// error11// error
test/cases/compile_errors/int_to_err_non_global_invalid_number.zig+3-3
...@@ -7,8 +7,8 @@ const Set2 = error{...@@ -7,8 +7,8 @@ const Set2 = error{
7 C,7 C,
8};8};
9comptime {9comptime {
10 var x = @intFromError(Set1.B);10 const x = @intFromError(Set1.B);
11 var y: Set2 = @errorCast(@errorFromInt(x));11 const y: Set2 = @errorCast(@errorFromInt(x));
12 _ = y;12 _ = y;
13}13}
1414
...@@ -16,4 +16,4 @@ comptime {...@@ -16,4 +16,4 @@ comptime {
16// backend=llvm16// backend=llvm
17// target=native17// target=native
18//18//
19// :11:19: error: 'error.B' not a member of error set 'error{C,A}'19// :11:21: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/integer_cast_truncates_bits.zig+2-2
...@@ -11,12 +11,12 @@ export fn entry2() void {...@@ -11,12 +11,12 @@ export fn entry2() void {
11export fn entry3() void {11export fn entry3() void {
12 var spartan_count: u16 = 300;12 var spartan_count: u16 = 300;
13 var byte: u8 = spartan_count;13 var byte: u8 = spartan_count;
14 _ = byte;14 _ = .{ &spartan_count, &byte };
15}15}
16export fn entry4() void {16export fn entry4() void {
17 var signed: i8 = -1;17 var signed: i8 = -1;
18 var unsigned: u64 = signed;18 var unsigned: u64 = signed;
19 _ = unsigned;19 _ = .{ &signed, &unsigned };
20}20}
2121
22// error22// error
test/cases/compile_errors/invalid_compare_string.zig+4-4
...@@ -1,20 +1,20 @@...@@ -1,20 +1,20 @@
1comptime {1comptime {
2 var a = "foo";2 const a = "foo";
3 if (a == "foo") unreachable;3 if (a == "foo") unreachable;
4}4}
5comptime {5comptime {
6 var a = "foo";6 const a = "foo";
7 if (a == ("foo")) unreachable; // intentionally allow7 if (a == ("foo")) unreachable; // intentionally allow
8}8}
9comptime {9comptime {
10 var a = "foo";10 const a = "foo";
11 switch (a) {11 switch (a) {
12 "foo" => unreachable,12 "foo" => unreachable,
13 else => {},13 else => {},
14 }14 }
15}15}
16comptime {16comptime {
17 var a = "foo";17 const a = "foo";
18 switch (a) {18 switch (a) {
19 ("foo") => unreachable, // intentionally allow19 ("foo") => unreachable, // intentionally allow
20 else => {},20 else => {},
test/cases/compile_errors/invalid_deref_on_switch_target.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var tile = Tile.Empty;2 const tile = Tile.Empty;
3 switch (tile.*) {3 switch (tile.*) {
4 Tile.Empty => {},4 Tile.Empty => {},
5 Tile.Filled => {},5 Tile.Filled => {},
test/cases/compile_errors/invalid_float_casts.zig+8-4
...@@ -1,17 +1,21 @@...@@ -1,17 +1,21 @@
1export fn foo() void {1export fn foo() void {
2 var a: f32 = 2;2 var a: f32 = 2;
3 _ = &a;
3 _ = @as(comptime_float, @floatCast(a));4 _ = @as(comptime_float, @floatCast(a));
4}5}
5export fn bar() void {6export fn bar() void {
6 var a: f32 = 2;7 var a: f32 = 2;
8 _ = &a;
7 _ = @as(f32, @intFromFloat(a));9 _ = @as(f32, @intFromFloat(a));
8}10}
9export fn baz() void {11export fn baz() void {
10 var a: f32 = 2;12 var a: f32 = 2;
13 _ = &a;
11 _ = @as(f32, @floatFromInt(a));14 _ = @as(f32, @floatFromInt(a));
12}15}
13export fn qux() void {16export fn qux() void {
14 var a: u32 = 2;17 var a: u32 = 2;
18 _ = &a;
15 _ = @as(f32, @floatCast(a));19 _ = @as(f32, @floatCast(a));
16}20}
1721
...@@ -19,7 +23,7 @@ export fn qux() void {...@@ -19,7 +23,7 @@ export fn qux() void {
19// backend=stage223// backend=stage2
20// target=native24// target=native
21//25//
22// :3:40: error: unable to cast runtime value to 'comptime_float'26// :4:40: error: unable to cast runtime value to 'comptime_float'
23// :7:18: error: expected integer type, found 'f32'27// :9:18: error: expected integer type, found 'f32'
24// :11:32: error: expected integer type, found 'f32'28// :14:32: error: expected integer type, found 'f32'
25// :15:29: error: expected float or vector type, found 'u32'29// :19:29: error: expected float or vector type, found 'u32'
test/cases/compile_errors/invalid_inline_else_type.zig+6-3
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub export fn entry1() void {1pub export fn entry1() void {
2 var a: anyerror = undefined;2 var a: anyerror = undefined;
3 _ = &a;
3 switch (a) {4 switch (a) {
4 inline else => {},5 inline else => {},
5 }6 }
...@@ -7,12 +8,14 @@ pub export fn entry1() void {...@@ -7,12 +8,14 @@ pub export fn entry1() void {
7const E = enum(u8) { a, _ };8const E = enum(u8) { a, _ };
8pub export fn entry2() void {9pub export fn entry2() void {
9 var a: E = undefined;10 var a: E = undefined;
11 _ = &a;
10 switch (a) {12 switch (a) {
11 inline else => {},13 inline else => {},
12 }14 }
13}15}
14pub export fn entry3() void {16pub export fn entry3() void {
15 var a: *u32 = undefined;17 var a: *u32 = undefined;
18 _ = &a;
16 switch (a) {19 switch (a) {
17 inline else => {},20 inline else => {},
18 }21 }
...@@ -22,6 +25,6 @@ pub export fn entry3() void {...@@ -22,6 +25,6 @@ pub export fn entry3() void {
22// backend=stage225// backend=stage2
23// target=native26// target=native
24//27//
25// :4:21: error: cannot enumerate values of type 'anyerror' for 'inline else'28// :5:21: error: cannot enumerate values of type 'anyerror' for 'inline else'
26// :11:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'29// :13:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'
27// :17:21: error: cannot enumerate values of type '*u32' for 'inline else'30// :20:21: error: cannot enumerate values of type '*u32' for 'inline else'
test/cases/compile_errors/invalid_int_casts.zig+8-4
...@@ -1,17 +1,21 @@...@@ -1,17 +1,21 @@
1export fn foo() void {1export fn foo() void {
2 var a: u32 = 2;2 var a: u32 = 2;
3 _ = &a;
3 _ = @as(comptime_int, @intCast(a));4 _ = @as(comptime_int, @intCast(a));
4}5}
5export fn bar() void {6export fn bar() void {
6 var a: u32 = 2;7 var a: u32 = 2;
8 _ = &a;
7 _ = @as(u32, @floatFromInt(a));9 _ = @as(u32, @floatFromInt(a));
8}10}
9export fn baz() void {11export fn baz() void {
10 var a: u32 = 2;12 var a: u32 = 2;
13 _ = &a;
11 _ = @as(u32, @intFromFloat(a));14 _ = @as(u32, @intFromFloat(a));
12}15}
13export fn qux() void {16export fn qux() void {
14 var a: f32 = 2;17 var a: f32 = 2;
18 _ = &a;
15 _ = @as(u32, @intCast(a));19 _ = @as(u32, @intCast(a));
16}20}
1721
...@@ -19,7 +23,7 @@ export fn qux() void {...@@ -19,7 +23,7 @@ export fn qux() void {
19// backend=stage223// backend=stage2
20// target=native24// target=native
21//25//
22// :3:36: error: unable to cast runtime value to 'comptime_int'26// :4:36: error: unable to cast runtime value to 'comptime_int'
23// :7:18: error: expected float type, found 'u32'27// :9:18: error: expected float type, found 'u32'
24// :11:32: error: expected float type, found 'u32'28// :14:32: error: expected float type, found 'u32'
25// :15:27: error: expected integer or vector, found 'f32'29// :19:27: error: expected integer or vector, found 'f32'
test/cases/compile_errors/invalid_multiple_dereferences.zig+5-4
...@@ -1,11 +1,12 @@...@@ -1,11 +1,12 @@
1export fn a() void {1export fn a() void {
2 var box = Box{ .field = 0 };2 var box = Box{ .field = 0 };
3 _ = &box;
3 box.*.field = 1;4 box.*.field = 1;
4}5}
5export fn b() void {6export fn b() void {
6 var box = Box{ .field = 0 };7 var box = Box{ .field = 0 };
7 var boxPtr = &box;8 const box_ptr = &box;
8 boxPtr.*.*.field = 1;9 box_ptr.*.*.field = 1;
9}10}
10pub const Box = struct {11pub const Box = struct {
11 field: i32,12 field: i32,
...@@ -15,5 +16,5 @@ pub const Box = struct {...@@ -15,5 +16,5 @@ pub const Box = struct {
15// backend=stage216// backend=stage2
16// target=native17// target=native
17//18//
18// :3:8: error: cannot dereference non-pointer type 'tmp.Box'19// :4:8: error: cannot dereference non-pointer type 'tmp.Box'
19// :8:13: error: cannot dereference non-pointer type 'tmp.Box'20// :9:14: error: cannot dereference non-pointer type 'tmp.Box'
test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig+2-2
...@@ -10,12 +10,12 @@ const U = union(E) {...@@ -10,12 +10,12 @@ const U = union(E) {
10export fn foo() void {10export fn foo() void {
11 var e: E = @enumFromInt(15);11 var e: E = @enumFromInt(15);
12 var u: U = e;12 var u: U = e;
13 _ = u;13 _ = .{ &e, &u };
14}14}
15export fn bar() void {15export fn bar() void {
16 const e: E = @enumFromInt(15);16 const e: E = @enumFromInt(15);
17 var u: U = e;17 var u: U = e;
18 _ = u;18 _ = &u;
19}19}
2020
21// error21// error
test/cases/compile_errors/invalid_peer_type_resolution.zig+20-18
...@@ -1,11 +1,13 @@...@@ -1,11 +1,13 @@
1export fn optionalVector() void {1export fn optionalVector() void {
2 var x: ?@Vector(10, i32) = undefined;2 var x: ?@Vector(10, i32) = undefined;
3 var y: @Vector(11, i32) = undefined;3 var y: @Vector(11, i32) = undefined;
4 _ = .{ &x, &y };
4 _ = @TypeOf(x, y);5 _ = @TypeOf(x, y);
5}6}
6export fn badTupleField() void {7export fn badTupleField() void {
7 var x = .{ @as(u8, 0), @as(u32, 1) };8 var x = .{ @as(u8, 0), @as(u32, 1) };
8 var y = .{ @as(u8, 1), "hello" };9 var y = .{ @as(u8, 1), "hello" };
10 _ = .{ &x, &y };
9 _ = @TypeOf(x, y);11 _ = @TypeOf(x, y);
10}12}
11export fn badNestedField() void {13export fn badNestedField() void {
...@@ -30,21 +32,21 @@ export fn incompatiblePointers4() void {...@@ -30,21 +32,21 @@ export fn incompatiblePointers4() void {
30// backend=llvm32// backend=llvm
31// target=native33// target=native
32//34//
33// :4:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'35// :5:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
34// :4:17: note: type '?@Vector(10, i32)' here36// :5:17: note: type '?@Vector(10, i32)' here
35// :4:20: note: type '@Vector(11, i32)' here37// :5:20: note: type '@Vector(11, i32)' here
36// :9:9: error: struct field '1' has conflicting types38// :11:9: error: struct field '1' has conflicting types
37// :9:9: note: incompatible types: 'u32' and '*const [5:0]u8'39// :11:9: note: incompatible types: 'u32' and '*const [5:0]u8'
38// :9:17: note: type 'u32' here40// :11:17: note: type 'u32' here
39// :9:20: note: type '*const [5:0]u8' here41// :11:20: note: type '*const [5:0]u8' here
40// :14:9: error: struct field 'bar' has conflicting types42// :16:9: error: struct field 'bar' has conflicting types
41// :14:9: note: struct field '1' has conflicting types43// :16:9: note: struct field '1' has conflicting types
42// :14:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'44// :16:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'
43// :14:17: note: type 'comptime_int' here45// :16:17: note: type 'comptime_int' here
44// :14:20: note: type '*const [2:0]u8' here46// :16:20: note: type '*const [2:0]u8' here
45// :19:9: error: incompatible types: '[]const u8' and '[*:0]const u8'47// :21:9: error: incompatible types: '[]const u8' and '[*:0]const u8'
46// :19:17: note: type '[]const u8' here48// :21:17: note: type '[]const u8' here
47// :19:20: note: type '[*:0]const u8' here49// :21:20: note: type '[*:0]const u8' here
48// :26:9: error: incompatible types: '[]const u8' and '[*]const u8'50// :28:9: error: incompatible types: '[]const u8' and '[*]const u8'
49// :26:23: note: type '[]const u8' here51// :28:23: note: type '[]const u8' here
50// :26:26: note: type '[*]const u8' here52// :28:26: note: type '[*]const u8' here
test/cases/compile_errors/invalid_store_to_comptime_field.zig+13-11
...@@ -17,8 +17,9 @@ pub export fn entry2() void {...@@ -17,8 +17,9 @@ pub export fn entry2() void {
17 var list = .{ 1, 2, 3 };17 var list = .{ 1, 2, 3 };
18 var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 };18 var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 };
19 var list3 = @TypeOf(list){ 1, 2, 4 };19 var list3 = @TypeOf(list){ 1, 2, 4 };
20 _ = list2;20 _ = &list;
21 _ = list3;21 _ = &list2;
22 _ = &list3;
22}23}
23pub export fn entry3() void {24pub export fn entry3() void {
24 const U = struct {25 const U = struct {
...@@ -46,6 +47,7 @@ pub export fn entry5() void {...@@ -46,6 +47,7 @@ pub export fn entry5() void {
46}47}
47pub export fn entry6() void {48pub export fn entry6() void {
48 var x: u32 = 15;49 var x: u32 = 15;
50 _ = &x;
49 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });51 const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
50 const S = struct {52 const S = struct {
51 fn foo(_: T) void {}53 fn foo(_: T) void {}
...@@ -74,12 +76,12 @@ pub export fn entry8() void {...@@ -74,12 +76,12 @@ pub export fn entry8() void {
74// :6:9: error: value stored in comptime field does not match the default value of the field76// :6:9: error: value stored in comptime field does not match the default value of the field
75// :14:9: error: value stored in comptime field does not match the default value of the field77// :14:9: error: value stored in comptime field does not match the default value of the field
76// :19:38: error: value stored in comptime field does not match the default value of the field78// :19:38: error: value stored in comptime field does not match the default value of the field
77// :31:19: error: value stored in comptime field does not match the default value of the field79// :32:19: error: value stored in comptime field does not match the default value of the field
78// :25:29: note: default value set here80// :26:29: note: default value set here
79// :41:19: error: value stored in comptime field does not match the default value of the field81// :42:19: error: value stored in comptime field does not match the default value of the field
80// :35:29: note: default value set here82// :36:29: note: default value set here
81// :45:12: error: value stored in comptime field does not match the default value of the field83// :46:12: error: value stored in comptime field does not match the default value of the field
82// :53:25: error: value stored in comptime field does not match the default value of the field84// :55:25: error: value stored in comptime field does not match the default value of the field
83// :66:36: error: value stored in comptime field does not match the default value of the field85// :68:36: error: value stored in comptime field does not match the default value of the field
84// :59:30: error: value stored in comptime field does not match the default value of the field86// :61:30: error: value stored in comptime field does not match the default value of the field
85// :57:29: note: default value set here87// :59:29: note: default value set here
test/cases/compile_errors/invalid_struct_field.zig+3-2
...@@ -8,6 +8,7 @@ export fn f() void {...@@ -8,6 +8,7 @@ export fn f() void {
8export fn g() void {8export fn g() void {
9 var a: A = undefined;9 var a: A = undefined;
10 const y = a.bar;10 const y = a.bar;
11 _ = &a;
11 _ = y;12 _ = y;
12}13}
13export fn e() void {14export fn e() void {
...@@ -26,5 +27,5 @@ export fn e() void {...@@ -26,5 +27,5 @@ export fn e() void {
26// :1:11: note: struct declared here27// :1:11: note: struct declared here
27// :10:17: error: no field named 'bar' in struct 'tmp.A'28// :10:17: error: no field named 'bar' in struct 'tmp.A'
28// :1:11: note: struct declared here29// :1:11: note: struct declared here
29// :18:45: error: no field named 'f' in struct 'tmp.e.B'30// :19:45: error: no field named 'f' in struct 'tmp.e.B'
30// :14:15: note: struct declared here31// :15:15: note: struct declared here
test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var foo: u32 = @This(){};2 const foo: u32 = @This(){};
3 _ = foo;3 _ = foo;
4}4}
55
...@@ -7,5 +7,5 @@ export fn entry() void {...@@ -7,5 +7,5 @@ export fn entry() void {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:27: error: expected type 'u32', found 'tmp'10// :2:29: error: expected type 'u32', found 'tmp'
11// :1:1: note: struct declared here11// :1:1: note: struct declared here
test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig+1-1
...@@ -4,7 +4,7 @@ export fn foo1() void {...@@ -4,7 +4,7 @@ export fn foo1() void {
4 _ = word;4 _ = word;
5}5}
6export fn foo2() void {6export fn foo2() void {
7 var bytes: []const u8 = &[_]u8{ 1, 2 };7 const bytes: []const u8 = &[_]u8{ 1, 2 };
8 const word: u16 = @bitCast(bytes);8 const word: u16 = @bitCast(bytes);
9 _ = word;9 _ = word;
10}10}
test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig+5-5
...@@ -1,14 +1,14 @@...@@ -1,14 +1,14 @@
1export fn foo() void {1export fn foo() void {
2 var u: ?*anyopaque = null;2 var u: ?*anyopaque = null;
3 var v: *anyopaque = undefined;3 var v: *anyopaque = undefined;
4 v = u;4 v = (&u).*;
5}5}
66
7// error7// error
8// backend=stage28// backend=stage2
9// target=native9// target=native
10//10//
11// :4:9: error: expected type '*anyopaque', found '?*anyopaque'11// :4:13: error: expected type '*anyopaque', found '?*anyopaque'
12// :4:9: note: cannot convert optional to payload type12// :4:13: note: cannot convert optional to payload type
13// :4:9: note: consider using '.?', 'orelse', or 'if'13// :4:13: note: consider using '.?', 'orelse', or 'if'
14// :4:9: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque'14// :4:13: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque'
test/cases/compile_errors/lazy_pointer_with_undefined_element_type.zig+2-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1export fn foo() void {1export fn foo() void {
2 comptime var T: type = undefined;2 comptime var T: type = undefined;
3 _ = &T;
3 const S = struct { x: *T };4 const S = struct { x: *T };
4 const I = @typeInfo(S);5 const I = @typeInfo(S);
5 _ = I;6 _ = I;
...@@ -9,4 +10,4 @@ export fn foo() void {...@@ -9,4 +10,4 @@ export fn foo() void {
9// backend=stage210// backend=stage2
10// target=native11// target=native
11//12//
12// :3:28: error: use of undefined value here causes undefined behavior13// :4:28: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig+1-1
...@@ -3,7 +3,7 @@ export fn entry() void {...@@ -3,7 +3,7 @@ export fn entry() void {
33
4 var i: u32 = 0;4 var i: u32 = 0;
5 var x = loadv(&v[i]);5 var x = loadv(&v[i]);
6 _ = x;6 _ = .{ &i, &x };
7}7}
88
9fn loadv(ptr: anytype) i31 {9fn loadv(ptr: anytype) i31 {
test/cases/compile_errors/memset_no_length.zig+6-4
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1export fn foo() void {1export fn foo() void {
2 var ptr: [*]u8 = undefined;2 var ptr: [*]u8 = undefined;
3 _ = &ptr;
3 @memset(ptr, 123);4 @memset(ptr, 123);
4}5}
5export fn bar() void {6export fn bar() void {
6 var ptr: [*c]bool = undefined;7 var ptr: [*c]bool = undefined;
8 _ = &ptr;
7 @memset(ptr, true);9 @memset(ptr, true);
8}10}
911
...@@ -11,7 +13,7 @@ export fn bar() void {...@@ -11,7 +13,7 @@ export fn bar() void {
11// backend=stage213// backend=stage2
12// target=native14// target=native
13//15//
14// :3:5: error: unknown @memset length16// :4:5: error: unknown @memset length
15// :3:13: note: destination type '[*]u8' provides no length17// :4:13: note: destination type '[*]u8' provides no length
16// :7:5: error: unknown @memset length18// :9:5: error: unknown @memset length
17// :7:13: note: destination type '[*c]bool' provides no length19// :9:13: note: destination type '[*c]bool' provides no length
test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig+1-1
...@@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D {...@@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D {
7 };7 };
8}8}
9export fn entry() void {9export fn entry() void {
10 var geo_data = getGeo3DTex2D();10 const geo_data = getGeo3DTex2D();
11 _ = geo_data;11 _ = geo_data;
12}12}
1313
test/cases/compile_errors/missing_else_clause.zig+2-2
...@@ -14,7 +14,7 @@ fn h() void {...@@ -14,7 +14,7 @@ fn h() void {
14 // https://github.com/ziglang/zig/issues/1274314 // https://github.com/ziglang/zig/issues/12743
15 const T = struct { oh_no: *u32 };15 const T = struct { oh_no: *u32 };
16 var x: T = if (false) {};16 var x: T = if (false) {};
17 _ = x;17 _ = &x;
18}18}
19fn k(b: bool) void {19fn k(b: bool) void {
20 // block_ptr case20 // block_ptr case
...@@ -22,7 +22,7 @@ fn k(b: bool) void {...@@ -22,7 +22,7 @@ fn k(b: bool) void {
22 var x = if (b) blk: {22 var x = if (b) blk: {
23 break :blk if (false) T{ .oh_no = 2 };23 break :blk if (false) T{ .oh_no = 2 };
24 } else T{ .oh_no = 1 };24 } else T{ .oh_no = 1 };
25 _ = x;25 _ = &x;
26}26}
27export fn entry() void {27export fn entry() void {
28 f(true);28 f(true);
test/cases/compile_errors/missing_parameter_name_of_generic_function.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1fn dump(anytype) void {}1fn dump(anytype) void {}
2export fn entry() void {2export fn entry() void {
3 var a: u8 = 9;3 var a: u8 = 9;
4 dump(a);4 dump((&a).*);
5}5}
66
7// error7// error
test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig+1-1
...@@ -24,7 +24,7 @@ pub const JsonNode = struct {...@@ -24,7 +24,7 @@ pub const JsonNode = struct {
24fn foo() void {24fn foo() void {
25 var jll: JasonList = undefined;25 var jll: JasonList = undefined;
26 jll.init(1234);26 jll.init(1234);
27 var jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} };27 const jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} };
28 _ = jd;28 _ = jd;
29}29}
3030
test/cases/compile_errors/mod_on_undefined_value.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1comptime {1comptime {
2 var a: i64 = undefined;2 var a: i64 = undefined;
3 _ = a % a;3 _ = a % a;
4 _ = &a;
4}5}
56
6// error7// error
test/cases/compile_errors/mult_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: i64 = undefined;2 const a: i64 = undefined;
3 _ = a * a;3 _ = a * a;
4}4}
55
test/cases/compile_errors/negate_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: i64 = undefined;2 const a: i64 = undefined;
3 _ = -a;3 _ = -a;
4}4}
55
test/cases/compile_errors/nested_vectors.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn entry() void {1export fn entry() void {
2 const V1 = @Vector(4, u8);2 const V1 = @Vector(4, u8);
3 const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });3 const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
4 var v: V2 = undefined;4 const v: V2 = undefined;
5 _ = v;5 _ = v;
6}6}
77
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig+7-7
...@@ -1,30 +1,30 @@...@@ -1,30 +1,30 @@
1export fn entry1() void {1export fn entry1() void {
2 var m2 = &2;2 var m2 = &2;
3 _ = m2;3 _ = &m2;
4}4}
5export fn entry2() void {5export fn entry2() void {
6 var a = undefined;6 var a = undefined;
7 _ = a;7 _ = &a;
8}8}
9export fn entry3() void {9export fn entry3() void {
10 var b = 1;10 var b = 1;
11 _ = b;11 _ = &b;
12}12}
13export fn entry4() void {13export fn entry4() void {
14 var c = 1.0;14 var c = 1.0;
15 _ = c;15 _ = &c;
16}16}
17export fn entry5() void {17export fn entry5() void {
18 var d = null;18 var d = null;
19 _ = d;19 _ = &d;
20}20}
21export fn entry6(opaque_: *Opaque) void {21export fn entry6(opaque_: *Opaque) void {
22 var e = opaque_.*;22 var e = opaque_.*;
23 _ = e;23 _ = &e;
24}24}
25export fn entry7() void {25export fn entry7() void {
26 var f = i32;26 var f = i32;
27 _ = f;27 _ = &f;
28}28}
29const Opaque = opaque {};29const Opaque = opaque {};
30export fn entry8() void {30export fn entry8() void {
test/cases/compile_errors/non-integer_tag_type_to_enum.zig+1-1
...@@ -3,7 +3,7 @@ const Foo = enum(f32) {...@@ -3,7 +3,7 @@ const Foo = enum(f32) {
3};3};
4export fn entry() void {4export fn entry() void {
5 var f: Foo = undefined;5 var f: Foo = undefined;
6 _ = f;6 _ = &f;
7}7}
88
9// error9// error
test/cases/compile_errors/non_void_error_union_payload_ignored.zig+4-2
...@@ -5,6 +5,7 @@ pub export fn entry1() void {...@@ -5,6 +5,7 @@ pub export fn entry1() void {
5 } else |_| {5 } else |_| {
6 // bar6 // bar
7 }7 }
8 _ = &x;
8}9}
9pub export fn entry2() void {10pub export fn entry2() void {
10 var x: anyerror!usize = 5;11 var x: anyerror!usize = 5;
...@@ -13,6 +14,7 @@ pub export fn entry2() void {...@@ -13,6 +14,7 @@ pub export fn entry2() void {
13 } else |_| {14 } else |_| {
14 // bar15 // bar
15 }16 }
17 _ = &x;
16}18}
1719
18// error20// error
...@@ -21,5 +23,5 @@ pub export fn entry2() void {...@@ -21,5 +23,5 @@ pub export fn entry2() void {
21//23//
22// :3:5: error: error union payload is ignored24// :3:5: error: error union payload is ignored
23// :3:5: note: payload value can be explicitly ignored with '|_|'25// :3:5: note: payload value can be explicitly ignored with '|_|'
24// :11:5: error: error union payload is ignored26// :12:5: error: error union payload is ignored
25// :11:5: note: payload value can be explicitly ignored with '|_|'27// :12:5: note: payload value can be explicitly ignored with '|_|'
test/cases/compile_errors/not_an_enum_type.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var self: Error = undefined;2 var self: Error = undefined;
3 switch (self) {3 switch ((&self).*) {
4 InvalidToken => |x| return x.token,4 InvalidToken => |x| return x.token,
5 ExpectedVarDeclOrFn => |x| return x.token,5 ExpectedVarDeclOrFn => |x| return x.token,
6 }6 }
test/cases/compile_errors/or_on_undefined_value.zig+2-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1comptime {1comptime {
2 var a: bool = undefined;2 var a: bool = undefined;
3 _ = &a;
3 _ = a or a;4 _ = a or a;
4}5}
56
...@@ -7,4 +8,4 @@ comptime {...@@ -7,4 +8,4 @@ comptime {
7// backend=stage28// backend=stage2
8// target=native9// target=native
9//10//
10// :3:9: error: use of undefined value here causes undefined behavior11// :4:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/orelse_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: ?bool = undefined;2 const a: ?bool = undefined;
3 _ = a orelse false;3 _ = a orelse false;
4}4}
55
test/cases/compile_errors/out_of_bounds_index.zig+8-8
...@@ -1,29 +1,29 @@...@@ -1,29 +1,29 @@
1comptime {1comptime {
2 var array = [_:0]u8{ 1, 2, 3, 4 };2 var array = [_:0]u8{ 1, 2, 3, 4 };
3 var src_slice: [:0]u8 = &array;3 var src_slice: [:0]u8 = &array;
4 var slice = src_slice[2..6];4 const slice = src_slice[2..6];
5 _ = slice;5 _ = slice;
6}6}
7comptime {7comptime {
8 var array = [_:0]u8{ 1, 2, 3, 4 };8 var array = [_:0]u8{ 1, 2, 3, 4 };
9 var slice = array[2..6];9 const slice = array[2..6];
10 _ = slice;10 _ = slice;
11}11}
12comptime {12comptime {
13 var array = [_]u8{ 1, 2, 3, 4 };13 var array = [_]u8{ 1, 2, 3, 4 };
14 var slice = array[2..5];14 const slice = array[2..5];
15 _ = slice;15 _ = slice;
16}16}
17comptime {17comptime {
18 var array = [_:0]u8{ 1, 2, 3, 4 };18 var array = [_:0]u8{ 1, 2, 3, 4 };
19 var slice = array[3..2];19 const slice = array[3..2];
20 _ = slice;20 _ = slice;
21}21}
2222
23// error23// error
24// target=native24// target=native
25//25//
26// :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)26// :4:32: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
27// :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel)27// :9:28: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
28// :14:26: error: end index 5 out of bounds for array of length 428// :14:28: error: end index 5 out of bounds for array of length 4
29// :19:23: error: start index 3 is larger than end index 229// :19:25: error: start index 3 is larger than end index 2
test/cases/compile_errors/overflow_in_enum_value_allocation.zig+1-1
...@@ -3,7 +3,7 @@ const Moo = enum(u8) {...@@ -3,7 +3,7 @@ const Moo = enum(u8) {
3 Over,3 Over,
4};4};
5pub export fn entry() void {5pub export fn entry() void {
6 var y = Moo.Last;6 const y = Moo.Last;
7 _ = y;7 _ = y;
8}8}
99
test/cases/compile_errors/packed_union_given_enum_tag_type.zig+1-1
...@@ -9,7 +9,7 @@ const Payload = packed union(Letter) {...@@ -9,7 +9,7 @@ const Payload = packed union(Letter) {
9 C: bool,9 C: bool,
10};10};
11export fn entry() void {11export fn entry() void {
12 var a = Payload{ .A = 1234 };12 const a: Payload = .{ .A = 1234 };
13 _ = a;13 _ = a;
14}14}
1515
test/cases/compile_errors/packed_union_with_automatic_layout_field.zig+1-1
...@@ -7,7 +7,7 @@ const Payload = packed union {...@@ -7,7 +7,7 @@ const Payload = packed union {
7 B: bool,7 B: bool,
8};8};
9export fn entry() void {9export fn entry() void {
10 var a = Payload{ .B = true };10 const a: Payload = .{ .B = true };
11 _ = a;11 _ = a;
12}12}
1313
test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig+5-5
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn foo() void {1export fn foo() void {
2 var x: [10]u8 = undefined;2 var x: [10]u8 = undefined;
3 var y = &x;3 const y = &x;
4 var z = y + 1;4 const z = y + 1;
5 _ = z;5 _ = z;
6}6}
77
...@@ -9,6 +9,6 @@ export fn foo() void {...@@ -9,6 +9,6 @@ export fn foo() void {
9// backend=stage29// backend=stage2
10// target=native10// target=native
11//11//
12// :4:15: error: incompatible types: '*[10]u8' and 'comptime_int'12// :4:17: error: incompatible types: '*[10]u8' and 'comptime_int'
13// :4:13: note: type '*[10]u8' here13// :4:15: note: type '*[10]u8' here
14// :4:17: note: type 'comptime_int' here14// :4:19: note: type 'comptime_int' here
test/cases/compile_errors/pointer_to_anyopaque_slice.zig+1
...@@ -2,6 +2,7 @@ export fn x() void {...@@ -2,6 +2,7 @@ export fn x() void {
2 var a: *u32 = undefined;2 var a: *u32 = undefined;
3 var b: []anyopaque = undefined;3 var b: []anyopaque = undefined;
4 b = a;4 b = a;
5 _ = &a;
5}6}
67
7// error8// error
test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var y: [*]align(4) u8 = @ptrFromInt(5);2 var y: [*]align(4) u8 = @ptrFromInt(5);
3 _ = y;3 _ = &y;
4}4}
55
6// error6// error
test/cases/compile_errors/recursive_inline_fn.zig+2-1
...@@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 {...@@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 {
88
9pub export fn entry() void {9pub export fn entry() void {
10 var x: i32 = 4;10 var x: i32 = 4;
11 _ = &x;
11 _ = foo(x) == 20;12 _ = foo(x) == 20;
12}13}
1314
...@@ -32,4 +33,4 @@ pub export fn entry2() void {...@@ -32,4 +33,4 @@ pub export fn entry2() void {
32// target=native33// target=native
33//34//
34// :5:27: error: inline call is recursive35// :5:27: error: inline call is recursive
35// :23:10: error: inline call is recursive36// :24:10: error: inline call is recursive
test/cases/compile_errors/reference_to_const_data.zig+6-3
...@@ -5,10 +5,12 @@ export fn foo() void {...@@ -5,10 +5,12 @@ export fn foo() void {
5export fn bar() void {5export fn bar() void {
6 var ptr = &@as(u32, 2);6 var ptr = &@as(u32, 2);
7 ptr.* = 2;7 ptr.* = 2;
8 _ = &ptr;
8}9}
9export fn baz() void {10export fn baz() void {
10 var ptr = &true;11 var ptr = &true;
11 ptr.* = false;12 ptr.* = false;
13 _ = &ptr;
12}14}
13export fn qux() void {15export fn qux() void {
14 const S = struct {16 const S = struct {
...@@ -21,6 +23,7 @@ export fn qux() void {...@@ -21,6 +23,7 @@ export fn qux() void {
21export fn quux() void {23export fn quux() void {
22 var x = &@returnAddress();24 var x = &@returnAddress();
23 x.* = 6;25 x.* = 6;
26 _ = &x;
24}27}
2528
26// error29// error
...@@ -29,6 +32,6 @@ export fn quux() void {...@@ -29,6 +32,6 @@ export fn quux() void {
29//32//
30// :3:8: error: cannot assign to constant33// :3:8: error: cannot assign to constant
31// :7:8: error: cannot assign to constant34// :7:8: error: cannot assign to constant
32// :11:8: error: cannot assign to constant35// :12:8: error: cannot assign to constant
33// :19:8: error: cannot assign to constant36// :21:8: error: cannot assign to constant
34// :23:6: error: cannot assign to constant37// :25:6: error: cannot assign to constant
test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig+1
...@@ -2,6 +2,7 @@ export fn entry() void {...@@ -2,6 +2,7 @@ export fn entry() void {
2 var var_1: f32 = undefined;2 var var_1: f32 = undefined;
3 var var_2: u32 = undefined;3 var var_2: u32 = undefined;
4 _ = @TypeOf(var_1, var_2);4 _ = @TypeOf(var_1, var_2);
5 _ = .{ &var_1, &var_2 };
5}6}
67
7// error8// error
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var damn = Container{2 const damn = Container{
3 .not_optional = getOptional(),3 .not_optional = getOptional(),
4 };4 };
5 _ = damn;5 _ = damn;
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig+1-1
...@@ -2,7 +2,7 @@ export fn entry() void {...@@ -2,7 +2,7 @@ export fn entry() void {
2 var damn = Container{2 var damn = Container{
3 .not_optional = getOptional(i32),3 .not_optional = getOptional(i32),
4 };4 };
5 _ = damn;5 _ = &damn;
6}6}
7pub fn getOptional(comptime T: type) ?T {7pub fn getOptional(comptime T: type) ?T {
8 return 0;8 return 0;
test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig+1
...@@ -5,6 +5,7 @@ const Foo = struct {...@@ -5,6 +5,7 @@ const Foo = struct {
5export fn f() void {5export fn f() void {
6 var x: u8 = 0;6 var x: u8 = 0;
7 const foo = Foo{ .Bar = x, .Baz = u8 };7 const foo = Foo{ .Bar = x, .Baz = u8 };
8 _ = &x;
8 _ = foo;9 _ = foo;
9}10}
1011
test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig+3-2
...@@ -4,6 +4,7 @@ const Foo = union {...@@ -4,6 +4,7 @@ const Foo = union {
4};4};
5export fn f() void {5export fn f() void {
6 var x: u8 = 0;6 var x: u8 = 0;
7 _ = &x;
7 const foo = Foo{ .Bar = x };8 const foo = Foo{ .Bar = x };
8 _ = foo;9 _ = foo;
9}10}
...@@ -12,5 +13,5 @@ export fn f() void {...@@ -12,5 +13,5 @@ export fn f() void {
12// backend=stage213// backend=stage2
13// target=native14// target=native
14//15//
15// :7:23: error: unable to resolve comptime value16// :8:23: error: unable to resolve comptime value
16// :7:23: note: initializer of comptime only union must be comptime-known17// :8:23: note: initializer of comptime only union must be comptime-known
test/cases/compile_errors/runtime_cast_to_union_which_has_non-void_fields.zig+2-2
...@@ -8,7 +8,7 @@ export fn entry() void {...@@ -8,7 +8,7 @@ export fn entry() void {
8 foo(Letter.A);8 foo(Letter.A);
9}9}
10fn foo(l: Letter) void {10fn foo(l: Letter) void {
11 var x: Value = l;11 const x: Value = l;
12 _ = x;12 _ = x;
13}13}
1414
...@@ -16,6 +16,6 @@ fn foo(l: Letter) void {...@@ -16,6 +16,6 @@ fn foo(l: Letter) void {
16// backend=stage216// backend=stage2
17// target=native17// target=native
18//18//
19// :11:20: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields19// :11:22: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields
20// :3:5: note: field 'A' has type 'i32'20// :3:5: note: field 'A' has type 'i32'
21// :2:15: note: union declared here21// :2:15: note: union declared here
test/cases/compile_errors/runtime_indexing_comptime_array.zig+4-2
...@@ -13,12 +13,14 @@ pub export fn entry2() void {...@@ -13,12 +13,14 @@ pub export fn entry2() void {
13 const test_fns = [_]TestFn{ foo, bar };13 const test_fns = [_]TestFn{ foo, bar };
14 var i: usize = 0;14 var i: usize = 0;
15 _ = test_fns[i];15 _ = test_fns[i];
16 _ = &i;
16}17}
17pub export fn entry3() void {18pub export fn entry3() void {
18 const TestFn = fn () void;19 const TestFn = fn () void;
19 const test_fns = [_]TestFn{ foo, bar };20 const test_fns = [_]TestFn{ foo, bar };
20 var i: usize = 0;21 var i: usize = 0;
21 _ = &test_fns[i];22 _ = &test_fns[i];
23 _ = &i;
22}24}
23// error25// error
24// target=native26// target=native
...@@ -28,5 +30,5 @@ pub export fn entry3() void {...@@ -28,5 +30,5 @@ pub export fn entry3() void {
28// :7:10: note: use '*const fn () void' for a function pointer type30// :7:10: note: use '*const fn () void' for a function pointer type
29// :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known31// :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
30// :15:17: note: use '*const fn () void' for a function pointer type32// :15:17: note: use '*const fn () void' for a function pointer type
31// :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known33// :22:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
32// :21:18: note: use '*const fn () void' for a function pointer type34// :22:18: note: use '*const fn () void' for a function pointer type
test/cases/compile_errors/runtime_to_comptime_num.zig+12-8
...@@ -1,19 +1,23 @@...@@ -1,19 +1,23 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var a: u32 = 0;2 var a: u32 = 0;
3 _ = &a;
3 _ = @as(comptime_int, a);4 _ = @as(comptime_int, a);
4}5}
5pub export fn entry2() void {6pub export fn entry2() void {
6 var a: u32 = 0;7 var a: u32 = 0;
8 _ = &a;
7 _ = @as(comptime_float, a);9 _ = @as(comptime_float, a);
8}10}
9pub export fn entry3() void {11pub export fn entry3() void {
10 comptime var aa: comptime_float = 0.0;12 comptime var aa: comptime_float = 0.0;
11 var a: f32 = 4;13 var a: f32 = 4;
14 _ = &a;
12 aa = a;15 aa = a;
13}16}
14pub export fn entry4() void {17pub export fn entry4() void {
15 comptime var aa: comptime_int = 0.0;18 comptime var aa: comptime_int = 0.0;
16 var a: f32 = 4;19 var a: f32 = 4;
20 _ = &a;
17 aa = a;21 aa = a;
18}22}
1923
...@@ -21,11 +25,11 @@ pub export fn entry4() void {...@@ -21,11 +25,11 @@ pub export fn entry4() void {
21// backend=stage225// backend=stage2
22// target=native26// target=native
23//27//
24// :3:27: error: unable to resolve comptime value28// :4:27: error: unable to resolve comptime value
25// :3:27: note: value being casted to 'comptime_int' must be comptime-known29// :4:27: note: value being casted to 'comptime_int' must be comptime-known
26// :7:29: error: unable to resolve comptime value30// :9:29: error: unable to resolve comptime value
27// :7:29: note: value being casted to 'comptime_float' must be comptime-known31// :9:29: note: value being casted to 'comptime_float' must be comptime-known
28// :12:10: error: unable to resolve comptime value32// :15:10: error: unable to resolve comptime value
29// :12:10: note: value being casted to 'comptime_float' must be comptime-known33// :15:10: note: value being casted to 'comptime_float' must be comptime-known
30// :17:10: error: unable to resolve comptime value34// :21:10: error: unable to resolve comptime value
31// :17:10: note: value being casted to 'comptime_int' must be comptime-known35// :21:10: note: value being casted to 'comptime_int' must be comptime-known
test/cases/compile_errors/runtime_value_in_switch_prong.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var byte: u8 = 1;2 var byte: u8 = 1;
3 switch (byte) {3 switch ((&byte).*) {
4 byte => {},4 byte => {},
5 else => {},5 else => {},
6 }6 }
test/cases/compile_errors/self_referential_struct_requires_comptime.zig+1-1
...@@ -4,7 +4,7 @@ const S = struct {...@@ -4,7 +4,7 @@ const S = struct {
4};4};
5pub export fn entry() void {5pub export fn entry() void {
6 var s: S = undefined;6 var s: S = undefined;
7 _ = s;7 _ = &s;
8}8}
99
10// error10// error
test/cases/compile_errors/self_referential_union_requires_comptime.zig+1-1
...@@ -4,7 +4,7 @@ const U = union {...@@ -4,7 +4,7 @@ const U = union {
4};4};
5pub export fn entry() void {5pub export fn entry() void {
6 var u: U = undefined;6 var u: U = undefined;
7 _ = u;7 _ = &u;
8}8}
99
10// error10// error
test/cases/compile_errors/shift_by_negative_comptime_integer.zig+2-2
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a = 1 >> -1;2 const a = 1 >> -1;
3 _ = a;3 _ = a;
4}4}
55
...@@ -7,4 +7,4 @@ comptime {...@@ -7,4 +7,4 @@ comptime {
7// backend=stage27// backend=stage2
8// target=native8// target=native
9//9//
10// :2:18: error: shift by negative amount '-1'10// :2:20: error: shift by negative amount '-1'
test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig+8-4
...@@ -2,18 +2,22 @@ export fn entry() void {...@@ -2,18 +2,22 @@ export fn entry() void {
2 const S = struct {2 const S = struct {
3 fn a() void {3 fn a() void {
4 var x: u24 = 42;4 var x: u24 = 42;
5 _ = &x;
5 _ = x >> 24;6 _ = x >> 24;
6 }7 }
7 fn b() void {8 fn b() void {
8 var x: u24 = 42;9 var x: u24 = 42;
10 _ = &x;
9 _ = x << 24;11 _ = x << 24;
10 }12 }
11 fn c() void {13 fn c() void {
12 var x: u24 = 42;14 var x: u24 = 42;
15 _ = &x;
13 _ = @shlExact(x, 24);16 _ = @shlExact(x, 24);
14 }17 }
15 fn d() void {18 fn d() void {
16 var x: u24 = 42;19 var x: u24 = 42;
20 _ = &x;
17 _ = @shrExact(x, 24);21 _ = @shrExact(x, 24);
18 }22 }
19 };23 };
...@@ -27,7 +31,7 @@ export fn entry() void {...@@ -27,7 +31,7 @@ export fn entry() void {
27// backend=stage231// backend=stage2
28// target=native32// target=native
29//33//
30// :5:22: error: shift amount '24' is too large for operand type 'u24'34// :6:22: error: shift amount '24' is too large for operand type 'u24'
31// :9:22: error: shift amount '24' is too large for operand type 'u24'35// :11:22: error: shift amount '24' is too large for operand type 'u24'
32// :13:30: error: shift amount '24' is too large for operand type 'u24'36// :16:30: error: shift amount '24' is too large for operand type 'u24'
33// :17:30: error: shift amount '24' is too large for operand type 'u24'37// :21:30: error: shift amount '24' is too large for operand type 'u24'
test/cases/compile_errors/shifting_without_int_type_or_comptime_known.zig+4-2
...@@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 {...@@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 {
6}6}
7export fn entry2() void {7export fn entry2() void {
8 var x: u5 = 1;8 var x: u5 = 1;
9 _ = &x;
9 _ = @shlExact(12345, x);10 _ = @shlExact(12345, x);
10}11}
11export fn entry3() void {12export fn entry3() void {
12 var x: u5 = 1;13 var x: u5 = 1;
14 _ = &x;
13 _ = @shrExact(12345, x);15 _ = @shrExact(12345, x);
14}16}
1517
...@@ -19,5 +21,5 @@ export fn entry3() void {...@@ -19,5 +21,5 @@ export fn entry3() void {
19//21//
20// :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known22// :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
21// :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known23// :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
22// :9:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known24// :10:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
23// :13:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known25// :15:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
test/cases/compile_errors/shuffle_with_selected_index_past_first_vector_length.zig+4-4
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn entry() void {1export fn entry() void {
2 const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };2 const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
3 const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };3 const x: @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 });4 const z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
5 _ = z;5 _ = z;
6}6}
77
...@@ -9,6 +9,6 @@ export fn entry() void {...@@ -9,6 +9,6 @@ export fn entry() void {
9// backend=stage29// backend=stage2
10// target=native10// target=native
11//11//
12// :4:39: error: mask index '4' has out-of-bounds selection12// :4:41: error: mask index '4' has out-of-bounds selection
13// :4:27: note: selected index '7' out of bounds of '@Vector(4, u32)'13// :4:29: note: selected index '7' out of bounds of '@Vector(4, u32)'
14// :4:30: note: selections from the second vector are specified with negative numbers14// :4:32: note: selections from the second vector are specified with negative numbers
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig+2-3
...@@ -1,11 +1,10 @@...@@ -1,11 +1,10 @@
1export fn foo() void {1export fn foo() void {
2 const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16;2 const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16;
3 var value = @as(*const []const u8, @ptrCast(&bytes)).*;3 _ = @as(*const []const u8, @ptrCast(&bytes)).*;
4 _ = value;
5}4}
65
7// error6// error
8// backend=stage27// backend=stage2
9// target=native8// target=native
10//9//
11// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.10// :3:49: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.
test/cases/compile_errors/slice_of_null_pointer.zig+3-3
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1comptime {1comptime {
2 var x: [*c]u8 = null;2 var x: [*c]u8 = null;
3 var runtime_len: usize = 0;3 var runtime_len: usize = 0;
4 var y = x[0..runtime_len];4 _ = &runtime_len;
5 _ = y;5 _ = x[0..runtime_len];
6}6}
77
8// error8// error
9// target=native9// target=native
10//10//
11// :4:14: error: slice of null pointer11// :5:10: error: slice of null pointer
test/cases/compile_errors/slice_sentinel_mismatch-2.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1fn foo() [:0]u8 {1fn foo() [:0]u8 {
2 var x: []u8 = undefined;2 const x: []u8 = undefined;
3 return x;3 return x;
4}4}
5comptime {5comptime {
test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig+1-2
...@@ -7,8 +7,7 @@ const Small = enum(u2) {...@@ -7,8 +7,7 @@ const Small = enum(u2) {
7};7};
88
9export fn entry() void {9export fn entry() void {
10 var x = Small.One;10 _ = Small.One;
11 _ = x;
12}11}
1312
14// error13// error
test/cases/compile_errors/specify_non-integer_enum_tag_type.zig+1-1
...@@ -5,7 +5,7 @@ const Small = enum(f32) {...@@ -5,7 +5,7 @@ const Small = enum(f32) {
5};5};
66
7export fn entry() void {7export fn entry() void {
8 var x = Small.One;8 const x = Small.One;
9 _ = x;9 _ = x;
10}10}
1111
test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig+1-1
...@@ -2,7 +2,7 @@ export fn entry() void {...@@ -2,7 +2,7 @@ export fn entry() void {
2 var sp = asm volatile ("mov %[foo], sp"2 var sp = asm volatile ("mov %[foo], sp"
3 : [bar] "=r" (-> usize),3 : [bar] "=r" (-> usize),
4 );4 );
5 _ = sp;5 _ = &sp;
6}6}
77
8// error8// error
test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig+2-1
...@@ -2,6 +2,7 @@ export fn entry() void {...@@ -2,6 +2,7 @@ export fn entry() void {
2 var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined };2 var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined };
33
4 var i: u32 = 0;4 var i: u32 = 0;
5 _ = &i;
5 storev(&v[i], 42);6 storev(&v[i], 42);
6}7}
78
...@@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void {...@@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void {
13// backend=llvm14// backend=llvm
14// target=native15// target=native
15//16//
16// :9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31'17// :10:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31'
test/cases/compile_errors/sub_on_undefined_value.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1comptime {1comptime {
2 var a: i64 = undefined;2 const a: i64 = undefined;
3 _ = a - a;3 _ = a - a;
4}4}
55
test/cases/compile_errors/switch_capture_incompatible_types.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1export fn f() void {1export fn f() void {
2 const U = union(enum) { a: u32, b: *u8 };2 const U = union(enum) { a: u32, b: *u8 };
3 var u: U = undefined;3 var u: U = undefined;
4 switch (u) {4 switch ((&u).*) {
5 .a, .b => |val| _ = val,5 .a, .b => |val| _ = val,
6 }6 }
7}7}
...@@ -9,7 +9,7 @@ export fn f() void {...@@ -9,7 +9,7 @@ export fn f() void {
9export fn g() void {9export fn g() void {
10 const U = union(enum) { a: u64, b: u32 };10 const U = union(enum) { a: u64, b: u32 };
11 var u: U = undefined;11 var u: U = undefined;
12 switch (u) {12 switch ((&u).*) {
13 .a, .b => |*ptr| _ = ptr,13 .a, .b => |*ptr| _ = ptr,
14 }14 }
15}15}
test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const Foo = enum { M };1const Foo = enum { M };
22
3export fn entry() void {3export fn entry() void {
4 var f = Foo.M;4 const f = Foo.M;
5 switch (f) {}5 switch (f) {}
6}6}
77
test/cases/compile_errors/switch_on_slice.zig+2-1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub export fn entry() void {1pub export fn entry() void {
2 var a: [:0]const u8 = "foo";2 var a: [:0]const u8 = "foo";
3 _ = &a;
3 switch (a) {4 switch (a) {
4 ("--version"), ("version") => unreachable,5 ("--version"), ("version") => unreachable,
5 else => {},6 else => {},
...@@ -10,4 +11,4 @@ pub export fn entry() void {...@@ -10,4 +11,4 @@ pub export fn entry() void {
10// backend=stage211// backend=stage2
11// target=native12// target=native
12//13//
13// :3:13: error: switch on type '[:0]const u8'14// :4:13: error: switch on type '[:0]const u8'
test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig+2-2
...@@ -1,12 +1,12 @@...@@ -1,12 +1,12 @@
1pub export fn entry1() void {1pub export fn entry1() void {
2 var x: i32 = 0;2 const x: i32 = 0;
3 switch (x) {3 switch (x) {
4 6...1 => {},4 6...1 => {},
5 else => unreachable,5 else => unreachable,
6 }6 }
7}7}
8pub export fn entr2() void {8pub export fn entr2() void {
9 var x: i32 = 0;9 const x: i32 = 0;
10 switch (x) {10 switch (x) {
11 -1...-5 => {},11 -1...-5 => {},
12 else => unreachable,12 else => unreachable,
test/cases/compile_errors/switch_with_overlapping_case_ranges.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry() void {1export fn entry() void {
2 var q: u8 = 0;2 var q: u8 = 0;
3 switch (q) {3 switch ((&q).*) {
4 1...2 => {},4 1...2 => {},
5 0...255 => {},5 0...255 => {},
6 }6 }
test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig+1-1
...@@ -3,7 +3,7 @@ const E = enum {...@@ -3,7 +3,7 @@ const E = enum {
3 b,3 b,
4};4};
5pub export fn entry() void {5pub export fn entry() void {
6 var e: E = .b;6 const e: E = .b;
7 switch (e) {7 switch (e) {
8 .a => {},8 .a => {},
9 .b => {},9 .b => {},
test/cases/compile_errors/switching_with_non-exhaustive_enums.zig+3-3
...@@ -8,21 +8,21 @@ const U = union(E) {...@@ -8,21 +8,21 @@ const U = union(E) {
8 b: u32,8 b: u32,
9};9};
10pub export fn entry1() void {10pub export fn entry1() void {
11 var e: E = .b;11 const e: E = .b;
12 switch (e) { // error: switch not handling the tag `b`12 switch (e) { // error: switch not handling the tag `b`
13 .a => {},13 .a => {},
14 _ => {},14 _ => {},
15 }15 }
16}16}
17pub export fn entry2() void {17pub export fn entry2() void {
18 var e: E = .b;18 const e: E = .b;
19 switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong19 switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
20 .a => {},20 .a => {},
21 .b => {},21 .b => {},
22 }22 }
23}23}
24pub export fn entry3() void {24pub export fn entry3() void {
25 var u = U{ .a = 2 };25 const u = U{ .a = 2 };
26 switch (u) { // error: `_` prong not allowed when switching on tagged union26 switch (u) { // error: `_` prong not allowed when switching on tagged union
27 .a => {},27 .a => {},
28 .b => {},28 .b => {},
test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig+3-4
...@@ -3,14 +3,13 @@ const FloatInt = extern union {...@@ -3,14 +3,13 @@ const FloatInt = extern union {
3 Int: i32,3 Int: i32,
4};4};
5export fn entry() void {5export fn entry() void {
6 var fi = FloatInt{ .Float = 123.45 };6 const fi: FloatInt = .{ .Float = 123.45 };
7 var tagName = @tagName(fi);7 _ = @tagName(fi);
8 _ = tagName;
9}8}
109
11// error10// error
12// backend=stage211// backend=stage2
13// target=native12// target=native
14//13//
15// :7:19: error: union 'tmp.FloatInt' is untagged14// :7:9: error: union 'tmp.FloatInt' is untagged
16// :1:25: note: union declared here15// :1:25: note: union declared here
test/cases/compile_errors/truncate_sign_mismatch.zig+8-8
...@@ -1,25 +1,25 @@...@@ -1,25 +1,25 @@
1export fn entry1() i8 {1export fn entry1() i8 {
2 var x: u32 = 10;2 var x: u32 = 10;
3 return @truncate(x);3 return @truncate((&x).*);
4}4}
5export fn entry2() u8 {5export fn entry2() u8 {
6 var x: i32 = -10;6 var x: i32 = -10;
7 return @truncate(x);7 return @truncate((&x).*);
8}8}
9export fn entry3() i8 {9export fn entry3() i8 {
10 comptime var x: u32 = 10;10 comptime var x: u32 = 10;
11 return @truncate(x);11 return @truncate((&x).*);
12}12}
13export fn entry4() u8 {13export fn entry4() u8 {
14 comptime var x: i32 = -10;14 comptime var x: i32 = -10;
15 return @truncate(x);15 return @truncate((&x).*);
16}16}
1717
18// error18// error
19// backend=stage219// backend=stage2
20// target=native20// target=native
21//21//
22// :3:22: error: expected signed integer type, found 'u32'22// :3:26: error: expected signed integer type, found 'u32'
23// :7:22: error: expected unsigned integer type, found 'i32'23// :7:26: error: expected unsigned integer type, found 'i32'
24// :11:22: error: expected signed integer type, found 'u32'24// :11:26: error: expected signed integer type, found 'u32'
25// :15:22: error: expected unsigned integer type, found 'i32'25// :15:26: error: expected unsigned integer type, found 'i32'
test/cases/compile_errors/tuple_init_edge_cases.zig+23-18
...@@ -1,49 +1,54 @@...@@ -1,49 +1,54 @@
1pub export fn entry1() void {1pub export fn entry1() void {
2 const T = @TypeOf(.{ 123, 3 });2 const T = @TypeOf(.{ 123, 3 });
3 var b = T{ .@"1" = 3 };3 var b = T{ .@"1" = 3 };
4 _ = b;4 _ = &b;
5 var c = T{ 123, 3 };5 var c = T{ 123, 3 };
6 _ = c;6 _ = &c;
7 var d = T{};7 var d = T{};
8 _ = d;8 _ = &d;
9}9}
10pub export fn entry2() void {10pub export fn entry2() void {
11 var a: u32 = 2;11 var a: u32 = 2;
12 _ = &a;
12 const T = @TypeOf(.{ 123, a });13 const T = @TypeOf(.{ 123, a });
13 var b = T{ .@"1" = 3 };14 var b = T{ .@"1" = 3 };
14 _ = b;15 _ = &b;
15 var c = T{ 123, 3 };16 var c = T{ 123, 3 };
16 _ = c;17 _ = &c;
17 var d = T{};18 var d = T{};
18 _ = d;19 _ = &d;
19}20}
20pub export fn entry3() void {21pub export fn entry3() void {
21 var a: u32 = 2;22 var a: u32 = 2;
23 _ = &a;
22 const T = @TypeOf(.{ 123, a });24 const T = @TypeOf(.{ 123, a });
23 var b = T{ .@"0" = 123 };25 var b = T{ .@"0" = 123 };
24 _ = b;26 _ = &b;
25}27}
26comptime {28comptime {
27 var a: u32 = 2;29 var a: u32 = 2;
30 _ = &a;
28 const T = @TypeOf(.{ 123, a });31 const T = @TypeOf(.{ 123, a });
29 var b = T{ .@"0" = 123 };32 var b = T{ .@"0" = 123 };
30 _ = b;33 _ = &b;
31 var c = T{ 123, 2 };34 var c = T{ 123, 2 };
32 _ = c;35 _ = &c;
33 var d = T{};36 var d = T{};
34 _ = d;37 _ = &d;
35}38}
36pub export fn entry4() void {39pub export fn entry4() void {
37 var a: u32 = 2;40 var a: u32 = 2;
41 _ = &a;
38 const T = @TypeOf(.{ 123, a });42 const T = @TypeOf(.{ 123, a });
39 var b = T{ 123, 4, 5 };43 var b = T{ 123, 4, 5 };
40 _ = b;44 _ = &b;
41}45}
42pub export fn entry5() void {46pub export fn entry5() void {
43 var a: u32 = 2;47 var a: u32 = 2;
48 _ = &a;
44 const T = @TypeOf(.{ 123, a });49 const T = @TypeOf(.{ 123, a });
45 var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 };50 var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 };
46 _ = b;51 _ = &b;
47}52}
48pub const Consideration = struct {53pub const Consideration = struct {
49 curve: Curve,54 curve: Curve,
...@@ -64,9 +69,9 @@ pub export fn entry6() void {...@@ -64,9 +69,9 @@ pub export fn entry6() void {
64// backend=stage269// backend=stage2
65// target=native70// target=native
66//71//
67// :17:14: error: missing tuple field with index 172// :18:14: error: missing tuple field with index 1
68// :23:14: error: missing tuple field with index 173// :25:14: error: missing tuple field with index 1
69// :39:14: error: expected at most 2 tuple fields; found 374// :43:14: error: expected at most 2 tuple fields; found 3
70// :45:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}'75// :50:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}'
71// :58:37: error: missing tuple field with index 376// :63:37: error: missing tuple field with index 3
72// :53:32: note: struct declared here77// :58:32: note: struct declared here
test/cases/compile_errors/uncreachable_else_prong_err_set.zig deleted-25
...@@ -1,25 +0,0 @@
1pub export fn complex() void {
2 var a: error{ Foo, Bar } = error.Foo;
3 switch (a) {
4 error.Foo => unreachable,
5 error.Bar => unreachable,
6 else => {
7 @compileError("<something complex here>");
8 },
9 }
10}
11
12pub export fn simple() void {
13 var a: error{ Foo, Bar } = error.Foo;
14 switch (a) {
15 error.Foo => unreachable,
16 error.Bar => unreachable,
17 else => |e| return e,
18 }
19}
20
21// error
22// backend=llvm
23// target=native
24//
25// :6:14: error: unreachable else prong; all cases already handled
test/cases/compile_errors/union_access_of_inactive_field.zig+1
...@@ -5,6 +5,7 @@ const U = union {...@@ -5,6 +5,7 @@ const U = union {
5comptime {5comptime {
6 var u: U = .{ .a = {} };6 var u: U = .{ .a = {} };
7 const v = u.b;7 const v = u.b;
8 _ = &u;
8 _ = v;9 _ = v;
9}10}
1011
test/cases/compile_errors/union_auto-enum_value_already_taken.zig+1-1
...@@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) {...@@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) {
6 E = 60,6 E = 60,
7};7};
8export fn entry() void {8export fn entry() void {
9 var x = MultipleChoice{ .C = {} };9 const x: MultipleChoice = .{ .C = {} };
10 _ = x;10 _ = x;
11}11}
1212
test/cases/compile_errors/union_duplicate_enum_field.zig+1-1
...@@ -5,7 +5,7 @@ const U = union(E) {...@@ -5,7 +5,7 @@ const U = union(E) {
5};5};
66
7export fn foo() void {7export fn foo() void {
8 var u: U = .{ .a = 123 };8 const u: U = .{ .a = 123 };
9 _ = u;9 _ = u;
10}10}
1111
test/cases/compile_errors/union_enum_field_does_not_match_enum.zig+1-1
...@@ -10,7 +10,7 @@ const Payload = union(Letter) {...@@ -10,7 +10,7 @@ const Payload = union(Letter) {
10 D: bool,10 D: bool,
11};11};
12export fn entry() void {12export fn entry() void {
13 var a = Payload{ .A = 1234 };13 const a: Payload = .{ .A = 1234 };
14 _ = a;14 _ = a;
15}15}
1616
test/cases/compile_errors/union_noreturn_field_initialized.zig+3-3
...@@ -9,7 +9,7 @@ pub export fn entry1() void {...@@ -9,7 +9,7 @@ pub export fn entry1() void {
9 };9 };
1010
11 var a = U{ .b = undefined };11 var a = U{ .b = undefined };
12 _ = a;12 _ = &a;
13}13}
14pub export fn entry2() void {14pub export fn entry2() void {
15 const U = union(enum) {15 const U = union(enum) {
...@@ -25,7 +25,7 @@ pub export fn entry3() void {...@@ -25,7 +25,7 @@ pub export fn entry3() void {
25 };25 };
26 var e = @typeInfo(U).Union.tag_type.?.a;26 var e = @typeInfo(U).Union.tag_type.?.a;
27 var u: U = undefined;27 var u: U = undefined;
28 u = e;28 u = (&e).*;
29}29}
3030
31// error31// error
...@@ -38,6 +38,6 @@ pub export fn entry3() void {...@@ -38,6 +38,6 @@ pub export fn entry3() void {
38// :19:10: error: cannot initialize 'noreturn' field of union38// :19:10: error: cannot initialize 'noreturn' field of union
39// :16:9: note: field 'a' declared here39// :16:9: note: field 'a' declared here
40// :15:15: note: union declared here40// :15:15: note: union declared here
41// :28:9: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field41// :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
42// :23:9: note: 'noreturn' field here42// :23:9: note: 'noreturn' field here
43// :22:15: note: union declared here43// :22:15: note: union declared here
test/cases/compile_errors/union_runtime_coercion_from_enum.zig+1-1
...@@ -11,7 +11,7 @@ fn foo() E {...@@ -11,7 +11,7 @@ fn foo() E {
11}11}
12export fn doTheTest() u64 {12export fn doTheTest() u64 {
13 var u: U = foo();13 var u: U = foo();
14 return u.b;14 return (&u).b;
15}15}
1616
17// error17// error
test/cases/compile_errors/unreachable_else_prong_err_set.zig created+27
...@@ -0,0 +1,27 @@
1pub export fn complex() void {
2 var a: error{ Foo, Bar } = error.Foo;
3 _ = &a;
4 switch (a) {
5 error.Foo => unreachable,
6 error.Bar => unreachable,
7 else => {
8 @compileError("<something complex here>");
9 },
10 }
11}
12
13pub export fn simple() void {
14 var a: error{ Foo, Bar } = error.Foo;
15 _ = &a;
16 switch (a) {
17 error.Foo => unreachable,
18 error.Bar => unreachable,
19 else => |e| return e,
20 }
21}
22
23// error
24// backend=llvm
25// target=native
26//
27// :7:14: error: unreachable else prong; all cases already handled
test/cases/compile_errors/use_implicit_casts_to_assign_null_to_non-nullable_pointer.zig+5-6
...@@ -1,16 +1,15 @@...@@ -1,16 +1,15 @@
1export fn entry() void {1export fn entry() void {
2 var x: i32 = 1234;2 var x: i32 = 1234;
3 var p: *i32 = &x;3 var p: *i32 = &x;
4 var pp: *?*i32 = &p;4 const pp: *?*i32 = &p;
5 pp.* = null;5 pp.* = null;
6 var y = p.*;6 _ = p.*;
7 _ = y;
8}7}
98
10// error9// error
11// backend=stage210// backend=stage2
12// target=native11// target=native
13//12//
14// :4:22: error: expected type '*?*i32', found '**i32'13// :4:24: error: expected type '*?*i32', found '**i32'
15// :4:22: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'14// :4:24: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'
16// :4:22: note: mutable '*i32' allows illegal null values stored to type '?*i32'15// :4:24: note: mutable '*i32' allows illegal null values stored to type '?*i32'
test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig+1-1
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1var v = 25;1var v = 25;
2export fn entry() void {2export fn entry() void {
3 var arr: [v]u8 = undefined;3 var arr: [v]u8 = undefined;
4 _ = arr;4 _ = &arr;
5}5}
66
7// error7// error
test/cases/compile_errors/variable_with_type_noreturn.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1export fn entry9() void {1export fn entry9() void {
2 var z: noreturn = return;2 var z: noreturn = return;
3 _ = z;3 _ = &z;
4}4}
55
6// error6// error
test/cases/compile_errors/variadic_arg_validation.zig+5-4
...@@ -7,6 +7,7 @@ pub export fn entry() void {...@@ -7,6 +7,7 @@ pub export fn entry() void {
7pub export fn entry1() void {7pub export fn entry1() void {
8 var arr: [2]u8 = undefined;8 var arr: [2]u8 = undefined;
9 _ = printf("%d\n", arr);9 _ = printf("%d\n", arr);
10 _ = &arr;
10}11}
1112
12pub export fn entry2() void {13pub export fn entry2() void {
...@@ -23,7 +24,7 @@ pub export fn entry3() void {...@@ -23,7 +24,7 @@ pub export fn entry3() void {
23//24//
24// :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type25// :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type
25// :9:24: error: arrays must be passed by reference to variadic function26// :9:24: error: arrays must be passed by reference to variadic function
26// :13:24: error: cannot pass 'u48' to variadic function27// :14:24: error: cannot pass 'u48' to variadic function
27// :13:24: note: only integers with 0 or power of two bits are extern compatible28// :14:24: note: only integers with 0 or power of two bits are extern compatible
28// :17:24: error: cannot pass 'void' to variadic function29// :18:24: error: cannot pass 'void' to variadic function
29// :17:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'30// :18:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
test/cases/compile_errors/while_loop_body_expression_ignored.zig+16-12
...@@ -6,18 +6,22 @@ export fn f1() void {...@@ -6,18 +6,22 @@ export fn f1() void {
6}6}
7export fn f2() void {7export fn f2() void {
8 var x: ?i32 = null;8 var x: ?i32 = null;
9 _ = &x;
9 while (x) |_| returns();10 while (x) |_| returns();
10}11}
11export fn f3() void {12export fn f3() void {
12 var x: anyerror!i32 = error.Bad;13 var x: anyerror!i32 = error.Bad;
14 _ = &x;
13 while (x) |_| returns() else |_| unreachable;15 while (x) |_| returns() else |_| unreachable;
14}16}
15export fn f4() void {17export fn f4() void {
16 var a = true;18 var a = true;
19 _ = &a;
17 while (a) {} else true;20 while (a) {} else true;
18}21}
19export fn f5() void {22export fn f5() void {
20 var a = true;23 var a = true;
24 _ = &a;
21 const foo = while (a) returns() else true;25 const foo = while (a) returns() else true;
22 _ = foo;26 _ = foo;
23}27}
...@@ -29,15 +33,15 @@ export fn f5() void {...@@ -29,15 +33,15 @@ export fn f5() void {
29// :5:25: error: value of type 'usize' ignored33// :5:25: error: value of type 'usize' ignored
30// :5:25: note: all non-void values must be used34// :5:25: note: all non-void values must be used
31// :5:25: note: this error can be suppressed by assigning the value to '_'35// :5:25: note: this error can be suppressed by assigning the value to '_'
32// :9:26: error: value of type 'usize' ignored36// :10:26: error: value of type 'usize' ignored
33// :9:26: note: all non-void values must be used37// :10:26: note: all non-void values must be used
34// :9:26: note: this error can be suppressed by assigning the value to '_'38// :10:26: note: this error can be suppressed by assigning the value to '_'
35// :13:26: error: value of type 'usize' ignored39// :15:26: error: value of type 'usize' ignored
36// :13:26: note: all non-void values must be used40// :15:26: note: all non-void values must be used
37// :13:26: note: this error can be suppressed by assigning the value to '_'41// :15:26: note: this error can be suppressed by assigning the value to '_'
38// :17:23: error: value of type 'bool' ignored42// :20:23: error: value of type 'bool' ignored
39// :17:23: note: all non-void values must be used43// :20:23: note: all non-void values must be used
40// :17:23: note: this error can be suppressed by assigning the value to '_'44// :20:23: note: this error can be suppressed by assigning the value to '_'
41// :21:34: error: value of type 'usize' ignored45// :25:34: error: value of type 'usize' ignored
42// :21:34: note: all non-void values must be used46// :25:34: note: all non-void values must be used
43// :21:34: note: this error can be suppressed by assigning the value to '_'47// :25:34: note: this error can be suppressed by assigning the value to '_'
test/cases/compile_errors/while_loop_break_value_ignored.zig+4-2
...@@ -7,6 +7,7 @@ export fn f1() void {...@@ -7,6 +7,7 @@ export fn f1() void {
7 while (a) {7 while (a) {
8 break returns();8 break returns();
9 }9 }
10 _ = &a;
10}11}
1112
12export fn f2() void {13export fn f2() void {
...@@ -16,6 +17,7 @@ export fn f2() void {...@@ -16,6 +17,7 @@ export fn f2() void {
16 break :outer returns();17 break :outer returns();
17 }18 }
18 }19 }
20 _ = &x;
19}21}
2022
21// error23// error
...@@ -24,5 +26,5 @@ export fn f2() void {...@@ -24,5 +26,5 @@ export fn f2() void {
24//26//
25// :7:5: error: incompatible types: 'usize' and 'void'27// :7:5: error: incompatible types: 'usize' and 'void'
26// :8:22: note: type 'usize' here28// :8:22: note: type 'usize' here
27// :14:12: error: incompatible types: 'usize' and 'void'29// :15:12: error: incompatible types: 'usize' and 'void'
28// :16:33: note: type 'usize' here30// :17:33: note: type 'usize' here
test/cases/compile_errors/wrong_type_passed_to_panic.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1export fn entry() void {1export fn entry() void {
2 var e = error.Foo;2 const e = error.Foo;
3 @panic(e);3 @panic(e);
4}4}
55
test/cases/compile_log.0.zig+1-1
...@@ -4,7 +4,7 @@ export fn _start() noreturn {...@@ -4,7 +4,7 @@ export fn _start() noreturn {
4 @compileLog(b, 20, f, x);4 @compileLog(b, 20, f, x);
5 @compileLog(1000);5 @compileLog(1000);
6 var bruh: usize = true;6 var bruh: usize = true;
7 _ = bruh;7 _ = .{ &f, &bruh };
8 unreachable;8 unreachable;
9}9}
10export fn other() void {10export fn other() void {
test/cases/compile_log.1.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1export fn _start() noreturn {1export fn _start() noreturn {
2 const b = true;2 const b = true;
3 var f: u32 = 1;3 var f: u32 = 1;
4 _ = &f;
4 @compileLog(b, 20, f, x);5 @compileLog(b, 20, f, x);
5 @compileLog(1000);6 @compileLog(1000);
6 unreachable;7 unreachable;
test/cases/comptime_var.0.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var a: u32 = 0;2 var a: u32 = 0;
3 _ = &a;
3 comptime var b: u32 = 0;4 comptime var b: u32 = 0;
4 if (a == 0) b = 3;5 if (a == 0) b = 3;
5}6}
...@@ -9,5 +10,5 @@ pub fn main() void {...@@ -9,5 +10,5 @@ pub fn main() void {
9// target=x86_64-macos,x86_64-linux10// target=x86_64-macos,x86_64-linux
10// link_libc=true11// link_libc=true
11//12//
12// :4:19: error: store to comptime variable depends on runtime condition13// :5:19: error: store to comptime variable depends on runtime condition
13// :4:11: note: runtime condition here14// :5:11: note: runtime condition here
test/cases/comptime_var.1.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var a: u32 = 0;2 var a: u32 = 0;
3 _ = &a;
3 comptime var b: u32 = 0;4 comptime var b: u32 = 0;
4 switch (a) {5 switch (a) {
5 0 => {},6 0 => {},
test/cases/comptime_var.5.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var a: u32 = 0;2 var a: u32 = 0;
3 _ = &a;
3 if (a == 0) {4 if (a == 0) {
4 comptime var b: u32 = 0;5 comptime var b: u32 = 0;
5 b = 1;6 b = 1;
test/cases/conditions.5.zig+1
...@@ -10,6 +10,7 @@ fn assert(ok: bool) void {...@@ -10,6 +10,7 @@ fn assert(ok: bool) void {
10fn foo(ok: bool) i32 {10fn foo(ok: bool) i32 {
11 const val: i32 = blk: {11 const val: i32 = blk: {
12 var x: i32 = 1;12 var x: i32 = 1;
13 _ = &x;
13 if (!ok) break :blk x + @as(i32, 9);14 if (!ok) break :blk x + @as(i32, 9);
14 break :blk x + @as(i32, 19);15 break :blk x + @as(i32, 19);
15 };16 };
test/cases/decl_value_arena.zig+1-1
...@@ -14,7 +14,7 @@ pub const Connection = struct {...@@ -14,7 +14,7 @@ pub const Connection = struct {
1414
15pub fn main() void {15pub fn main() void {
16 var conn: Connection = undefined;16 var conn: Connection = undefined;
17 _ = conn;17 _ = &conn;
18}18}
1919
20// run20// run
test/cases/enum_values.0.zig+2-2
...@@ -4,8 +4,8 @@ pub fn main() void {...@@ -4,8 +4,8 @@ pub fn main() void {
4 var number1 = Number.One;4 var number1 = Number.One;
5 var number2: Number = .Two;5 var number2: Number = .Two;
6 if (false) {6 if (false) {
7 number1;7 &number1;
8 number2;8 &number2;
9 }9 }
10 const number3: Number = @enumFromInt(2);10 const number3: Number = @enumFromInt(2);
11 if (@intFromEnum(number3) != 2) {11 if (@intFromEnum(number3) != 2) {
test/cases/enum_values.1.zig+3
...@@ -2,7 +2,9 @@ const Number = enum { One, Two, Three };...@@ -2,7 +2,9 @@ const Number = enum { One, Two, Three };
22
3pub fn main() void {3pub fn main() void {
4 var number1 = Number.One;4 var number1 = Number.One;
5 _ = &number1;
5 var number2: Number = .Two;6 var number2: Number = .Two;
7 _ = &number2;
6 const number3: Number = @enumFromInt(2);8 const number3: Number = @enumFromInt(2);
7 assert(number1 != number2);9 assert(number1 != number2);
8 assert(number2 != number3);10 assert(number2 != number3);
...@@ -10,6 +12,7 @@ pub fn main() void {...@@ -10,6 +12,7 @@ pub fn main() void {
10 assert(@intFromEnum(number2) == 1);12 assert(@intFromEnum(number2) == 1);
11 assert(@intFromEnum(number3) == 2);13 assert(@intFromEnum(number3) == 2);
12 var x: Number = .Two;14 var x: Number = .Two;
15 _ = &x;
13 assert(number2 == x);16 assert(number2 == x);
1417
15 return;18 return;
test/cases/error_in_nested_declaration.zig+1-1
...@@ -19,7 +19,7 @@ const S2 = struct {...@@ -19,7 +19,7 @@ const S2 = struct {
1919
20pub export fn entry2() void {20pub export fn entry2() void {
21 var s: S2 = undefined;21 var s: S2 = undefined;
22 _ = s;22 _ = &s;
23}23}
2424
25// error25// error
test/cases/error_unions.0.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1pub fn main() void {1pub fn main() void {
2 var e1 = error.Foo;2 var e1 = error.Foo;
3 var e2 = error.Bar;3 var e2 = error.Bar;
4 _ = .{ &e1, &e2 };
4 assert(e1 != e2);5 assert(e1 != e2);
5 assert(e1 == error.Foo);6 assert(e1 == error.Foo);
6 assert(e2 == error.Bar);7 assert(e2 == error.Bar);
test/cases/error_unions.1.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var e: anyerror!u8 = 5;2 var e: anyerror!u8 = 5;
3 _ = &e;
3 const i = e catch 10;4 const i = e catch 10;
4 return i - 5;5 return i - 5;
5}6}
test/cases/error_unions.2.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var e: anyerror!u8 = error.Foo;2 var e: anyerror!u8 = error.Foo;
3 _ = &e;
3 const i = e catch 10;4 const i = e catch 10;
4 return i - 10;5 return i - 10;
5}6}
test/cases/error_unions.3.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var e = foo();2 var e = foo();
3 _ = &e;
3 const i = e catch 69;4 const i = e catch 69;
4 return i - 5;5 return i - 5;
5}6}
test/cases/error_unions.4.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var e = foo();2 var e = foo();
3 _ = &e;
3 const i = e catch 69;4 const i = e catch 69;
4 return i - 69;5 return i - 69;
5}6}
test/cases/error_unions.5.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var e = foo();2 var e = foo();
3 _ = &e;
3 const i = e catch 42;4 const i = e catch 42;
4 return i - 42;5 return i - 42;
5}6}
test/cases/f32_passed_to_variadic_fn.zig+2-2
...@@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int;...@@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int;
2pub fn main() void {2pub fn main() void {
3 var a: f64 = 2.0;3 var a: f64 = 2.0;
4 var b: f32 = 10.0;4 var b: f32 = 10.0;
5 _ = printf("f64: %f\n", a);5 _ = printf("f64: %f\n", (&a).*);
6 _ = printf("f32: %f\n", b);6 _ = printf("f32: %f\n", (&b).*);
7}7}
88
9// run9// run
test/cases/inner_func_accessing_outer_var.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn f() void {1pub fn f() void {
2 var bar: bool = true;2 var bar: bool = true;
3 _ = &bar;
3 const S = struct {4 const S = struct {
4 fn baz() bool {5 fn baz() bool {
5 return bar;6 return bar;
...@@ -10,6 +11,6 @@ pub fn f() void {...@@ -10,6 +11,6 @@ pub fn f() void {
1011
11// error12// error
12//13//
13// :5:20: error: mutable 'bar' not accessible from here14// :6:20: error: mutable 'bar' not accessible from here
14// :2:9: note: declared mutable here15// :2:9: note: declared mutable here
15// :3:15: note: crosses namespace boundary here16// :4:15: note: crosses namespace boundary here
test/cases/llvm/blocks.zig+1
...@@ -5,6 +5,7 @@ fn assert(ok: bool) void {...@@ -5,6 +5,7 @@ fn assert(ok: bool) void {
5fn foo(ok: bool) i32 {5fn foo(ok: bool) i32 {
6 const val: i32 = blk: {6 const val: i32 = blk: {
7 var x: i32 = 1;7 var x: i32 = 1;
8 _ = &x;
8 if (!ok) break :blk x + 9;9 if (!ok) break :blk x + 9;
9 break :blk x + 19;10 break :blk x + 19;
10 };11 };
test/cases/llvm/f_segment_address_space_reading_and_writing.zig+1
...@@ -35,6 +35,7 @@ pub fn main() void {...@@ -35,6 +35,7 @@ pub fn main() void {
35 assert(getFs() == @intFromPtr(&test_value));35 assert(getFs() == @intFromPtr(&test_value));
3636
37 var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);37 var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);
38 _ = &test_ptr;
38 assert(test_ptr.* == 12345);39 assert(test_ptr.* == 12345);
39 test_ptr.* = 98765;40 test_ptr.* = 98765;
40 assert(test_value == 98765);41 assert(test_value == 98765);
test/cases/llvm/nested_blocks.zig+1-1
...@@ -10,7 +10,7 @@ fn foo(ok: bool) i32 {...@@ -10,7 +10,7 @@ fn foo(ok: bool) i32 {
10 };10 };
11 break :blk val2 + 10;11 break :blk val2 + 10;
12 };12 };
13 return val;13 return (&val).*;
14}14}
1515
16pub fn main() void {16pub fn main() void {
test/cases/llvm/optionals.zig+4
...@@ -7,8 +7,10 @@ pub fn main() void {...@@ -7,8 +7,10 @@ pub fn main() void {
7 var null_val: ?i32 = null;7 var null_val: ?i32 = null;
88
9 var val1: i32 = opt_val.?;9 var val1: i32 = opt_val.?;
10 _ = &val1;
10 const val1_1: i32 = opt_val.?;11 const val1_1: i32 = opt_val.?;
11 var ptr_val1 = &(opt_val.?);12 var ptr_val1 = &(opt_val.?);
13 _ = &ptr_val1;
12 const ptr_val1_1 = &(opt_val.?);14 const ptr_val1_1 = &(opt_val.?);
1315
14 var val2: i32 = null_val orelse 20;16 var val2: i32 = null_val orelse 20;
...@@ -16,9 +18,11 @@ pub fn main() void {...@@ -16,9 +18,11 @@ pub fn main() void {
1618
17 var value: i32 = 20;19 var value: i32 = 20;
18 var ptr_val2 = &(null_val orelse value);20 var ptr_val2 = &(null_val orelse value);
21 _ = &ptr_val2;
1922
20 const val3 = opt_val orelse 30;23 const val3 = opt_val orelse 30;
21 var val3_var = opt_val orelse 30;24 var val3_var = opt_val orelse 30;
25 _ = &val3_var;
2226
23 assert(val1 == 10);27 assert(val1 == 10);
24 assert(val1_1 == 10);28 assert(val1_1 == 10);
test/cases/llvm/simple_addition_and_subtraction.zig+1
...@@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 {...@@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 {
44
5pub fn main() void {5pub fn main() void {
6 var a: i32 = -5;6 var a: i32 = -5;
7 _ = &a;
7 const x = add(a, 7);8 const x = add(a, 7);
8 var y = add(2, 0);9 var y = add(2, 0);
9 y -= x;10 y -= x;
test/cases/locals.0.zig+2-2
...@@ -3,8 +3,8 @@ pub fn main() void {...@@ -3,8 +3,8 @@ pub fn main() void {
3 var y: f32 = 42.0;3 var y: f32 = 42.0;
4 var x: u8 = 10;4 var x: u8 = 10;
5 if (false) {5 if (false) {
6 y;6 &y;
7 x;7 &x / &i;
8 }8 }
9 if (i != 5) unreachable;9 if (i != 5) unreachable;
10}10}
test/cases/locals.1.zig+2-1
...@@ -1,8 +1,9 @@...@@ -1,8 +1,9 @@
1pub fn main() void {1pub fn main() void {
2 var i: u8 = 5;2 var i: u8 = 5;
3 var y: f32 = 42.0;3 var y: f32 = 42.0;
4 _ = y;4 _ = &y;
5 var x: u8 = 10;5 var x: u8 = 10;
6 _ = &x;
6 foo(i, x);7 foo(i, x);
7 i = x;8 i = x;
8 if (i != 10) unreachable;9 if (i != 10) unreachable;
test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var x: usize = 5;2 var x: usize = 5;
3 _ = &x;
3 const y = mul(2, 3, x);4 const y = mul(2, 3, x);
4 if (y - 30 != 0) unreachable;5 if (y - 30 != 0) unreachable;
5}6}
test/cases/only_1_function_and_it_gets_updated.1.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1pub export fn _start() noreturn {1pub export fn _start() noreturn {
2 var dummy: u32 = 10;2 var dummy: u32 = 10;
3 _ = dummy;3 _ = &dummy;
4 while (true) {}4 while (true) {}
5}5}
66
test/cases/optionals.0.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var x: ?u8 = 5;2 var x: ?u8 = 5;
3 _ = &x;
3 var y: u8 = 0;4 var y: u8 = 0;
4 if (x) |val| {5 if (x) |val| {
5 y = val;6 y = val;
test/cases/optionals.1.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var x: ?u8 = null;2 var x: ?u8 = null;
3 _ = &x;
3 var y: u8 = 0;4 var y: u8 = 0;
4 if (x) |val| {5 if (x) |val| {
5 y = val;6 y = val;
test/cases/optionals.2.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var x: ?u8 = 5;2 var x: ?u8 = 5;
3 _ = &x;
3 return x.? - 5;4 return x.? - 5;
4}5}
56
test/cases/optionals.3.zig+1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var x: u8 = 5;2 var x: u8 = 5;
3 var y: ?u8 = x;3 var y: ?u8 = x;
4 _ = .{ &x, &y };
4 return y.? - 5;5 return y.? - 5;
5}6}
67
test/cases/runtime_bitwise_and.zig+1
...@@ -7,6 +7,7 @@ pub fn main() void {...@@ -7,6 +7,7 @@ pub fn main() void {
7 var m2: u32 = 0b0000;7 var m2: u32 = 0b0000;
8 assert(m1 & 0b1010 == 0b1010);8 assert(m1 & 0b1010 == 0b1010);
9 assert(m2 & 0b1010 == 0b0000);9 assert(m2 & 0b1010 == 0b0000);
10 _ = .{ &i, &j, &m1, &m2 };
10}11}
11fn assert(b: bool) void {12fn assert(b: bool) void {
12 if (!b) unreachable;13 if (!b) unreachable;
test/cases/runtime_bitwise_or.zig+1
...@@ -7,6 +7,7 @@ pub fn main() void {...@@ -7,6 +7,7 @@ pub fn main() void {
7 var m2: u32 = 0b0000;7 var m2: u32 = 0b0000;
8 assert(m1 | 0b1010 == 0b1111);8 assert(m1 | 0b1010 == 0b1111);
9 assert(m2 | 0b1010 == 0b1010);9 assert(m2 | 0b1010 == 0b1010);
10 _ = .{ &i, &j, &m1, &m2 };
10}11}
11fn assert(b: bool) void {12fn assert(b: bool) void {
12 if (!b) unreachable;13 if (!b) unreachable;
test/cases/safety/@asyncCall with too small a frame.zig +2-1
...@@ -13,8 +13,9 @@ pub fn main() !void {...@@ -13,8 +13,9 @@ pub fn main() !void {
13 }13 }
14 var bytes: [1]u8 align(16) = undefined;14 var bytes: [1]u8 align(16) = undefined;
15 var ptr = other;15 var ptr = other;
16 _ = &ptr;
16 var frame = @asyncCall(&bytes, {}, ptr, .{});17 var frame = @asyncCall(&bytes, {}, ptr, .{});
17 _ = frame;18 _ = &frame;
18 return error.TestFailed;19 return error.TestFailed;
19}20}
20fn other() callconv(.Async) void {21fn other() callconv(.Async) void {
test/cases/safety/@intCast to u0.zig +1-1
...@@ -14,7 +14,7 @@ pub fn main() !void {...@@ -14,7 +14,7 @@ pub fn main() !void {
14}14}
1515
16fn bar(one: u1, not_zero: i32) void {16fn bar(one: u1, not_zero: i32) void {
17 var x = one << @as(u0, @intCast(not_zero));17 const x = one << @intCast(not_zero);
18 _ = x;18 _ = x;
19}19}
20// run20// run
test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var zero: usize = 0;11 var zero: usize = 0;
12 var b: *u8 = @ptrFromInt(zero);12 _ = &zero;
13 const b: *u8 = @ptrFromInt(zero);
13 _ = b;14 _ = b;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var zero: usize = 0;11 var zero: usize = 0;
12 var b: *i32 = @ptrFromInt(zero);12 _ = &zero;
13 const b: *i32 = @ptrFromInt(zero);
13 _ = b;14 _ = b;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/@ptrFromInt with misaligned address.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var x: usize = 5;11 var x: usize = 5;
12 var y: [*]align(4) u8 = @ptrFromInt(x);12 _ = &x;
13 const y: [*]align(4) u8 = @ptrFromInt(x);
13 _ = y;14 _ = y;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/@tagName on corrupted enum value.zig +1-1
...@@ -16,7 +16,7 @@ const E = enum(u32) {...@@ -16,7 +16,7 @@ const E = enum(u32) {
16pub fn main() !void {16pub fn main() !void {
17 var e: E = undefined;17 var e: E = undefined;
18 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);18 @memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
19 var n = @tagName(e);19 const n = @tagName(e);
20 _ = n;20 _ = n;
21 return error.TestFailed;21 return error.TestFailed;
22}22}
test/cases/safety/@tagName on corrupted union value.zig +2-2
...@@ -16,8 +16,8 @@ const U = union(enum(u32)) {...@@ -16,8 +16,8 @@ const U = union(enum(u32)) {
16pub fn main() !void {16pub fn main() !void {
17 var u: U = undefined;17 var u: U = undefined;
18 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);18 @memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
19 var t: @typeInfo(U).Union.tag_type.? = u;19 const t: @typeInfo(U).Union.tag_type.? = u;
20 var n = @tagName(t);20 const n = @tagName(t);
21 _ = n;21 _ = n;
22 return error.TestFailed;22 return error.TestFailed;
23}23}
test/cases/safety/array slice sentinel mismatch non-scalar.zig +1-1
...@@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
11pub fn main() !void {11pub fn main() !void {
12 const S = struct { a: u32 };12 const S = struct { a: u32 };
13 var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } };13 var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } };
14 var s = arr[0..1 :.{ .a = 1 }];14 const s = arr[0..1 :.{ .a = 1 }];
15 _ = s;15 _ = s;
16 return error.TestFailed;16 return error.TestFailed;
17}17}
test/cases/safety/exact division failure - vectors.zig +2-2
...@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
1010
11pub fn main() !void {11pub fn main() !void {
12 var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };12 const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
13 var b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 };13 const b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 };
14 const x = divExact(a, b);14 const x = divExact(a, b);
15 _ = x;15 _ = x;
16 return error.TestFailed;16 return error.TestFailed;
test/cases/safety/for_len_mismatch.zig+1
...@@ -12,6 +12,7 @@ pub fn main() !void {...@@ -12,6 +12,7 @@ pub fn main() !void {
12 var runtime_i: usize = 1;12 var runtime_i: usize = 1;
13 var j: usize = 3;13 var j: usize = 3;
14 var slice = "too long";14 var slice = "too long";
15 _ = .{ &runtime_i, &j, &slice };
15 for (runtime_i..j, slice) |a, b| {16 for (runtime_i..j, slice) |a, b| {
16 _ = a;17 _ = a;
17 _ = b;18 _ = b;
test/cases/safety/for_len_mismatch_three.zig+1
...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var slice: []const u8 = "hello";12 var slice: []const u8 = "hello";
13 _ = &slice;
13 for (10..20, slice, 20..30) |a, b, c| {14 for (10..20, slice, 20..30) |a, b, c| {
14 _ = a;15 _ = a;
15 _ = b;16 _ = b;
test/cases/safety/integer division by zero - vectors.zig +2-2
...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
8 std.process.exit(1);8 std.process.exit(1);
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };11 const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
12 var b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 };12 const b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 };
13 const x = div0(a, b);13 const x = div0(a, b);
14 _ = x;14 _ = x;
15 return error.TestFailed;15 return error.TestFailed;
test/cases/safety/memcpy_alias.zig+1
...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
10pub fn main() !void {10pub fn main() !void {
11 var buffer = [2]u8{ 1, 2 } ** 5;11 var buffer = [2]u8{ 1, 2 } ** 5;
12 var len: usize = 5;12 var len: usize = 5;
13 _ = &len;
13 @memcpy(buffer[0..len], buffer[4 .. 4 + len]);14 @memcpy(buffer[0..len], buffer[4 .. 4 + len]);
14}15}
15// run16// run
test/cases/safety/memcpy_len_mismatch.zig+1
...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
10pub fn main() !void {10pub fn main() !void {
11 var buffer = [2]u8{ 1, 2 } ** 5;11 var buffer = [2]u8{ 1, 2 } ** 5;
12 var len: usize = 5;12 var len: usize = 5;
13 _ = &len;
13 @memcpy(buffer[0..len], buffer[len .. len + 4]);14 @memcpy(buffer[0..len], buffer[len .. len + 4]);
14}15}
15// run16// run
test/cases/safety/memset_slice_undefined_bytes.zig+1
...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
10pub fn main() !void {10pub fn main() !void {
11 var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 };11 var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 };
12 var len = buffer.len;12 var len = buffer.len;
13 _ = &len;
13 @memset(buffer[0..len], undefined);14 @memset(buffer[0..len], undefined);
14 var x: u8 = buffer[1];15 var x: u8 = buffer[1];
15 x += buffer[2];16 x += buffer[2];
test/cases/safety/memset_slice_undefined_large.zig+1
...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
10pub fn main() !void {10pub fn main() !void {
11 var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 };11 var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 };
12 var len = buffer.len;12 var len = buffer.len;
13 _ = &len;
13 @memset(buffer[0..len], undefined);14 @memset(buffer[0..len], undefined);
14 var x: i32 = buffer[1];15 var x: i32 = buffer[1];
15 x += buffer[2];16 x += buffer[2];
test/cases/safety/optional unwrap operator on C pointer.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var ptr: [*c]i32 = null;11 var ptr: [*c]i32 = null;
12 var b = ptr.?;12 _ = &ptr;
13 const b = ptr.?;
13 _ = b;14 _ = b;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/optional unwrap operator on null pointer.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var ptr: ?*i32 = null;11 var ptr: ?*i32 = null;
12 var b = ptr.?;12 _ = &ptr;
13 const b = ptr.?;
13 _ = b;14 _ = b;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/pointer casting null to non-optional pointer.zig +2-1
...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var c_ptr: [*c]u8 = 0;12 var c_ptr: [*c]u8 = 0;
13 var zig_ptr: *u8 = c_ptr;13 _ = &c_ptr;
14 const zig_ptr: *u8 = c_ptr;
14 _ = zig_ptr;15 _ = zig_ptr;
15 return error.TestFailed;16 return error.TestFailed;
16}17}
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig +1-1
...@@ -10,7 +10,7 @@ fn foo() void {...@@ -10,7 +10,7 @@ fn foo() void {
10 global_frame = @frame();10 global_frame = @frame();
11 }11 }
12 var f = async bar(@frame());12 var f = async bar(@frame());
13 _ = f;13 _ = &f;
14 std.os.exit(1);14 std.os.exit(1);
15}15}
1616
test/cases/safety/resuming a non-suspended function which never been suspended.zig +1-1
...@@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
7}7}
8fn foo() void {8fn foo() void {
9 var f = async bar(@frame());9 var f = async bar(@frame());
10 _ = f;10 _ = &f;
11 std.os.exit(1);11 std.os.exit(1);
12}12}
1313
test/cases/safety/shift left by huge amount.zig +2-1
...@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
11pub fn main() !void {11pub fn main() !void {
12 var x: u24 = 42;12 var x: u24 = 42;
13 var y: u5 = 24;13 var y: u5 = 24;
14 var z = x >> y;14 _ = .{ &x, &y };
15 const z = x >> y;
15 _ = z;16 _ = z;
16 return error.TestFailed;17 return error.TestFailed;
17}18}
test/cases/safety/shift right by huge amount.zig +2-1
...@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
11pub fn main() !void {11pub fn main() !void {
12 var x: u24 = 42;12 var x: u24 = 42;
13 var y: u5 = 24;13 var y: u5 = 24;
14 var z = x << y;14 _ = .{ &x, &y };
15 const z = x << y;
15 _ = z;16 _ = z;
16 return error.TestFailed;17 return error.TestFailed;
17}18}
test/cases/safety/signed integer division overflow - vectors.zig +2-2
...@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
1010
11pub fn main() !void {11pub fn main() !void {
12 var a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };12 const a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
13 var b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };13 const b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
14 const x = div(a, b);14 const x = div(a, b);
15 if (x[2] == 32767) return error.Whatever;15 if (x[2] == 32767) return error.Whatever;
16 return error.TestFailed;16 return error.TestFailed;
test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var value: c_short = -1;11 var value: c_short = -1;
12 var casted: u32 = @intCast(value);12 _ = &value;
13 const casted: u32 = @intCast(value);
13 _ = casted;14 _ = casted;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/signed-unsigned vector cast.zig +2-1
...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var x: @Vector(4, i32) = @splat(-2147483647);12 var x: @Vector(4, i32) = @splat(-2147483647);
13 var y: @Vector(4, u32) = @intCast(x);13 _ = &x;
14 const y: @Vector(4, u32) = @intCast(x);
14 _ = y;15 _ = y;
15 return error.TestFailed;16 return error.TestFailed;
16}17}
test/cases/safety/slice start index greater than end index.zig +1
...@@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
11pub fn main() !void {11pub fn main() !void {
12 var a: usize = 1;12 var a: usize = 1;
13 var b: usize = 10;13 var b: usize = 10;
14 _ = .{ &a, &b };
14 var buf: [16]u8 = undefined;15 var buf: [16]u8 = undefined;
1516
16 const slice = buf[b..a];17 const slice = buf[b..a];
test/cases/safety/slice with sentinel out of bounds - runtime len.zig +1
...@@ -12,6 +12,7 @@ pub fn main() !void {...@@ -12,6 +12,7 @@ pub fn main() !void {
12 var buf = [4]u8{ 'a', 'b', 'c', 0 };12 var buf = [4]u8{ 'a', 'b', 'c', 0 };
13 const input: []u8 = &buf;13 const input: []u8 = &buf;
14 var len: usize = 4;14 var len: usize = 4;
15 _ = &len;
15 const slice = input[0..len :0];16 const slice = input[0..len :0];
16 _ = slice;17 _ = slice;
17 return error.TestFailed;18 return error.TestFailed;
test/cases/safety/slicing null C pointer - runtime len.zig +2-1
...@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
11pub fn main() !void {11pub fn main() !void {
12 var ptr: [*c]const u32 = null;12 var ptr: [*c]const u32 = null;
13 var len: usize = 3;13 var len: usize = 3;
14 var slice = ptr[0..len];14 _ = &len;
15 const slice = ptr[0..len];
15 _ = slice;16 _ = slice;
16 return error.TestFailed;17 return error.TestFailed;
17}18}
test/cases/safety/slicing null C pointer.zig +2-1
...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var ptr: [*c]const u32 = null;12 var ptr: [*c]const u32 = null;
13 var slice = ptr[0..3];13 _ = &ptr;
14 const slice = ptr[0..3];
14 _ = slice;15 _ = slice;
15 return error.TestFailed;16 return error.TestFailed;
16}17}
test/cases/safety/truncating vector cast.zig +2-1
...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var x: @Vector(4, u32) = @splat(0xdeadbeef);12 var x: @Vector(4, u32) = @splat(0xdeadbeef);
13 var y: @Vector(4, u16) = @intCast(x);13 _ = &x;
14 const y: @Vector(4, u16) = @intCast(x);
14 _ = y;15 _ = y;
15 return error.TestFailed;16 return error.TestFailed;
16}17}
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +2-1
...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var value: u8 = 245;11 var value: u8 = 245;
12 var casted: i8 = @intCast(value);12 _ = &value;
13 const casted: i8 = @intCast(value);
13 _ = casted;14 _ = casted;
14 return error.TestFailed;15 return error.TestFailed;
15}16}
test/cases/safety/unsigned-signed vector cast.zig +2-1
...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
1010
11pub fn main() !void {11pub fn main() !void {
12 var x: @Vector(4, u32) = @splat(0x80000000);12 var x: @Vector(4, u32) = @splat(0x80000000);
13 var y: @Vector(4, i32) = @intCast(x);13 _ = &x;
14 const y: @Vector(4, i32) = @intCast(x);
14 _ = y;15 _ = y;
15 return error.TestFailed;16 return error.TestFailed;
16}17}
test/cases/safety/vector integer addition overflow.zig +2-2
...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
8 std.process.exit(1);8 std.process.exit(1);
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };11 const a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
12 var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };12 const b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
13 const x = add(a, b);13 const x = add(a, b);
14 _ = x;14 _ = x;
15 return error.TestFailed;15 return error.TestFailed;
test/cases/safety/vector integer multiplication overflow.zig +2-2
...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
8 std.process.exit(1);8 std.process.exit(1);
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };11 const a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
12 var b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };12 const b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
13 const x = mul(b, a);13 const x = mul(b, a);
14 _ = x;14 _ = x;
15 return error.TestFailed;15 return error.TestFailed;
test/cases/safety/vector integer negation overflow.zig +1
...@@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };11 var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
12 _ = &a;
12 const x = neg(a);13 const x = neg(a);
13 _ = x;14 _ = x;
14 return error.TestFailed;15 return error.TestFailed;
test/cases/safety/vector integer subtraction overflow.zig +2-2
...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi...@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
8 std.process.exit(1);8 std.process.exit(1);
9}9}
10pub fn main() !void {10pub fn main() !void {
11 var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };11 const a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
12 var b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };12 const b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
13 const x = sub(b, a);13 const x = sub(b, a);
14 _ = x;14 _ = x;
15 return error.TestFailed;15 return error.TestFailed;
test/cases/structs.0.zig+1
...@@ -2,6 +2,7 @@ const Example = struct { x: u8 };...@@ -2,6 +2,7 @@ const Example = struct { x: u8 };
22
3pub fn main() u8 {3pub fn main() u8 {
4 var example: Example = .{ .x = 5 };4 var example: Example = .{ .x = 5 };
5 _ = &example;
5 return example.x - 5;6 return example.x - 5;
6}7}
78
test/cases/structs.2.zig+1
...@@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 };...@@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 };
22
3pub fn main() u8 {3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };4 var example: Example = .{ .x = 5, .y = 10 };
5 _ = &example;
5 return example.y + example.x - 15;6 return example.y + example.x - 15;
6}7}
78
test/cases/structs.3.zig+1
...@@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 };...@@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 };
3pub fn main() u8 {3pub fn main() u8 {
4 var example: Example = .{ .x = 5, .y = 10 };4 var example: Example = .{ .x = 5, .y = 10 };
5 var example2: Example = .{ .x = 10, .y = 20 };5 var example2: Example = .{ .x = 10, .y = 20 };
6 _ = &example2;
67
7 example = example2;8 example = example2;
8 return example.y + example.x - 30;9 return example.y + example.x - 30;
test/cases/switch.0.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var val: u8 = 1;2 var val: u8 = 1;
3 var a: u8 = switch (val) {3 _ = &val;
4 const a: u8 = switch (val) {
4 0, 1 => 2,5 0, 1 => 2,
5 2 => 3,6 2 => 3,
6 3 => 4,7 3 => 4,
test/cases/switch.1.zig+2
...@@ -1,11 +1,13 @@...@@ -1,11 +1,13 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var val: u8 = 2;2 var val: u8 = 2;
3 _ = &val;
3 var a: u8 = switch (val) {4 var a: u8 = switch (val) {
4 0, 1 => 2,5 0, 1 => 2,
5 2 => 3,6 2 => 3,
6 3 => 4,7 3 => 4,
7 else => 5,8 else => 5,
8 };9 };
10 _ = &a;
911
10 return a - 3;12 return a - 3;
11}13}
test/cases/switch.2.zig+2-1
...@@ -1,6 +1,7 @@...@@ -1,6 +1,7 @@
1pub fn main() u8 {1pub fn main() u8 {
2 var val: u8 = 10;2 var val: u8 = 10;
3 var a: u8 = switch (val) {3 _ = &val;
4 const a: u8 = switch (val) {
4 0, 1 => 2,5 0, 1 => 2,
5 2 => 3,6 2 => 3,
6 3 => 4,7 3 => 4,
test/cases/switch.3.zig+2-1
...@@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three };...@@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three };
22
3pub fn main() u8 {3pub fn main() u8 {
4 var val: MyEnum = .Two;4 var val: MyEnum = .Two;
5 var a: u8 = switch (val) {5 _ = &val;
6 const a: u8 = switch (val) {
6 .One => 1,7 .One => 1,
7 .Two => 2,8 .Two => 2,
8 .Three => 3,9 .Three => 3,
test/cases/type_of.0.zig+1
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1pub fn main() void {1pub fn main() void {
2 var x: usize = 0;2 var x: usize = 0;
3 _ = &x;
3 const z = @TypeOf(x, @as(u128, 5));4 const z = @TypeOf(x, @as(u128, 5));
4 assert(z == u128);5 assert(z == u128);
5}6}
test/cases/while_loops.1.zig+1
...@@ -2,6 +2,7 @@ pub fn main() u8 {...@@ -2,6 +2,7 @@ pub fn main() u8 {
2 var i: u8 = 0;2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;4 var x: u8 = 1;
5 _ = &x;
5 i += x;6 i += x;
6 }7 }
7 return i - 10;8 return i - 10;
test/cases/while_loops.2.zig+1
...@@ -2,6 +2,7 @@ pub fn main() u8 {...@@ -2,6 +2,7 @@ pub fn main() u8 {
2 var i: u8 = 0;2 var i: u8 = 0;
3 while (i < @as(u8, 10)) {3 while (i < @as(u8, 10)) {
4 var x: u8 = 1;4 var x: u8 = 1;
5 _ = &x;
5 i += x;6 i += x;
6 if (i == @as(u8, 5)) break;7 if (i == @as(u8, 5)) break;
7 }8 }