Commit 21fa187abc
Changed files (289)
test
cases
compile_errors
async
llvm
safety
test/cases/compile_errors/async/async_function_depends_on_its_own_frame.zig
@@ -3,7 +3,7 @@ export fn entry() void {
}
fn amain() callconv(.Async) void {
var x: [@sizeOf(@Frame(amain))]u8 = undefined;
- _ = x;
+ _ = &x;
}
// error
test/cases/compile_errors/async/async_function_indirectly_depends_on_its_own_frame.zig
@@ -6,7 +6,7 @@ fn amain() callconv(.Async) void {
}
fn other() void {
var x: [@sizeOf(@Frame(amain))]u8 = undefined;
- _ = x;
+ _ = &x;
}
// error
test/cases/compile_errors/async/bad_alignment_in_asynccall.zig
@@ -2,6 +2,7 @@ export fn entry() void {
var ptr: fn () callconv(.Async) void = func;
var bytes: [64]u8 = undefined;
_ = @asyncCall(&bytes, {}, ptr, .{});
+ _ = &ptr;
}
fn func() callconv(.Async) void {}
test/cases/compile_errors/async/const_frame_cast_to_anyframe.zig
@@ -5,7 +5,7 @@ export fn a() void {
export fn b() void {
const f = async func();
var x: anyframe = &f;
- _ = x;
+ _ = &x;
}
fn func() void {
suspend {}
test/cases/compile_errors/async/Frame_of_generic_function.zig
@@ -1,10 +1,10 @@
export fn entry() void {
var frame: @Frame(func) = undefined;
- _ = frame;
+ _ = &frame;
}
fn func(comptime T: type) void {
var x: T = undefined;
- _ = x;
+ _ = &x;
}
// error
test/cases/compile_errors/async/indirect_recursion_of_async_functions_detected.zig
@@ -12,7 +12,7 @@ fn rangeSum(x: i32) i32 {
frame = null;
if (x == 0) return 0;
- var child = rangeSumIndirect(x - 1);
+ const child = rangeSumIndirect(x - 1);
return child + 1;
}
@@ -23,7 +23,7 @@ fn rangeSumIndirect(x: i32) i32 {
frame = null;
if (x == 0) return 0;
- var child = rangeSum(x - 1);
+ const child = rangeSum(x - 1);
return child + 1;
}
@@ -32,5 +32,5 @@ fn rangeSumIndirect(x: i32) i32 {
// target=native
//
// tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself
-// tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here
-// tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
+// tmp.zig:15:35: note: when analyzing type '@Frame(rangeSum)' here
+// tmp.zig:28:25: note: when analyzing type '@Frame(rangeSumIndirect)' here
test/cases/compile_errors/async/invalid_suspend_in_exported_function.zig
@@ -1,7 +1,7 @@
export fn entry() void {
var frame = async func();
var result = await frame;
- _ = result;
+ _ = &result;
}
fn func() void {
suspend {}
test/cases/compile_errors/async/non_async_function_pointer_passed_to_asyncCall.zig
@@ -2,6 +2,7 @@ export fn entry() void {
var ptr = afunc;
var bytes: [100]u8 align(16) = undefined;
_ = @asyncCall(&bytes, {}, ptr, .{});
+ _ = &ptr;
}
fn afunc() void {}
test/cases/compile_errors/async/prevent_bad_implicit_casting_of_anyframe_types.zig
@@ -1,17 +1,17 @@
export fn a() void {
var x: anyframe = undefined;
var y: anyframe->i32 = x;
- _ = y;
+ _ = .{ &x, &y };
}
export fn b() void {
var x: i32 = undefined;
var y: anyframe->i32 = x;
- _ = y;
+ _ = .{ &x, &y };
}
export fn c() void {
var x: @Frame(func) = undefined;
var y: anyframe->i32 = &x;
- _ = y;
+ _ = .{ &x, &y };
}
fn func() void {}
test/cases/compile_errors/async/runtime-known_async_function_called.zig
@@ -4,6 +4,7 @@ export fn entry() void {
fn amain() void {
var ptr = afunc;
_ = ptr();
+ _ = &ptr;
}
fn afunc() callconv(.Async) void {}
test/cases/compile_errors/async/runtime-known_function_called_with_async_keyword.zig
@@ -1,6 +1,7 @@
export fn entry() void {
var ptr = afunc;
_ = async ptr();
+ _ = &ptr;
}
fn afunc() callconv(.Async) void {}
test/cases/compile_errors/stage1/obj/variable_in_inline_assembly_template_cannot_be_found.zig
@@ -2,7 +2,7 @@ export fn entry() void {
var sp = asm volatile ("mov %[foo], sp"
: [bar] "=r" (-> usize),
);
- _ = sp;
+ _ = &sp;
}
// error
test/cases/compile_errors/accessing_runtime_parameter_from_outer_function.zig
@@ -7,8 +7,8 @@ fn outer(y: u32) *const fn (u32) u32 {
return st.get;
}
export fn entry() void {
- var func = outer(10);
- var x = func(3);
+ const func = outer(10);
+ const x = func(3);
_ = x;
}
test/cases/compile_errors/add_on_undefined_value.zig
@@ -1,5 +1,5 @@
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
_ = a + a;
}
test/cases/compile_errors/alignment_of_enum_field_specified.zig
@@ -6,7 +6,7 @@ const Number = enum {
// zig fmt: on
export fn entry1() void {
- var x: Number = undefined;
+ const x: Number = undefined;
_ = x;
}
test/cases/compile_errors/ambiguous_coercion_of_division_operands.zig
@@ -1,17 +1,17 @@
export fn entry1() void {
- var f: f32 = 54.0 / 5;
+ const f: f32 = 54.0 / 5;
_ = f;
}
export fn entry2() void {
- var f: f32 = 54 / 5.0;
+ const f: f32 = 54 / 5.0;
_ = f;
}
export fn entry3() void {
- var f: f32 = 55.0 / 5;
+ const f: f32 = 55.0 / 5;
_ = f;
}
export fn entry4() void {
- var f: f32 = 55 / 5.0;
+ const f: f32 = 55 / 5.0;
_ = f;
}
@@ -19,5 +19,5 @@ export fn entry4() void {
// backend=stage2
// target=native
//
-// :2:23: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4'
-// :6:21: error: ambiguous coercion of division operands 'comptime_int' and 'comptime_float'; non-zero remainder '4'
+// :2:25: error: ambiguous coercion of division operands 'comptime_float' and 'comptime_int'; non-zero remainder '4'
+// :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
@@ -1,5 +1,6 @@
comptime {
var a: bool = undefined;
+ _ = &a;
_ = a and a;
}
@@ -7,4 +8,4 @@ comptime {
// backend=stage2
// target=native
//
-// :3:9: error: use of undefined value here causes undefined behavior
+// :4:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/array_access_of_non_array.zig
@@ -3,7 +3,7 @@ export fn f() void {
bad[0] = bad[0];
}
export fn g() void {
- var bad: bool = undefined;
+ const bad: bool = undefined;
_ = bad[0];
}
test/cases/compile_errors/array_access_of_type.zig
@@ -1,6 +1,6 @@
export fn foo() void {
var b: u8[40] = undefined;
- _ = b;
+ _ = &b;
}
// error
test/cases/compile_errors/array_access_with_non_integer_index.zig
@@ -2,11 +2,13 @@ export fn f() void {
var array = "aoeu";
var bad = false;
array[bad] = array[bad];
+ _ = &bad;
}
export fn g() void {
var array = "aoeu";
var bad = false;
_ = array[bad];
+ _ = .{ &array, &bad };
}
// error
@@ -14,4 +16,4 @@ export fn g() void {
// target=native
//
// :4:11: error: expected type 'usize', found 'bool'
-// :9:15: error: expected type 'usize', found 'bool'
+// :10:15: error: expected type 'usize', found 'bool'
test/cases/compile_errors/array_init_invalid_elem_count.zig
@@ -2,27 +2,27 @@ const V = @Vector(8, u8);
const A = [8]u8;
comptime {
var v: V = V{1};
- _ = v;
+ _ = &v;
}
comptime {
var v: V = V{};
- _ = v;
+ _ = &v;
}
comptime {
var a: A = A{1};
- _ = a;
+ _ = &a;
}
comptime {
var a: A = A{};
- _ = a;
+ _ = &a;
}
pub export fn entry1() void {
var bla: V = .{ 1, 2, 3, 4 };
- _ = bla;
+ _ = &bla;
}
pub export fn entry2() void {
var bla: A = .{ 1, 2, 3, 4 };
- _ = bla;
+ _ = &bla;
}
const S = struct {
list: [2]u8 = .{0},
test/cases/compile_errors/assign_inline_fn_to_non-comptime_var.zig
@@ -1,6 +1,6 @@
export fn entry() void {
var a = &b;
- _ = a;
+ _ = &a;
}
inline fn b() void {}
test/cases/compile_errors/assign_local_bad_coercion.zig
@@ -9,7 +9,7 @@ export fn constEntry() u32 {
export fn varEntry() u32 {
var x: u32 = g();
- return x;
+ return (&x).*;
}
// error
test/cases/compile_errors/assign_too_big_number_to_u16.zig
@@ -1,5 +1,5 @@
export fn foo() void {
- var vga_mem: u16 = 0xB8000;
+ const vga_mem: u16 = 0xB8000;
_ = vga_mem;
}
@@ -7,4 +7,4 @@ export fn foo() void {
// backend=stage2
// target=native
//
-// :2:24: error: type 'u16' cannot represent integer value '753664'
+// :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
@@ -10,8 +10,8 @@ const S = struct {
export fn entry() void {
var u = U{ .Ye = maybe(false) };
var s = S{ .num = maybe(false) };
- _ = u;
- _ = s;
+ _ = &u;
+ _ = &s;
}
// error
test/cases/compile_errors/AstGen_comptime_known_struct_is_resolved_before_error.zig
@@ -6,7 +6,7 @@ const S2 = struct {
};
pub export fn entry() void {
var s: S1 = undefined;
- _ = s;
+ _ = &s;
}
// error
test/cases/compile_errors/attempted_implicit_cast_from_const_T_to_array_len_1_T.zig
@@ -1,9 +1,9 @@
-export fn entry(byte: u8) void {
+export fn entry() void {
const w: i32 = 1234;
var x: *const i32 = &w;
var y: *[1]i32 = x;
y[0] += 1;
- _ = byte;
+ _ = &x;
}
// error
test/cases/compile_errors/bad_alignment_in_implicit_cast_from_array_pointer_to_slice.zig
@@ -1,6 +1,6 @@
export fn a() void {
var x: [10]u8 = undefined;
- var y: []align(16) u8 = &x;
+ const y: []align(16) u8 = &x;
_ = y;
}
@@ -8,5 +8,5 @@ export fn a() void {
// backend=stage2
// target=native
//
-// :3:29: error: expected type '[]align(16) u8', found '*[10]u8'
-// :3:29: note: pointer alignment '1' cannot cast into pointer alignment '16'
+// :3:31: error: expected type '[]align(16) u8', found '*[10]u8'
+// :3:31: note: pointer alignment '1' cannot cast into pointer alignment '16'
test/cases/compile_errors/bad_alignment_type.zig
@@ -1,9 +1,9 @@
export fn entry1() void {
- var x: []align(true) i32 = undefined;
+ const x: []align(true) i32 = undefined;
_ = x;
}
export fn entry2() void {
- var x: *align(@as(f64, 12.34)) i32 = undefined;
+ const x: *align(@as(f64, 12.34)) i32 = undefined;
_ = x;
}
@@ -11,5 +11,5 @@ export fn entry2() void {
// backend=stage2
// target=native
//
-// :2:20: error: expected type 'u32', found 'bool'
-// :6:19: error: fractional component prevents float value '12.34' from coercion to type 'u32'
+// :2:22: error: expected type 'u32', found 'bool'
+// :6:21: error: fractional component prevents float value '12.34' from coercion to type 'u32'
test/cases/compile_errors/bad_usage_of_call.zig
@@ -11,7 +11,7 @@ export fn entry4() void {
@call(.never_inline, bar, .{});
}
export fn entry5(c: bool) void {
- var baz = if (c) &baz1 else &baz2;
+ const baz = if (c) &baz1 else &baz2;
@call(.compile_time, baz, .{});
}
export fn entry6() void {
@@ -22,6 +22,7 @@ export fn entry7() void {
}
pub export fn entry() void {
var call_me: *const fn () void = undefined;
+ _ = &call_me;
@call(.always_inline, call_me, .{});
}
@@ -45,4 +46,4 @@ noinline fn dummy2() void {}
// :15:26: error: modifier 'compile_time' requires a comptime-known function
// :18:9: error: 'always_inline' call of noinline function
// :21:9: error: 'always_inline' call of noinline function
-// :25:27: error: modifier 'always_inline' requires a comptime-known function
+// :26:27: error: modifier 'always_inline' requires a comptime-known function
test/cases/compile_errors/binary_OR_operator_on_error_sets.zig
@@ -1,7 +1,7 @@
pub const A = error.A;
pub const AB = A | error.B;
export fn entry() void {
- var x: AB = undefined;
+ const x: AB = undefined;
_ = x;
}
test/cases/compile_errors/bitCast_same_size_but_bit_count_mismatch.zig
@@ -1,5 +1,5 @@
export fn entry(byte: u8) void {
- var oops: u7 = @bitCast(byte);
+ const oops: u7 = @bitCast(byte);
_ = oops;
}
@@ -7,4 +7,4 @@ export fn entry(byte: u8) void {
// backend=stage2
// target=native
//
-// :2:20: error: @bitCast size mismatch: destination type 'u7' has 7 bits but source type 'u8' has 8 bits
+// :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
@@ -1,5 +1,6 @@
export fn entry() void {
- var foo = (@as(u8, @bitCast(@as(f32, 1.0))) == 0xf);
+ const f: f32 = 1.0;
+ const foo = (@as(u8, @bitCast(f)) == 0xf);
_ = foo;
}
@@ -7,4 +8,4 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :2:24: error: @bitCast size mismatch: destination type 'u8' has 8 bits but source type 'f32' has 32 bits
+// :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
@@ -1,5 +1,6 @@
pub export fn entry1() void {
var x: u32 = 3;
+ _ = &x;
_ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
if (x > 1) 1 else -1,
});
@@ -7,6 +8,7 @@ pub export fn entry1() void {
pub export fn entry2() void {
var y: ?i8 = -1;
+ _ = &y;
_ = @shuffle(u32, [_]u32{0}, @as(@Vector(1, u32), @splat(0)), [_]i8{
y orelse 1,
});
@@ -16,6 +18,6 @@ pub export fn entry2() void {
// backend=stage2
// target=native
//
-// :4:15: error: unable to evaluate comptime expression
-// :4:13: note: operation is runtime due to this operand
-// :11:11: error: unable to evaluate comptime expression
+// :5:15: error: unable to evaluate comptime expression
+// :5:13: note: operation is runtime due to this operand
+// :13:11: error: unable to evaluate comptime expression
test/cases/compile_errors/break_void_result_location.zig
@@ -10,6 +10,7 @@ export fn f2() void {
}
export fn f3() void {
var t: bool = true;
+ _ = &t;
const x: usize = while (t) {
break;
};
@@ -28,5 +29,5 @@ export fn f4() void {
//
// :2:22: error: expected type 'usize', found 'void'
// :7:9: error: expected type 'usize', found 'void'
-// :14:9: error: expected type 'usize', found 'void'
-// :20:9: error: expected type 'usize', found 'void'
+// :15:9: error: expected type 'usize', found 'void'
+// :21:9: error: expected type 'usize', found 'void'
test/cases/compile_errors/C_pointer_pointing_to_non_C_ABI_compatible_type_or_has_align_attr.zig
@@ -1,7 +1,7 @@
const Foo = struct { a: u32 };
export fn a() void {
const T = [*c]Foo;
- var t: T = undefined;
+ const t: T = undefined;
_ = t;
}
test/cases/compile_errors/C_pointer_to_anyopaque.zig
@@ -1,7 +1,7 @@
export fn a() void {
var x: *anyopaque = undefined;
var y: [*c]anyopaque = x;
- _ = y;
+ _ = .{ &x, &y };
}
// error
test/cases/compile_errors/c_pointer_to_void.zig
@@ -1,5 +1,5 @@
export fn entry() void {
- var a: [*c]void = undefined;
+ const a: [*c]void = undefined;
_ = a;
}
@@ -7,5 +7,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :2:16: error: C pointers cannot point to non-C-ABI-compatible type 'void'
-// :2:16: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
+// :2:18: error: C pointers cannot point to non-C-ABI-compatible type 'void'
+// :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
@@ -2,15 +2,15 @@ const F1 = fn () callconv(.Stdcall) void;
const F2 = fn () callconv(.Fastcall) void;
const F3 = fn () callconv(.Thiscall) void;
export fn entry1() void {
- var a: F1 = undefined;
+ const a: F1 = undefined;
_ = a;
}
export fn entry2() void {
- var a: F2 = undefined;
+ const a: F2 = undefined;
_ = a;
}
export fn entry3() void {
- var a: F3 = undefined;
+ const a: F3 = undefined;
_ = a;
}
test/cases/compile_errors/cast_between_optional_T_where_T_is_not_a_pointer.zig
@@ -4,6 +4,7 @@ export fn entry1() void {
var a: fnty1 = undefined;
var b: fnty2 = undefined;
a = b;
+ _ = &b;
}
pub const fnty3 = ?*const fn (u63) void;
@@ -11,6 +12,7 @@ export fn entry2() void {
var a: fnty3 = undefined;
var b: fnty2 = undefined;
a = b;
+ _ = &b;
}
// error
@@ -21,6 +23,6 @@ export fn entry2() void {
// :6:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (i8) void'
// :6:9: note: parameter 0 'u64' cannot cast into 'i8'
// :6:9: note: unsigned 64-bit int cannot represent all possible signed 8-bit values
-// :13:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
-// :13:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
-// :13:9: note: parameter 0 'u64' cannot cast into 'u63'
+// :14:9: error: expected type '?*const fn (u63) void', found '?*const fn (u64) void'
+// :14:9: note: pointer type child 'fn (u64) void' cannot cast into pointer type child 'fn (u63) void'
+// :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
@@ -1,6 +1,6 @@
const SmallErrorSet = error{A};
export fn entry() void {
- var x: SmallErrorSet!i32 = foo();
+ const x: SmallErrorSet!i32 = foo();
_ = x;
}
fn foo() anyerror!i32 {
@@ -11,5 +11,5 @@ fn foo() anyerror!i32 {
// backend=stage2
// target=native
//
-// :3:35: error: expected type 'error{A}!i32', found 'anyerror!i32'
-// :3:35: note: global error set cannot cast into a smaller set
+// :3:37: error: expected type 'error{A}!i32', found 'anyerror!i32'
+// :3:37: note: global error set cannot cast into a smaller set
test/cases/compile_errors/cast_global_error_set_to_error_set.zig
@@ -1,6 +1,6 @@
const SmallErrorSet = error{A};
export fn entry() void {
- var x: SmallErrorSet = foo();
+ const x: SmallErrorSet = foo();
_ = x;
}
fn foo() anyerror {
@@ -11,5 +11,5 @@ fn foo() anyerror {
// backend=stage2
// target=native
//
-// :3:31: error: expected type 'error{A}', found 'anyerror'
-// :3:31: note: global error set cannot cast into a smaller set
+// :3:33: error: expected type 'error{A}', found 'anyerror'
+// :3:33: note: global error set cannot cast into a smaller set
test/cases/compile_errors/catch_on_undefined_value.zig
@@ -1,5 +1,5 @@
comptime {
- var a: anyerror!bool = undefined;
+ const a: anyerror!bool = undefined;
if (a catch false) {}
}
test/cases/compile_errors/compare_optional_to_non_optional_with_incomparable_type.zig
@@ -1,6 +1,6 @@
export fn entry() void {
- var x: ?[3]i32 = undefined;
- var y: [3]i32 = undefined;
+ const x: ?[3]i32 = undefined;
+ const y: [3]i32 = undefined;
_ = (x == y);
}
test/cases/compile_errors/comparison_operators_with_undefined_value.zig
@@ -1,36 +1,36 @@
// operator ==
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
var x: i32 = 0;
if (a == a) x += 1;
}
// operator !=
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
var x: i32 = 0;
if (a != a) x += 1;
}
// operator >
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
var x: i32 = 0;
if (a > a) x += 1;
}
// operator <
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
var x: i32 = 0;
if (a < a) x += 1;
}
// operator >=
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
var x: i32 = 0;
if (a >= a) x += 1;
}
// operator <=
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
var x: i32 = 0;
if (a <= a) x += 1;
}
test/cases/compile_errors/compile_error_in_struct_init_expression.zig
@@ -3,7 +3,7 @@ const Foo = struct {
b: i32,
};
export fn entry() void {
- var x = Foo{
+ const x: Foo = .{
.b = 5,
};
_ = x;
test/cases/compile_errors/compile_time_null_ptr_cast.zig
@@ -1,5 +1,5 @@
comptime {
- var opt_ptr: ?*i32 = null;
+ const opt_ptr: ?*i32 = null;
const ptr: *i32 = @ptrCast(opt_ptr);
_ = ptr;
}
test/cases/compile_errors/compile_time_undef_ptr_cast.zig
@@ -1,6 +1,7 @@
comptime {
var undef_ptr: *i32 = undefined;
const ptr: *i32 = @ptrCast(undef_ptr);
+ _ = &undef_ptr;
_ = ptr;
}
test/cases/compile_errors/comptime_cast_enum_to_union_but_field_has_payload.zig
@@ -6,7 +6,7 @@ const Value = union(Letter) {
};
export fn entry() void {
var x: Value = Letter.A;
- _ = x;
+ _ = &x;
}
// error
test/cases/compile_errors/comptime_continue_inside_runtime_if_bool.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: usize = undefined;
+ _ = &p;
comptime var q = true;
inline while (q) {
if (p == 11) continue;
@@ -11,5 +12,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :5:22: error: comptime control flow inside runtime block
-// :5:15: note: runtime control flow here
+// :6:22: error: comptime control flow inside runtime block
+// :6:15: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_if_error.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: anyerror!i32 = undefined;
+ _ = &p;
comptime var q = true;
inline while (q) {
if (p) |_| continue else |_| {}
@@ -11,5 +12,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :5:20: error: comptime control flow inside runtime block
-// :5:13: note: runtime control flow here
+// :6:20: error: comptime control flow inside runtime block
+// :6:13: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_if_optional.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: ?i32 = undefined;
+ _ = &p;
comptime var q = true;
inline while (q) {
if (p) |_| continue;
@@ -11,5 +12,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :5:20: error: comptime control flow inside runtime block
-// :5:13: note: runtime control flow here
+// :6:20: error: comptime control flow inside runtime block
+// :6:13: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_switch.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: i32 = undefined;
+ _ = &p;
comptime var q = true;
inline while (q) {
switch (p) {
@@ -14,5 +15,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :6:19: error: comptime control flow inside runtime block
-// :5:17: note: runtime control flow here
+// :7:19: error: comptime control flow inside runtime block
+// :6:17: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_bool.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: usize = undefined;
+ _ = &p;
comptime var q = true;
outer: inline while (q) {
while (p == 11) continue :outer;
@@ -11,5 +12,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :5:25: error: comptime control flow inside runtime block
-// :5:18: note: runtime control flow here
+// :6:25: error: comptime control flow inside runtime block
+// :6:18: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_error.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: anyerror!usize = undefined;
+ _ = &p;
comptime var q = true;
outer: inline while (q) {
while (p) |_| {
@@ -13,5 +14,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :6:13: error: comptime control flow inside runtime block
-// :5:16: note: runtime control flow here
+// :7:13: error: comptime control flow inside runtime block
+// :6:16: note: runtime control flow here
test/cases/compile_errors/comptime_continue_inside_runtime_while_optional.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var p: ?usize = undefined;
+ _ = &p;
comptime var q = true;
outer: inline while (q) {
while (p) |_| continue :outer;
@@ -11,5 +12,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :5:23: error: comptime control flow inside runtime block
-// :5:16: note: runtime control flow here
+// :6:23: error: comptime control flow inside runtime block
+// :6:16: note: runtime control flow here
test/cases/compile_errors/comptime_continue_to_outer_inline_loop.zig
@@ -1,5 +1,6 @@
pub export fn entry() void {
var a = false;
+ _ = &a;
const arr1 = .{ 1, 2, 3 };
loop: inline for (arr1) |val1| {
_ = val1;
@@ -17,5 +18,5 @@ pub export fn entry() void {
// backend=stage2
// target=native
//
-// :9:30: error: comptime control flow inside runtime block
-// :6:13: note: runtime control flow here
+// :10:30: error: comptime control flow inside runtime block
+// :7:13: note: runtime control flow here
test/cases/compile_errors/comptime_if_inside_runtime_for.zig
@@ -1,8 +1,9 @@
export fn entry() void {
var x: u32 = 0;
+ _ = &x;
for (0..1, 1..2) |_, _| {
var y = x + if (x == 0) 1 else 0;
- _ = y;
+ _ = &y;
}
}
@@ -10,5 +11,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :4:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow
-// :3:10: note: runtime control flow here
+// :5:21: error: value with comptime-only type 'comptime_int' depends on runtime control flow
+// :4:10: note: runtime control flow here
test/cases/compile_errors/comptime_slice_of_an_undefined_slice.zig
@@ -1,7 +1,7 @@
comptime {
var a: []u8 = undefined;
var b = a[0..10];
- _ = b;
+ _ = &b;
}
// error
test/cases/compile_errors/comptime_struct_field_no_init_value.zig
@@ -3,7 +3,7 @@ const Foo = struct {
};
export fn entry() void {
var f: Foo = undefined;
- _ = f;
+ _ = &f;
}
// error
test/cases/compile_errors/comptime_vector_overflow_shows_the_index.zig
@@ -2,7 +2,7 @@ comptime {
var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
var x = a + b;
- _ = x;
+ _ = .{ &a, &b, &x };
}
// error
test/cases/compile_errors/constant_inside_comptime_function_has_compile_error.zig
@@ -1,9 +1,7 @@
const ContextAllocator = MemoryPool(usize);
pub fn MemoryPool(comptime T: type) type {
- const free_list_t = @compileError(
- "aoeu",
- );
+ const free_list_t = @compileError("aoeu");
_ = T;
return struct {
@@ -12,7 +10,7 @@ pub fn MemoryPool(comptime T: type) type {
}
export fn entry() void {
- var allocator: ContextAllocator = undefined;
+ const allocator: ContextAllocator = undefined;
_ = allocator;
}
test/cases/compile_errors/deref_on_undefined_value.zig
@@ -1,5 +1,5 @@
comptime {
- var a: *u8 = undefined;
+ const a: *u8 = undefined;
_ = a.*;
}
test/cases/compile_errors/deref_slice_and_get_len_field.zig
@@ -1,6 +1,7 @@
export fn entry() void {
var a: []u8 = undefined;
_ = a.*.len;
+ _ = &a;
}
// error
test/cases/compile_errors/dereference_an_array.zig
@@ -1,6 +1,7 @@
var s_buffer: [10]u8 = undefined;
pub fn pass(in: []u8) []u8 {
var out = &s_buffer;
+ _ = &out;
out.*.* = in[0];
return out.*[0..1];
}
@@ -13,4 +14,4 @@ export fn entry() usize {
// backend=stage2
// target=native
//
-// :4:10: error: cannot dereference non-pointer type '[10]u8'
+// :5:10: error: cannot dereference non-pointer type '[10]u8'
test/cases/compile_errors/dereferencing_invalid_payload_ptr_at_comptime.zig
@@ -16,7 +16,7 @@ comptime {
_ = payload_ptr.*;
}
comptime {
- var val: u8 = 15;
+ const val: u8 = 15;
var err_union: anyerror!u8 = val;
const payload_ptr = &(err_union catch unreachable);
test/cases/compile_errors/directly_embedding_opaque_type_in_struct_and_union.zig
@@ -8,11 +8,11 @@ const Bar = union {
};
export fn a() void {
var foo: Foo = undefined;
- _ = foo;
+ _ = &foo;
}
export fn b() void {
var bar: Bar = undefined;
- _ = bar;
+ _ = &bar;
}
export fn c() void {
const baz = &@as(O, undefined);
test/cases/compile_errors/div_on_undefined_value.zig
@@ -1,6 +1,7 @@
comptime {
var a: i64 = undefined;
_ = a / a;
+ _ = &a;
}
// error
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig
@@ -11,12 +11,13 @@ pub export fn entry2() void {
fn func(_: ?*anyopaque) void {}
pub export fn entry3() void {
var x: *?*usize = undefined;
-
+ _ = &x;
const ptr: *const anyopaque = x;
_ = ptr;
}
export fn entry4() void {
var a: []*u32 = undefined;
+ _ = &a;
var b: []anyopaque = undefined;
b = a;
}
@@ -32,5 +33,5 @@ export fn entry4() void {
// :11:12: note: parameter type declared here
// :15:35: error: expected type '*const anyopaque', found '*?*usize'
// :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque'
-// :21:9: error: expected type '[]anyopaque', found '[]*u32'
-// :21:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'
+// :22:9: error: expected type '[]anyopaque', found '[]*u32'
+// :22:9: note: cannot implicitly cast double pointer '[]*u32' to anyopaque pointer '[]anyopaque'
test/cases/compile_errors/empty_switch_on_an_integer.zig
@@ -1,5 +1,5 @@
export fn entry() void {
- var x: u32 = 0;
+ const x: u32 = 0;
switch (x) {}
}
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig
@@ -1,7 +1,7 @@
pub export fn entry() void {
const E = enum(comptime_int) { a, b, c, _ };
var e: E = .a;
- _ = e;
+ _ = &e;
}
// error
test/cases/compile_errors/enum_field_value_references_enum.zig
@@ -3,7 +3,7 @@ pub const Foo = enum(c_int) {
C = D,
};
export fn entry() void {
- var s: Foo = Foo.E;
+ const s: Foo = Foo.E;
_ = s;
}
const D = 1;
test/cases/compile_errors/enum_in_field_count_range_but_not_matching_tag.zig
@@ -3,7 +3,7 @@ const Foo = enum(u32) {
B = 11,
};
export fn entry() void {
- var x: Foo = @enumFromInt(0);
+ const x: Foo = @enumFromInt(0);
_ = x;
}
@@ -11,5 +11,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :6:18: error: enum 'tmp.Foo' has no tag with value '0'
+// :6:20: error: enum 'tmp.Foo' has no tag with value '0'
// :1:13: note: enum declared here
test/cases/compile_errors/enum_value_already_taken.zig
@@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) {
E = 60,
};
export fn entry() void {
- var x = MultipleChoice.C;
+ const x = MultipleChoice.C;
_ = x;
}
test/cases/compile_errors/error_in_struct_initializer_doesnt_crash_the_compiler.zig
@@ -4,7 +4,7 @@ pub export fn entry() void {
e: u8,
};
var a = .{@sizeOf(bitfield)};
- _ = a;
+ _ = &a;
}
// error
test/cases/compile_errors/error_union_operator_with_non_error_set_LHS.zig
@@ -1,6 +1,6 @@
comptime {
const z = i32!i32;
- var x: z = undefined;
+ const x: z = undefined;
_ = x;
}
test/cases/compile_errors/error_when_evaluating_return_type.zig
@@ -6,7 +6,7 @@ const Foo = struct {
}
};
export fn entry() void {
- var rule_set = try Foo.init();
+ const rule_set = try Foo.init();
_ = rule_set;
}
test/cases/compile_errors/explain_why_generic_fn_is_called_at_comptime.zig
@@ -11,12 +11,13 @@ fn foo(a: u8, comptime PtrTy: type) S(PtrTy) {
}
pub export fn entry() void {
var a: u8 = 1;
+ _ = &a;
_ = foo(a, fn () void);
}
// error
// backend=stage2
// target=native
//
-// :14:13: error: unable to resolve comptime value
-// :14:13: note: argument to function being called at comptime must be comptime-known
+// :15:13: error: unable to resolve comptime value
+// :15:13: note: argument to function being called at comptime must be comptime-known
// :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
@@ -1,8 +1,8 @@
const Set1 = error{ A, B };
const Set2 = error{ A, C };
comptime {
- var x = Set1.B;
- var y: Set2 = @errorCast(x);
+ const x = Set1.B;
+ const y: Set2 = @errorCast(x);
_ = y;
}
@@ -10,4 +10,4 @@ comptime {
// backend=stage2
// target=native
//
-// :5:19: error: 'error.B' not a member of error set 'error{C,A}'
+// :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
@@ -7,7 +7,7 @@ const Small = enum(u2) {
export fn entry() void {
var y = @as(f32, 3);
- var x: Small = @enumFromInt(y);
+ const x: Small = @enumFromInt((&y).*);
_ = x;
}
@@ -15,4 +15,4 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :10:33: error: expected integer type, found 'f32'
+// :10:39: error: expected integer type, found 'f32'
test/cases/compile_errors/extern_union_field_missing_type.zig
@@ -2,7 +2,7 @@ const Letter = extern union {
A,
};
export fn entry() void {
- var a = Letter{ .A = {} };
+ const a: Letter = .{ .A = {} };
_ = a;
}
test/cases/compile_errors/extern_union_given_enum_tag_type.zig
@@ -9,7 +9,7 @@ const Payload = extern union(Letter) {
C: bool,
};
export fn entry() void {
- var a = Payload{ .A = 1234 };
+ const a: Payload = .{ .A = 1234 };
_ = a;
}
test/cases/compile_errors/field_access_of_slices.zig
@@ -1,5 +1,6 @@
export fn entry() void {
var slice: []i32 = undefined;
+ _ = &slice;
const info = @TypeOf(slice).unknown;
_ = info;
}
@@ -8,5 +9,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :3:32: error: type '[]i32' has no members
-// :3:32: note: slice values have 'len' and 'ptr' members
+// :4:32: error: type '[]i32' has no members
+// :4:32: note: slice values have 'len' and 'ptr' members
test/cases/compile_errors/for.zig
@@ -17,6 +17,7 @@ export fn c() void {
for (buf) |*byte| {
_ = byte;
}
+ _ = &buf;
}
export fn d() void {
const x: [*]const u8 = "hello";
@@ -39,6 +40,6 @@ export fn d() void {
// :10:14: note: for loop operand must be a range, array, slice, tuple, or vector
// :17:16: error: pointer capture of non pointer type '[10]u8'
// :17:10: note: consider using '&' here
-// :24:5: error: unbounded for loop
-// :24:10: note: type '[*]const u8' has no upper bound
-// :24:18: note: type '[*]const u8' has no upper bound
+// :25:5: error: unbounded for loop
+// :25:10: note: type '[*]const u8' has no upper bound
+// :25:18: note: type '[*]const u8' has no upper bound
test/cases/compile_errors/for_loop_body_expression_ignored.zig
@@ -7,7 +7,7 @@ export fn f1() void {
export fn f2() void {
var x: anyerror!i32 = error.Bad;
for ("hello") |_| returns() else unreachable;
- _ = x;
+ _ = &x;
}
export fn f3() void {
for ("hello") |_| {} else true;
test/cases/compile_errors/function_ptr_alignment.zig
@@ -1,24 +1,24 @@
comptime {
var a: *align(2) @TypeOf(foo) = undefined;
- _ = a;
+ _ = &a;
}
fn foo() void {}
comptime {
var a: *align(1) fn () void = undefined;
- _ = a;
+ _ = &a;
}
comptime {
var a: *align(2) fn () align(2) void = undefined;
- _ = a;
+ _ = &a;
}
comptime {
var a: *align(2) fn () void = undefined;
- _ = a;
+ _ = &a;
}
comptime {
var a: *align(1) fn () align(2) void = undefined;
- _ = a;
+ _ = &a;
}
// error
test/cases/compile_errors/generic_instantiation_failure_in_generic_function_return_type.zig
@@ -3,6 +3,7 @@ const std = @import("std");
pub export fn entry() void {
var ohnoes: *usize = undefined;
_ = sliceAsBytes(ohnoes);
+ _ = &ohnoes;
}
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)) {
// backend=llvm
// target=native
//
-// :7:63: error: expected type 'type', found 'bool'
+// :8:63: error: expected type 'type', found 'bool'
test/cases/compile_errors/generic_method_call_with_invalid_param.zig
@@ -11,6 +11,7 @@ export fn callVoidMethodWithBool() void {
export fn callComptimeBoolMethodWithRuntimeBool() void {
const s = S{};
var arg = true;
+ _ = &arg;
s.comptimeBoolMethod(arg);
}
@@ -25,8 +26,8 @@ const S = struct {
// target=native
//
// :3:18: error: expected type 'bool', found 'void'
-// :18:43: note: parameter type declared here
-// :8:18: error: expected type 'void', found 'bool'
// :19:43: note: parameter type declared here
-// :14:26: error: runtime-known argument passed to comptime parameter
-// :20:57: note: declared comptime here
+// :8:18: error: expected type 'void', found 'bool'
+// :20:43: note: parameter type declared here
+// :15:26: error: runtime-known argument passed to comptime parameter
+// :21:57: note: declared comptime here
test/cases/compile_errors/ignored_expression_in_while_continuation.zig
@@ -3,10 +3,12 @@ export fn a() void {
}
export fn b() void {
var x: anyerror!i32 = 1234;
+ _ = &x;
while (x) |_| : (bad()) {} else |_| {}
}
export fn c() void {
var x: ?i32 = 1234;
+ _ = &x;
while (x) |_| : (bad()) {}
}
fn bad() anyerror!void {
@@ -19,7 +21,7 @@ fn bad() anyerror!void {
//
// :2:24: error: error is ignored
// :2:24: note: consider using 'try', 'catch', or 'if'
-// :6:25: error: error is ignored
-// :6:25: note: consider using 'try', 'catch', or 'if'
-// :10:25: error: error is ignored
-// :10:25: note: consider using 'try', 'catch', or 'if'
+// :7:25: error: error is ignored
+// :7:25: note: consider using 'try', 'catch', or 'if'
+// :12:25: error: error is ignored
+// :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
@@ -1,32 +1,32 @@
export fn a() void {
var x: [*c]u8 = undefined;
var y: *align(4) u8 = x;
- _ = y;
+ _ = .{ &x, &y };
}
export fn b() void {
var x: [*c]const u8 = undefined;
var y: *u8 = x;
- _ = y;
+ _ = .{ &x, &y };
}
export fn c() void {
var x: [*c]u8 = undefined;
var y: *u32 = x;
- _ = y;
+ _ = .{ &x, &y };
}
export fn d() void {
var y: *align(1) u32 = undefined;
var x: [*c]u32 = y;
- _ = x;
+ _ = .{ &x, &y };
}
export fn e() void {
var y: *const u8 = undefined;
var x: [*c]u8 = y;
- _ = x;
+ _ = .{ &x, &y };
}
export fn f() void {
var y: *u8 = undefined;
var x: [*c]u32 = y;
- _ = x;
+ _ = .{ &x, &y };
}
// error
test/cases/compile_errors/implicit_cast_from_f64_to_f32.zig
@@ -7,7 +7,7 @@ export fn entry() void {
export fn entry2() void {
var x1: f64 = 1.0;
var y2: f32 = x1;
- _ = y2;
+ _ = .{ &x1, &y2 };
}
// error
test/cases/compile_errors/implicit_cast_of_error_set_not_a_subset.zig
@@ -4,7 +4,7 @@ export fn entry() void {
foo(Set1.B);
}
fn foo(set1: Set1) void {
- var x: Set2 = set1;
+ const x: Set2 = set1;
_ = x;
}
@@ -12,5 +12,5 @@ fn foo(set1: Set1) void {
// backend=stage2
// target=native
//
-// :7:19: error: expected type 'error{C,A}', found 'error{A,B}'
-// :7:19: note: 'error.B' not a member of destination error set
+// :7:21: error: expected type 'error{C,A}', found 'error{A,B}'
+// :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
@@ -4,6 +4,9 @@ export fn entry() void {
var ptr_opt_many_ptr = &opt_many_ptr;
var c_ptr: [*c]const [*c]const u8 = ptr_opt_many_ptr;
ptr_opt_many_ptr = c_ptr;
+ _ = &slice;
+ _ = &ptr_opt_many_ptr;
+ _ = &c_ptr;
}
export fn entry2() void {
var buf: [4]u8 = "aoeu".*;
@@ -11,7 +14,9 @@ export fn entry2() void {
var opt_many_ptr: [*]u8 = slice.ptr;
var ptr_opt_many_ptr = &opt_many_ptr;
var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
- _ = c_ptr;
+ _ = &slice;
+ _ = &ptr_opt_many_ptr;
+ _ = &c_ptr;
}
// error
@@ -21,6 +26,6 @@ export fn entry2() void {
// :6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'
// :6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'
// :6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'
-// :13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
-// :13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
-// :13:35: note: mutable '[*]u8' allows illegal null values stored to type '[*c]const u8'
+// :16:35: error: expected type '[*c][*c]const u8', found '*[*]u8'
+// :16:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'
+// :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
@@ -1,6 +1,7 @@
comptime {
var c_ptr: [*c]u8 = 0;
- var zig_ptr: *u8 = c_ptr;
+ const zig_ptr: *u8 = c_ptr;
+ _ = &c_ptr;
_ = zig_ptr;
}
@@ -8,4 +9,4 @@ comptime {
// backend=stage2
// target=native
//
-// :3:24: error: null pointer casted to type '*u8'
+// :3:26: error: null pointer casted to type '*u8'
test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig
@@ -7,7 +7,7 @@ const Small = enum(u2) {
export fn entry() void {
var x: u2 = Small.Two;
- _ = x;
+ _ = &x;
}
// error
test/cases/compile_errors/incompatible sub-byte fields.zig
@@ -11,6 +11,7 @@ export fn entry() void {
var a = A{ .a = 2, .b = 2 };
var b = B{ .q = 22, .a = 3, .b = 2 };
var t: usize = 0;
+ _ = &t;
const ptr = switch (t) {
0 => &a.a,
1 => &b.a,
@@ -24,6 +25,6 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :14:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'
-// :15:14: note: type '*align(1:0:1) u2' here
-// :16:14: note: type '*align(2:8:2) u2' here
+// :15:17: error: incompatible types: '*align(1:0:1) u2' and '*align(2:8:2) u2'
+// :16:14: note: type '*align(1:0:1) u2' here
+// :17:14: note: type '*align(2:8:2) u2' here
test/cases/compile_errors/incompatible_sentinels.zig
@@ -8,11 +8,11 @@ export fn entry2(ptr: [*]u8) [*:0]u8 {
}
export fn entry3() void {
var array: [2:0]u8 = [_:255]u8{ 1, 2 };
- _ = array;
+ _ = &array;
}
export fn entry4() void {
var array: [2:0]u8 = [_]u8{ 1, 2 };
- _ = array;
+ _ = &array;
}
// error
test/cases/compile_errors/incorrect_pointer_dereference_syntax.zig
@@ -1,6 +1,7 @@
pub export fn entry() void {
var a: *u32 = undefined;
_ = *a;
+ _ = &a;
}
// error
test/cases/compile_errors/incorrect_type_to_memset_memcpy.zig
@@ -1,17 +1,17 @@
pub export fn entry() void {
var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
- var slice: []u8 = &buf;
+ const slice: []u8 = &buf;
const a: u32 = 1234;
@memcpy(slice.ptr, @as([*]const u8, @ptrCast(&a)));
}
pub export fn entry1() void {
var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
- var ptr: *u8 = &buf[0];
+ const ptr: *u8 = &buf[0];
@memcpy(ptr, 0);
}
pub export fn entry2() void {
var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
- var ptr: *u8 = &buf[0];
+ const ptr: *u8 = &buf[0];
@memset(ptr, 0);
}
pub export fn non_matching_lengths() void {
@@ -29,7 +29,7 @@ pub export fn memcpy_const_dest_ptr() void {
@memcpy(&buf1, &buf2);
}
pub export fn memset_array() void {
- var buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
+ const buf: [5]u8 = .{ 1, 2, 3, 4, 5 };
@memcpy(buf, 1);
}
test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig
@@ -1,6 +1,7 @@
const array = [_]u8{};
export fn foo() void {
var index: usize = 0;
+ _ = &index;
const pointer = &array[index];
_ = pointer;
}
@@ -9,4 +10,4 @@ export fn foo() void {
// backend=stage2
// target=native
//
-// :4:27: error: indexing into empty array is not allowed
+// :5:27: error: indexing into empty array is not allowed
test/cases/compile_errors/inline_call_runtime_value_to_comptime_param.zig
@@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void {
}
pub export fn entry() void {
var value: u64 = 0;
- acceptRuntime(value);
+ acceptRuntime((&value).*);
}
// error
test/cases/compile_errors/int-float_conversion_to_comptime_int-float.zig
@@ -1,9 +1,11 @@
export fn foo() void {
var a: f32 = 2;
+ _ = &a;
_ = @as(comptime_int, @intFromFloat(a));
}
export fn bar() void {
var a: u32 = 2;
+ _ = &a;
_ = @as(comptime_float, @floatFromInt(a));
}
@@ -11,7 +13,7 @@ export fn bar() void {
// backend=stage2
// target=native
//
-// :3:41: error: unable to resolve comptime value
-// :3:41: note: value being casted to 'comptime_int' must be comptime-known
-// :7:43: error: unable to resolve comptime value
-// :7:43: note: value being casted to 'comptime_float' must be comptime-known
+// :4:41: error: unable to resolve comptime value
+// :4:41: note: value being casted to 'comptime_int' must be comptime-known
+// :9:43: error: unable to resolve comptime value
+// :9:43: note: value being casted to 'comptime_float' must be comptime-known
test/cases/compile_errors/int_to_err_global_invalid_number.zig
@@ -5,7 +5,7 @@ const Set1 = error{
comptime {
var x: u16 = 3;
var y = @errorFromInt(x);
- _ = y;
+ _ = .{ &x, &y };
}
// error
test/cases/compile_errors/int_to_err_non_global_invalid_number.zig
@@ -7,8 +7,8 @@ const Set2 = error{
C,
};
comptime {
- var x = @intFromError(Set1.B);
- var y: Set2 = @errorCast(@errorFromInt(x));
+ const x = @intFromError(Set1.B);
+ const y: Set2 = @errorCast(@errorFromInt(x));
_ = y;
}
@@ -16,4 +16,4 @@ comptime {
// backend=llvm
// target=native
//
-// :11:19: error: 'error.B' not a member of error set 'error{C,A}'
+// :11:21: error: 'error.B' not a member of error set 'error{C,A}'
test/cases/compile_errors/integer_cast_truncates_bits.zig
@@ -11,12 +11,12 @@ export fn entry2() void {
export fn entry3() void {
var spartan_count: u16 = 300;
var byte: u8 = spartan_count;
- _ = byte;
+ _ = .{ &spartan_count, &byte };
}
export fn entry4() void {
var signed: i8 = -1;
var unsigned: u64 = signed;
- _ = unsigned;
+ _ = .{ &signed, &unsigned };
}
// error
test/cases/compile_errors/intFromPtr_0_to_non_optional_pointer.zig
@@ -1,5 +1,5 @@
export fn entry() void {
- var b: *i32 = @ptrFromInt(0);
+ const b: *i32 = @ptrFromInt(0);
_ = b;
}
@@ -7,4 +7,4 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :2:31: error: pointer type '*i32' does not allow address zero
+// :2:33: error: pointer type '*i32' does not allow address zero
test/cases/compile_errors/invalid_compare_string.zig
@@ -1,20 +1,20 @@
comptime {
- var a = "foo";
+ const a = "foo";
if (a == "foo") unreachable;
}
comptime {
- var a = "foo";
+ const a = "foo";
if (a == ("foo")) unreachable; // intentionally allow
}
comptime {
- var a = "foo";
+ const a = "foo";
switch (a) {
"foo" => unreachable,
else => {},
}
}
comptime {
- var a = "foo";
+ const a = "foo";
switch (a) {
("foo") => unreachable, // intentionally allow
else => {},
test/cases/compile_errors/invalid_deref_on_switch_target.zig
@@ -1,5 +1,5 @@
comptime {
- var tile = Tile.Empty;
+ const tile = Tile.Empty;
switch (tile.*) {
Tile.Empty => {},
Tile.Filled => {},
test/cases/compile_errors/invalid_float_casts.zig
@@ -1,17 +1,21 @@
export fn foo() void {
var a: f32 = 2;
+ _ = &a;
_ = @as(comptime_float, @floatCast(a));
}
export fn bar() void {
var a: f32 = 2;
+ _ = &a;
_ = @as(f32, @intFromFloat(a));
}
export fn baz() void {
var a: f32 = 2;
+ _ = &a;
_ = @as(f32, @floatFromInt(a));
}
export fn qux() void {
var a: u32 = 2;
+ _ = &a;
_ = @as(f32, @floatCast(a));
}
@@ -19,7 +23,7 @@ export fn qux() void {
// backend=stage2
// target=native
//
-// :3:40: error: unable to cast runtime value to 'comptime_float'
-// :7:18: error: expected integer type, found 'f32'
-// :11:32: error: expected integer type, found 'f32'
-// :15:29: error: expected float or vector type, found 'u32'
+// :4:40: error: unable to cast runtime value to 'comptime_float'
+// :9:18: error: expected integer type, found 'f32'
+// :14:32: error: expected integer type, found 'f32'
+// :19:29: error: expected float or vector type, found 'u32'
test/cases/compile_errors/invalid_inline_else_type.zig
@@ -1,5 +1,6 @@
pub export fn entry1() void {
var a: anyerror = undefined;
+ _ = &a;
switch (a) {
inline else => {},
}
@@ -7,12 +8,14 @@ pub export fn entry1() void {
const E = enum(u8) { a, _ };
pub export fn entry2() void {
var a: E = undefined;
+ _ = &a;
switch (a) {
inline else => {},
}
}
pub export fn entry3() void {
var a: *u32 = undefined;
+ _ = &a;
switch (a) {
inline else => {},
}
@@ -22,6 +25,6 @@ pub export fn entry3() void {
// backend=stage2
// target=native
//
-// :4:21: error: cannot enumerate values of type 'anyerror' for 'inline else'
-// :11:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'
-// :17:21: error: cannot enumerate values of type '*u32' for 'inline else'
+// :5:21: error: cannot enumerate values of type 'anyerror' for 'inline else'
+// :13:21: error: cannot enumerate values of type 'tmp.E' for 'inline else'
+// :20:21: error: cannot enumerate values of type '*u32' for 'inline else'
test/cases/compile_errors/invalid_int_casts.zig
@@ -1,17 +1,21 @@
export fn foo() void {
var a: u32 = 2;
+ _ = &a;
_ = @as(comptime_int, @intCast(a));
}
export fn bar() void {
var a: u32 = 2;
+ _ = &a;
_ = @as(u32, @floatFromInt(a));
}
export fn baz() void {
var a: u32 = 2;
+ _ = &a;
_ = @as(u32, @intFromFloat(a));
}
export fn qux() void {
var a: f32 = 2;
+ _ = &a;
_ = @as(u32, @intCast(a));
}
@@ -19,7 +23,7 @@ export fn qux() void {
// backend=stage2
// target=native
//
-// :3:36: error: unable to cast runtime value to 'comptime_int'
-// :7:18: error: expected float type, found 'u32'
-// :11:32: error: expected float type, found 'u32'
-// :15:27: error: expected integer or vector, found 'f32'
+// :4:36: error: unable to cast runtime value to 'comptime_int'
+// :9:18: error: expected float type, found 'u32'
+// :14:32: error: expected float type, found 'u32'
+// :19:27: error: expected integer or vector, found 'f32'
test/cases/compile_errors/invalid_multiple_dereferences.zig
@@ -1,11 +1,12 @@
export fn a() void {
var box = Box{ .field = 0 };
+ _ = &box;
box.*.field = 1;
}
export fn b() void {
var box = Box{ .field = 0 };
- var boxPtr = &box;
- boxPtr.*.*.field = 1;
+ const box_ptr = &box;
+ box_ptr.*.*.field = 1;
}
pub const Box = struct {
field: i32,
@@ -15,5 +16,5 @@ pub const Box = struct {
// backend=stage2
// target=native
//
-// :3:8: error: cannot dereference non-pointer type 'tmp.Box'
-// :8:13: error: cannot dereference non-pointer type 'tmp.Box'
+// :4:8: error: cannot dereference non-pointer type 'tmp.Box'
+// :9:14: error: cannot dereference non-pointer type 'tmp.Box'
test/cases/compile_errors/invalid_non-exhaustive_enum_to_union.zig
@@ -10,12 +10,12 @@ const U = union(E) {
export fn foo() void {
var e: E = @enumFromInt(15);
var u: U = e;
- _ = u;
+ _ = .{ &e, &u };
}
export fn bar() void {
const e: E = @enumFromInt(15);
var u: U = e;
- _ = u;
+ _ = &u;
}
// error
test/cases/compile_errors/invalid_peer_type_resolution.zig
@@ -1,11 +1,13 @@
export fn optionalVector() void {
var x: ?@Vector(10, i32) = undefined;
var y: @Vector(11, i32) = undefined;
+ _ = .{ &x, &y };
_ = @TypeOf(x, y);
}
export fn badTupleField() void {
var x = .{ @as(u8, 0), @as(u32, 1) };
var y = .{ @as(u8, 1), "hello" };
+ _ = .{ &x, &y };
_ = @TypeOf(x, y);
}
export fn badNestedField() void {
@@ -30,21 +32,21 @@ export fn incompatiblePointers4() void {
// backend=llvm
// target=native
//
-// :4:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
-// :4:17: note: type '?@Vector(10, i32)' here
-// :4:20: note: type '@Vector(11, i32)' here
-// :9:9: error: struct field '1' has conflicting types
-// :9:9: note: incompatible types: 'u32' and '*const [5:0]u8'
-// :9:17: note: type 'u32' here
-// :9:20: note: type '*const [5:0]u8' here
-// :14:9: error: struct field 'bar' has conflicting types
-// :14:9: note: struct field '1' has conflicting types
-// :14:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'
-// :14:17: note: type 'comptime_int' here
-// :14:20: note: type '*const [2:0]u8' here
-// :19:9: error: incompatible types: '[]const u8' and '[*:0]const u8'
-// :19:17: note: type '[]const u8' here
-// :19:20: note: type '[*:0]const u8' here
-// :26:9: error: incompatible types: '[]const u8' and '[*]const u8'
-// :26:23: note: type '[]const u8' here
-// :26:26: note: type '[*]const u8' here
+// :5:9: error: incompatible types: '?@Vector(10, i32)' and '@Vector(11, i32)'
+// :5:17: note: type '?@Vector(10, i32)' here
+// :5:20: note: type '@Vector(11, i32)' here
+// :11:9: error: struct field '1' has conflicting types
+// :11:9: note: incompatible types: 'u32' and '*const [5:0]u8'
+// :11:17: note: type 'u32' here
+// :11:20: note: type '*const [5:0]u8' here
+// :16:9: error: struct field 'bar' has conflicting types
+// :16:9: note: struct field '1' has conflicting types
+// :16:9: note: incompatible types: 'comptime_int' and '*const [2:0]u8'
+// :16:17: note: type 'comptime_int' here
+// :16:20: note: type '*const [2:0]u8' here
+// :21:9: error: incompatible types: '[]const u8' and '[*:0]const u8'
+// :21:17: note: type '[]const u8' here
+// :21:20: note: type '[*:0]const u8' here
+// :28:9: error: incompatible types: '[]const u8' and '[*]const u8'
+// :28:23: note: type '[]const u8' here
+// :28:26: note: type '[*]const u8' here
test/cases/compile_errors/invalid_store_to_comptime_field.zig
@@ -17,8 +17,9 @@ pub export fn entry2() void {
var list = .{ 1, 2, 3 };
var list2 = @TypeOf(list){ .@"0" = 1, .@"1" = 2, .@"2" = 3 };
var list3 = @TypeOf(list){ 1, 2, 4 };
- _ = list2;
- _ = list3;
+ _ = &list;
+ _ = &list2;
+ _ = &list3;
}
pub export fn entry3() void {
const U = struct {
@@ -46,6 +47,7 @@ pub export fn entry5() void {
}
pub export fn entry6() void {
var x: u32 = 15;
+ _ = &x;
const T = @TypeOf(.{ @as(i32, -1234), @as(u32, 5678), x });
const S = struct {
fn foo(_: T) void {}
@@ -74,12 +76,12 @@ pub export fn entry8() void {
// :6:9: error: value stored in comptime field does not match the default value of the field
// :14:9: error: value stored in comptime field does not match the default value of the field
// :19:38: error: value stored in comptime field does not match the default value of the field
-// :31:19: error: value stored in comptime field does not match the default value of the field
-// :25:29: note: default value set here
-// :41:19: error: value stored in comptime field does not match the default value of the field
-// :35:29: note: default value set here
-// :45:12: error: value stored in comptime field does not match the default value of the field
-// :53:25: error: value stored in comptime field does not match the default value of the field
-// :66:36: error: value stored in comptime field does not match the default value of the field
-// :59:30: error: value stored in comptime field does not match the default value of the field
-// :57:29: note: default value set here
+// :32:19: error: value stored in comptime field does not match the default value of the field
+// :26:29: note: default value set here
+// :42:19: error: value stored in comptime field does not match the default value of the field
+// :36:29: note: default value set here
+// :46:12: error: value stored in comptime field does not match the default value of the field
+// :55:25: error: value stored in comptime field does not match the default value of the field
+// :68:36: error: value stored in comptime field does not match the default value of the field
+// :61:30: error: value stored in comptime field does not match the default value of the field
+// :59:29: note: default value set here
test/cases/compile_errors/invalid_struct_field.zig
@@ -8,6 +8,7 @@ export fn f() void {
export fn g() void {
var a: A = undefined;
const y = a.bar;
+ _ = &a;
_ = y;
}
export fn e() void {
@@ -26,5 +27,5 @@ export fn e() void {
// :1:11: note: struct declared here
// :10:17: error: no field named 'bar' in struct 'tmp.A'
// :1:11: note: struct declared here
-// :18:45: error: no field named 'f' in struct 'tmp.e.B'
-// :14:15: note: struct declared here
+// :19:45: error: no field named 'f' in struct 'tmp.e.B'
+// :15:15: note: struct declared here
test/cases/compile_errors/issue_2032_compile_diagnostic_string_for_top_level_decl_type.zig
@@ -1,5 +1,5 @@
export fn entry() void {
- var foo: u32 = @This(){};
+ const foo: u32 = @This(){};
_ = foo;
}
@@ -7,5 +7,5 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :2:27: error: expected type 'u32', found 'tmp'
+// :2:29: error: expected type 'u32', found 'tmp'
// :1:1: note: struct declared here
test/cases/compile_errors/issue_3818_bitcast_from_parray-slice_to_u16.zig
@@ -4,7 +4,7 @@ export fn foo1() void {
_ = word;
}
export fn foo2() void {
- var bytes: []const u8 = &[_]u8{ 1, 2 };
+ const bytes: []const u8 = &[_]u8{ 1, 2 };
const word: u16 = @bitCast(bytes);
_ = word;
}
test/cases/compile_errors/issue_5618_coercion_of_optional_anyopaque_to_anyopaque_must_fail.zig
@@ -1,14 +1,14 @@
export fn foo() void {
var u: ?*anyopaque = null;
var v: *anyopaque = undefined;
- v = u;
+ v = (&u).*;
}
// error
// backend=stage2
// target=native
//
-// :4:9: error: expected type '*anyopaque', found '?*anyopaque'
-// :4:9: note: cannot convert optional to payload type
-// :4:9: note: consider using '.?', 'orelse', or 'if'
-// :4:9: note: '?*anyopaque' could have null values which are illegal in type '*anyopaque'
+// :4:13: error: expected type '*anyopaque', found '?*anyopaque'
+// :4:13: note: cannot convert optional to payload type
+// :4:13: note: consider using '.?', 'orelse', or 'if'
+// :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
@@ -1,5 +1,6 @@
export fn foo() void {
comptime var T: type = undefined;
+ _ = &T;
const S = struct { x: *T };
const I = @typeInfo(S);
_ = I;
@@ -9,4 +10,4 @@ export fn foo() void {
// backend=stage2
// target=native
//
-// :3:28: error: use of undefined value here causes undefined behavior
+// :4:28: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/load_vector_pointer_with_unknown_runtime_index.zig
@@ -3,7 +3,7 @@ export fn entry() void {
var i: u32 = 0;
var x = loadv(&v[i]);
- _ = x;
+ _ = .{ &i, &x };
}
fn loadv(ptr: anytype) i31 {
test/cases/compile_errors/memset_no_length.zig
@@ -1,9 +1,11 @@
export fn foo() void {
var ptr: [*]u8 = undefined;
+ _ = &ptr;
@memset(ptr, 123);
}
export fn bar() void {
var ptr: [*c]bool = undefined;
+ _ = &ptr;
@memset(ptr, true);
}
@@ -11,7 +13,7 @@ export fn bar() void {
// backend=stage2
// target=native
//
-// :3:5: error: unknown @memset length
-// :3:13: note: destination type '[*]u8' provides no length
-// :7:5: error: unknown @memset length
-// :7:13: note: destination type '[*c]bool' provides no length
+// :4:5: error: unknown @memset length
+// :4:13: note: destination type '[*]u8' provides no length
+// :9:5: error: unknown @memset length
+// :9:13: note: destination type '[*c]bool' provides no length
test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig
@@ -7,7 +7,7 @@ pub fn getGeo3DTex2D() Geo3DTex2D {
};
}
export fn entry() void {
- var geo_data = getGeo3DTex2D();
+ const geo_data = getGeo3DTex2D();
_ = geo_data;
}
test/cases/compile_errors/missing_else_clause.zig
@@ -14,7 +14,7 @@ fn h() void {
// https://github.com/ziglang/zig/issues/12743
const T = struct { oh_no: *u32 };
var x: T = if (false) {};
- _ = x;
+ _ = &x;
}
fn k(b: bool) void {
// block_ptr case
@@ -22,7 +22,7 @@ fn k(b: bool) void {
var x = if (b) blk: {
break :blk if (false) T{ .oh_no = 2 };
} else T{ .oh_no = 1 };
- _ = x;
+ _ = &x;
}
export fn entry() void {
f(true);
test/cases/compile_errors/missing_parameter_name_of_generic_function.zig
@@ -1,7 +1,7 @@
fn dump(anytype) void {}
export fn entry() void {
var a: u8 = 9;
- dump(a);
+ dump((&a).*);
}
// error
test/cases/compile_errors/misspelled_type_with_pointer_only_reference.zig
@@ -24,7 +24,7 @@ pub const JsonNode = struct {
fn foo() void {
var jll: JasonList = undefined;
jll.init(1234);
- var jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} };
+ const jd = JsonNode{ .kind = JsonType.JSONArray, .jobject = JsonOA.JSONArray{jll} };
_ = jd;
}
test/cases/compile_errors/mod_on_undefined_value.zig
@@ -1,6 +1,7 @@
comptime {
var a: i64 = undefined;
_ = a % a;
+ _ = &a;
}
// error
test/cases/compile_errors/mult_on_undefined_value.zig
@@ -1,5 +1,5 @@
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
_ = a * a;
}
test/cases/compile_errors/negate_on_undefined_value.zig
@@ -1,5 +1,5 @@
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
_ = -a;
}
test/cases/compile_errors/nested_vectors.zig
@@ -1,7 +1,7 @@
export fn entry() void {
const V1 = @Vector(4, u8);
const V2 = @Type(.{ .Vector = .{ .len = 4, .child = V1 } });
- var v: V2 = undefined;
+ const v: V2 = undefined;
_ = v;
}
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig
@@ -1,30 +1,30 @@
export fn entry1() void {
var m2 = &2;
- _ = m2;
+ _ = &m2;
}
export fn entry2() void {
var a = undefined;
- _ = a;
+ _ = &a;
}
export fn entry3() void {
var b = 1;
- _ = b;
+ _ = &b;
}
export fn entry4() void {
var c = 1.0;
- _ = c;
+ _ = &c;
}
export fn entry5() void {
var d = null;
- _ = d;
+ _ = &d;
}
export fn entry6(opaque_: *Opaque) void {
var e = opaque_.*;
- _ = e;
+ _ = &e;
}
export fn entry7() void {
var f = i32;
- _ = f;
+ _ = &f;
}
const Opaque = opaque {};
export fn entry8() void {
test/cases/compile_errors/non-integer_tag_type_to_enum.zig
@@ -3,7 +3,7 @@ const Foo = enum(f32) {
};
export fn entry() void {
var f: Foo = undefined;
- _ = f;
+ _ = &f;
}
// error
test/cases/compile_errors/non_void_error_union_payload_ignored.zig
@@ -5,6 +5,7 @@ pub export fn entry1() void {
} else |_| {
// bar
}
+ _ = &x;
}
pub export fn entry2() void {
var x: anyerror!usize = 5;
@@ -13,6 +14,7 @@ pub export fn entry2() void {
} else |_| {
// bar
}
+ _ = &x;
}
// error
@@ -21,5 +23,5 @@ pub export fn entry2() void {
//
// :3:5: error: error union payload is ignored
// :3:5: note: payload value can be explicitly ignored with '|_|'
-// :11:5: error: error union payload is ignored
-// :11:5: note: payload value can be explicitly ignored with '|_|'
+// :12:5: error: error union payload is ignored
+// :12:5: note: payload value can be explicitly ignored with '|_|'
test/cases/compile_errors/not_an_enum_type.zig
@@ -1,6 +1,6 @@
export fn entry() void {
var self: Error = undefined;
- switch (self) {
+ switch ((&self).*) {
InvalidToken => |x| return x.token,
ExpectedVarDeclOrFn => |x| return x.token,
}
test/cases/compile_errors/or_on_undefined_value.zig
@@ -1,5 +1,6 @@
comptime {
var a: bool = undefined;
+ _ = &a;
_ = a or a;
}
@@ -7,4 +8,4 @@ comptime {
// backend=stage2
// target=native
//
-// :3:9: error: use of undefined value here causes undefined behavior
+// :4:9: error: use of undefined value here causes undefined behavior
test/cases/compile_errors/orelse_on_undefined_value.zig
@@ -1,5 +1,5 @@
comptime {
- var a: ?bool = undefined;
+ const a: ?bool = undefined;
_ = a orelse false;
}
test/cases/compile_errors/out_of_bounds_index.zig
@@ -1,29 +1,29 @@
comptime {
var array = [_:0]u8{ 1, 2, 3, 4 };
var src_slice: [:0]u8 = &array;
- var slice = src_slice[2..6];
+ const slice = src_slice[2..6];
_ = slice;
}
comptime {
var array = [_:0]u8{ 1, 2, 3, 4 };
- var slice = array[2..6];
+ const slice = array[2..6];
_ = slice;
}
comptime {
var array = [_]u8{ 1, 2, 3, 4 };
- var slice = array[2..5];
+ const slice = array[2..5];
_ = slice;
}
comptime {
var array = [_:0]u8{ 1, 2, 3, 4 };
- var slice = array[3..2];
+ const slice = array[3..2];
_ = slice;
}
// error
// target=native
//
-// :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
-// :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
-// :14:26: error: end index 5 out of bounds for array of length 4
-// :19:23: error: start index 3 is larger than end index 2
+// :4:32: error: end index 6 out of bounds for slice of length 4 +1 (sentinel)
+// :9:28: error: end index 6 out of bounds for array of length 4 +1 (sentinel)
+// :14:28: error: end index 5 out of bounds for array of length 4
+// :19:25: error: start index 3 is larger than end index 2
test/cases/compile_errors/overflow_in_enum_value_allocation.zig
@@ -3,7 +3,7 @@ const Moo = enum(u8) {
Over,
};
pub export fn entry() void {
- var y = Moo.Last;
+ const y = Moo.Last;
_ = y;
}
test/cases/compile_errors/packed_union_given_enum_tag_type.zig
@@ -9,7 +9,7 @@ const Payload = packed union(Letter) {
C: bool,
};
export fn entry() void {
- var a = Payload{ .A = 1234 };
+ const a: Payload = .{ .A = 1234 };
_ = a;
}
test/cases/compile_errors/packed_union_with_automatic_layout_field.zig
@@ -7,7 +7,7 @@ const Payload = packed union {
B: bool,
};
export fn entry() void {
- var a = Payload{ .B = true };
+ const a: Payload = .{ .B = true };
_ = a;
}
test/cases/compile_errors/pointer_arithmetic_on_pointer-to-array.zig
@@ -1,7 +1,7 @@
export fn foo() void {
var x: [10]u8 = undefined;
- var y = &x;
- var z = y + 1;
+ const y = &x;
+ const z = y + 1;
_ = z;
}
@@ -9,6 +9,6 @@ export fn foo() void {
// backend=stage2
// target=native
//
-// :4:15: error: incompatible types: '*[10]u8' and 'comptime_int'
-// :4:13: note: type '*[10]u8' here
-// :4:17: note: type 'comptime_int' here
+// :4:17: error: incompatible types: '*[10]u8' and 'comptime_int'
+// :4:15: note: type '*[10]u8' here
+// :4:19: note: type 'comptime_int' here
test/cases/compile_errors/pointer_to_anyopaque_slice.zig
@@ -2,6 +2,7 @@ export fn x() void {
var a: *u32 = undefined;
var b: []anyopaque = undefined;
b = a;
+ _ = &a;
}
// error
test/cases/compile_errors/ptrFromInt_with_misaligned_address.zig
@@ -1,6 +1,6 @@
pub export fn entry() void {
var y: [*]align(4) u8 = @ptrFromInt(5);
- _ = y;
+ _ = &y;
}
// error
test/cases/compile_errors/recursive_inline_fn.zig
@@ -8,6 +8,7 @@ inline fn foo(x: i32) i32 {
pub export fn entry() void {
var x: i32 = 4;
+ _ = &x;
_ = foo(x) == 20;
}
@@ -32,4 +33,4 @@ pub export fn entry2() void {
// target=native
//
// :5:27: error: inline call is recursive
-// :23:10: error: inline call is recursive
+// :24:10: error: inline call is recursive
test/cases/compile_errors/reference_to_const_data.zig
@@ -5,10 +5,12 @@ export fn foo() void {
export fn bar() void {
var ptr = &@as(u32, 2);
ptr.* = 2;
+ _ = &ptr;
}
export fn baz() void {
var ptr = &true;
ptr.* = false;
+ _ = &ptr;
}
export fn qux() void {
const S = struct {
@@ -21,6 +23,7 @@ export fn qux() void {
export fn quux() void {
var x = &@returnAddress();
x.* = 6;
+ _ = &x;
}
// error
@@ -29,6 +32,6 @@ export fn quux() void {
//
// :3:8: error: cannot assign to constant
// :7:8: error: cannot assign to constant
-// :11:8: error: cannot assign to constant
-// :19:8: error: cannot assign to constant
-// :23:6: error: cannot assign to constant
+// :12:8: error: cannot assign to constant
+// :21:8: error: cannot assign to constant
+// :25:6: error: cannot assign to constant
test/cases/compile_errors/reify_typeOf_with_incompatible_arguments.zig
@@ -2,6 +2,7 @@ export fn entry() void {
var var_1: f32 = undefined;
var var_2: u32 = undefined;
_ = @TypeOf(var_1, var_2);
+ _ = .{ &var_1, &var_2 };
}
// error
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr.zig
@@ -1,5 +1,5 @@
export fn entry() void {
- var damn = Container{
+ const damn = Container{
.not_optional = getOptional(),
};
_ = damn;
test/cases/compile_errors/result_location_incompatibility_mismatching_handle_is_ptr_generic_call.zig
@@ -2,7 +2,7 @@ export fn entry() void {
var damn = Container{
.not_optional = getOptional(i32),
};
- _ = damn;
+ _ = &damn;
}
pub fn getOptional(comptime T: type) ?T {
return 0;
test/cases/compile_errors/runtime_assignment_to_comptime_struct_type.zig
@@ -5,6 +5,7 @@ const Foo = struct {
export fn f() void {
var x: u8 = 0;
const foo = Foo{ .Bar = x, .Baz = u8 };
+ _ = &x;
_ = foo;
}
test/cases/compile_errors/runtime_assignment_to_comptime_union_type.zig
@@ -4,6 +4,7 @@ const Foo = union {
};
export fn f() void {
var x: u8 = 0;
+ _ = &x;
const foo = Foo{ .Bar = x };
_ = foo;
}
@@ -12,5 +13,5 @@ export fn f() void {
// backend=stage2
// target=native
//
-// :7:23: error: unable to resolve comptime value
-// :7:23: note: initializer of comptime only union must be comptime-known
+// :8:23: error: unable to resolve comptime value
+// :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
@@ -8,7 +8,7 @@ export fn entry() void {
foo(Letter.A);
}
fn foo(l: Letter) void {
- var x: Value = l;
+ const x: Value = l;
_ = x;
}
@@ -16,6 +16,6 @@ fn foo(l: Letter) void {
// backend=stage2
// target=native
//
-// :11:20: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields
+// :11:22: error: runtime coercion from enum 'tmp.Letter' to union 'tmp.Value' which has non-void fields
// :3:5: note: field 'A' has type 'i32'
// :2:15: note: union declared here
test/cases/compile_errors/runtime_indexing_comptime_array.zig
@@ -13,12 +13,14 @@ pub export fn entry2() void {
const test_fns = [_]TestFn{ foo, bar };
var i: usize = 0;
_ = test_fns[i];
+ _ = &i;
}
pub export fn entry3() void {
const TestFn = fn () void;
const test_fns = [_]TestFn{ foo, bar };
var i: usize = 0;
_ = &test_fns[i];
+ _ = &i;
}
// error
// target=native
@@ -28,5 +30,5 @@ pub export fn entry3() void {
// :7:10: note: use '*const fn () void' for a function pointer type
// :15:18: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
// :15:17: note: use '*const fn () void' for a function pointer type
-// :21:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
-// :21:18: note: use '*const fn () void' for a function pointer type
+// :22:19: error: values of type '[2]fn () void' must be comptime-known, but index value is runtime-known
+// :22:18: note: use '*const fn () void' for a function pointer type
test/cases/compile_errors/runtime_to_comptime_num.zig
@@ -1,19 +1,23 @@
pub export fn entry() void {
var a: u32 = 0;
+ _ = &a;
_ = @as(comptime_int, a);
}
pub export fn entry2() void {
var a: u32 = 0;
+ _ = &a;
_ = @as(comptime_float, a);
}
pub export fn entry3() void {
comptime var aa: comptime_float = 0.0;
var a: f32 = 4;
+ _ = &a;
aa = a;
}
pub export fn entry4() void {
comptime var aa: comptime_int = 0.0;
var a: f32 = 4;
+ _ = &a;
aa = a;
}
@@ -21,11 +25,11 @@ pub export fn entry4() void {
// backend=stage2
// target=native
//
-// :3:27: error: unable to resolve comptime value
-// :3:27: note: value being casted to 'comptime_int' must be comptime-known
-// :7:29: error: unable to resolve comptime value
-// :7:29: note: value being casted to 'comptime_float' must be comptime-known
-// :12:10: error: unable to resolve comptime value
-// :12:10: note: value being casted to 'comptime_float' must be comptime-known
-// :17:10: error: unable to resolve comptime value
-// :17:10: note: value being casted to 'comptime_int' must be comptime-known
+// :4:27: error: unable to resolve comptime value
+// :4:27: note: value being casted to 'comptime_int' must be comptime-known
+// :9:29: error: unable to resolve comptime value
+// :9:29: note: value being casted to 'comptime_float' must be comptime-known
+// :15:10: error: unable to resolve comptime value
+// :15:10: note: value being casted to 'comptime_float' must be comptime-known
+// :21:10: error: unable to resolve comptime value
+// :21:10: note: value being casted to 'comptime_int' must be comptime-known
test/cases/compile_errors/runtime_value_in_switch_prong.zig
@@ -1,6 +1,6 @@
pub export fn entry() void {
var byte: u8 = 1;
- switch (byte) {
+ switch ((&byte).*) {
byte => {},
else => {},
}
test/cases/compile_errors/self_referential_struct_requires_comptime.zig
@@ -4,7 +4,7 @@ const S = struct {
};
pub export fn entry() void {
var s: S = undefined;
- _ = s;
+ _ = &s;
}
// error
test/cases/compile_errors/self_referential_union_requires_comptime.zig
@@ -4,7 +4,7 @@ const U = union {
};
pub export fn entry() void {
var u: U = undefined;
- _ = u;
+ _ = &u;
}
// error
test/cases/compile_errors/shift_by_negative_comptime_integer.zig
@@ -1,5 +1,5 @@
comptime {
- var a = 1 >> -1;
+ const a = 1 >> -1;
_ = a;
}
@@ -7,4 +7,4 @@ comptime {
// backend=stage2
// target=native
//
-// :2:18: error: shift by negative amount '-1'
+// :2:20: error: shift by negative amount '-1'
test/cases/compile_errors/shift_on_type_with_non-power-of-two_size.zig
@@ -2,18 +2,22 @@ export fn entry() void {
const S = struct {
fn a() void {
var x: u24 = 42;
+ _ = &x;
_ = x >> 24;
}
fn b() void {
var x: u24 = 42;
+ _ = &x;
_ = x << 24;
}
fn c() void {
var x: u24 = 42;
+ _ = &x;
_ = @shlExact(x, 24);
}
fn d() void {
var x: u24 = 42;
+ _ = &x;
_ = @shrExact(x, 24);
}
};
@@ -27,7 +31,7 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :5:22: error: shift amount '24' is too large for operand type 'u24'
-// :9:22: error: shift amount '24' is too large for operand type 'u24'
-// :13:30: error: shift amount '24' is too large for operand type 'u24'
-// :17:30: error: shift amount '24' is too large for operand type 'u24'
+// :6:22: error: shift amount '24' is too large for operand type 'u24'
+// :11:22: error: shift amount '24' is too large for operand type 'u24'
+// :16:30: error: shift amount '24' is too large for operand type 'u24'
+// :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
@@ -6,10 +6,12 @@ export fn entry1(x: u8) u8 {
}
export fn entry2() void {
var x: u5 = 1;
+ _ = &x;
_ = @shlExact(12345, x);
}
export fn entry3() void {
var x: u5 = 1;
+ _ = &x;
_ = @shrExact(12345, x);
}
@@ -19,5 +21,5 @@ export fn entry3() void {
//
// :2:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
// :5:17: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
-// :9:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
-// :13:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
+// :10:9: error: LHS of shift must be a fixed-width integer type, or RHS must be comptime-known
+// :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
@@ -1,7 +1,7 @@
export fn entry() void {
const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
- var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
+ const z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
_ = z;
}
@@ -9,6 +9,6 @@ export fn entry() void {
// backend=stage2
// target=native
//
-// :4:39: error: mask index '4' has out-of-bounds selection
-// :4:27: note: selected index '7' out of bounds of '@Vector(4, u32)'
-// :4:30: note: selections from the second vector are specified with negative numbers
+// :4:41: error: mask index '4' has out-of-bounds selection
+// :4:29: note: selected index '7' out of bounds of '@Vector(4, u32)'
+// :4:32: note: selections from the second vector are specified with negative numbers
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig
@@ -1,11 +1,10 @@
export fn foo() void {
const bytes align(@alignOf([]const u8)) = [1]u8{0xfa} ** 16;
- var value = @as(*const []const u8, @ptrCast(&bytes)).*;
- _ = value;
+ _ = @as(*const []const u8, @ptrCast(&bytes)).*;
}
// error
// backend=stage2
// target=native
//
-// :3:57: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not.
+// :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
@@ -1,11 +1,11 @@
comptime {
var x: [*c]u8 = null;
var runtime_len: usize = 0;
- var y = x[0..runtime_len];
- _ = y;
+ _ = &runtime_len;
+ _ = x[0..runtime_len];
}
// error
// target=native
//
-// :4:14: error: slice of null pointer
+// :5:10: error: slice of null pointer
test/cases/compile_errors/slice_sentinel_mismatch-2.zig
@@ -1,5 +1,5 @@
fn foo() [:0]u8 {
- var x: []u8 = undefined;
+ const x: []u8 = undefined;
return x;
}
comptime {
test/cases/compile_errors/specify_enum_tag_type_that_is_too_small.zig
@@ -7,8 +7,7 @@ const Small = enum(u2) {
};
export fn entry() void {
- var x = Small.One;
- _ = x;
+ _ = Small.One;
}
// error
test/cases/compile_errors/specify_non-integer_enum_tag_type.zig
@@ -5,7 +5,7 @@ const Small = enum(f32) {
};
export fn entry() void {
- var x = Small.One;
+ const x = Small.One;
_ = x;
}
test/cases/compile_errors/store_vector_pointer_with_unknown_runtime_index.zig
@@ -2,6 +2,7 @@ export fn entry() void {
var v: @Vector(4, i31) = [_]i31{ 1, 5, 3, undefined };
var i: u32 = 0;
+ _ = &i;
storev(&v[i], 42);
}
@@ -13,4 +14,4 @@ fn storev(ptr: anytype, val: i31) void {
// backend=llvm
// target=native
//
-// :9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i31'
+// :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,5 +1,5 @@
comptime {
- var a: i64 = undefined;
+ const a: i64 = undefined;
_ = a - a;
}
test/cases/compile_errors/switch_capture_incompatible_types.zig
@@ -1,7 +1,7 @@
export fn f() void {
const U = union(enum) { a: u32, b: *u8 };
var u: U = undefined;
- switch (u) {
+ switch ((&u).*) {
.a, .b => |val| _ = val,
}
}
@@ -9,7 +9,7 @@ export fn f() void {
export fn g() void {
const U = union(enum) { a: u64, b: u32 };
var u: U = undefined;
- switch (u) {
+ switch ((&u).*) {
.a, .b => |*ptr| _ = ptr,
}
}
test/cases/compile_errors/switch_on_enum_with_1_field_with_no_prongs.zig
@@ -1,7 +1,7 @@
const Foo = enum { M };
export fn entry() void {
- var f = Foo.M;
+ const f = Foo.M;
switch (f) {}
}
test/cases/compile_errors/switch_on_slice.zig
@@ -1,5 +1,6 @@
pub export fn entry() void {
var a: [:0]const u8 = "foo";
+ _ = &a;
switch (a) {
("--version"), ("version") => unreachable,
else => {},
@@ -10,4 +11,4 @@ pub export fn entry() void {
// backend=stage2
// target=native
//
-// :3:13: error: switch on type '[:0]const u8'
+// :4:13: error: switch on type '[:0]const u8'
test/cases/compile_errors/switch_ranges_endpoints_are_validated.zig
@@ -1,12 +1,12 @@
pub export fn entry1() void {
- var x: i32 = 0;
+ const x: i32 = 0;
switch (x) {
6...1 => {},
else => unreachable,
}
}
pub export fn entr2() void {
- var x: i32 = 0;
+ const x: i32 = 0;
switch (x) {
-1...-5 => {},
else => unreachable,
test/cases/compile_errors/switch_with_overlapping_case_ranges.zig
@@ -1,6 +1,6 @@
export fn entry() void {
var q: u8 = 0;
- switch (q) {
+ switch ((&q).*) {
1...2 => {},
0...255 => {},
}
test/cases/compile_errors/switching_with_exhaustive_enum_has___prong_.zig
@@ -3,7 +3,7 @@ const E = enum {
b,
};
pub export fn entry() void {
- var e: E = .b;
+ const e: E = .b;
switch (e) {
.a => {},
.b => {},
test/cases/compile_errors/switching_with_non-exhaustive_enums.zig
@@ -8,21 +8,21 @@ const U = union(E) {
b: u32,
};
pub export fn entry1() void {
- var e: E = .b;
+ const e: E = .b;
switch (e) { // error: switch not handling the tag `b`
.a => {},
_ => {},
}
}
pub export fn entry2() void {
- var e: E = .b;
+ const e: E = .b;
switch (e) { // error: switch on non-exhaustive enum must include `else` or `_` prong
.a => {},
.b => {},
}
}
pub export fn entry3() void {
- var u = U{ .a = 2 };
+ const u = U{ .a = 2 };
switch (u) { // error: `_` prong not allowed when switching on tagged union
.a => {},
.b => {},
test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig
@@ -3,14 +3,13 @@ const FloatInt = extern union {
Int: i32,
};
export fn entry() void {
- var fi = FloatInt{ .Float = 123.45 };
- var tagName = @tagName(fi);
- _ = tagName;
+ const fi: FloatInt = .{ .Float = 123.45 };
+ _ = @tagName(fi);
}
// error
// backend=stage2
// target=native
//
-// :7:19: error: union 'tmp.FloatInt' is untagged
+// :7:9: error: union 'tmp.FloatInt' is untagged
// :1:25: note: union declared here
test/cases/compile_errors/truncate_sign_mismatch.zig
@@ -1,25 +1,25 @@
export fn entry1() i8 {
var x: u32 = 10;
- return @truncate(x);
+ return @truncate((&x).*);
}
export fn entry2() u8 {
var x: i32 = -10;
- return @truncate(x);
+ return @truncate((&x).*);
}
export fn entry3() i8 {
comptime var x: u32 = 10;
- return @truncate(x);
+ return @truncate((&x).*);
}
export fn entry4() u8 {
comptime var x: i32 = -10;
- return @truncate(x);
+ return @truncate((&x).*);
}
// error
// backend=stage2
// target=native
//
-// :3:22: error: expected signed integer type, found 'u32'
-// :7:22: error: expected unsigned integer type, found 'i32'
-// :11:22: error: expected signed integer type, found 'u32'
-// :15:22: error: expected unsigned integer type, found 'i32'
+// :3:26: error: expected signed integer type, found 'u32'
+// :7:26: error: expected unsigned integer type, found 'i32'
+// :11:26: error: expected signed integer type, found 'u32'
+// :15:26: error: expected unsigned integer type, found 'i32'
test/cases/compile_errors/tuple_init_edge_cases.zig
@@ -1,49 +1,54 @@
pub export fn entry1() void {
const T = @TypeOf(.{ 123, 3 });
var b = T{ .@"1" = 3 };
- _ = b;
+ _ = &b;
var c = T{ 123, 3 };
- _ = c;
+ _ = &c;
var d = T{};
- _ = d;
+ _ = &d;
}
pub export fn entry2() void {
var a: u32 = 2;
+ _ = &a;
const T = @TypeOf(.{ 123, a });
var b = T{ .@"1" = 3 };
- _ = b;
+ _ = &b;
var c = T{ 123, 3 };
- _ = c;
+ _ = &c;
var d = T{};
- _ = d;
+ _ = &d;
}
pub export fn entry3() void {
var a: u32 = 2;
+ _ = &a;
const T = @TypeOf(.{ 123, a });
var b = T{ .@"0" = 123 };
- _ = b;
+ _ = &b;
}
comptime {
var a: u32 = 2;
+ _ = &a;
const T = @TypeOf(.{ 123, a });
var b = T{ .@"0" = 123 };
- _ = b;
+ _ = &b;
var c = T{ 123, 2 };
- _ = c;
+ _ = &c;
var d = T{};
- _ = d;
+ _ = &d;
}
pub export fn entry4() void {
var a: u32 = 2;
+ _ = &a;
const T = @TypeOf(.{ 123, a });
var b = T{ 123, 4, 5 };
- _ = b;
+ _ = &b;
}
pub export fn entry5() void {
var a: u32 = 2;
+ _ = &a;
const T = @TypeOf(.{ 123, a });
var b = T{ .@"0" = 123, .@"2" = 123, .@"1" = 123 };
- _ = b;
+ _ = &b;
}
pub const Consideration = struct {
curve: Curve,
@@ -64,9 +69,9 @@ pub export fn entry6() void {
// backend=stage2
// target=native
//
-// :17:14: error: missing tuple field with index 1
-// :23:14: error: missing tuple field with index 1
-// :39:14: error: expected at most 2 tuple fields; found 3
-// :45:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}'
-// :58:37: error: missing tuple field with index 3
-// :53:32: note: struct declared here
+// :18:14: error: missing tuple field with index 1
+// :25:14: error: missing tuple field with index 1
+// :43:14: error: expected at most 2 tuple fields; found 3
+// :50:30: error: index '2' out of bounds of tuple 'struct{comptime comptime_int = 123, u32}'
+// :63:37: error: missing tuple field with index 3
+// :58:32: note: struct declared here
test/cases/compile_errors/union_access_of_inactive_field.zig
@@ -5,6 +5,7 @@ const U = union {
comptime {
var u: U = .{ .a = {} };
const v = u.b;
+ _ = &u;
_ = v;
}
test/cases/compile_errors/union_auto-enum_value_already_taken.zig
@@ -6,7 +6,7 @@ const MultipleChoice = union(enum(u32)) {
E = 60,
};
export fn entry() void {
- var x = MultipleChoice{ .C = {} };
+ const x: MultipleChoice = .{ .C = {} };
_ = x;
}
test/cases/compile_errors/union_duplicate_enum_field.zig
@@ -5,7 +5,7 @@ const U = union(E) {
};
export fn foo() void {
- var u: U = .{ .a = 123 };
+ const u: U = .{ .a = 123 };
_ = u;
}
test/cases/compile_errors/union_enum_field_does_not_match_enum.zig
@@ -10,7 +10,7 @@ const Payload = union(Letter) {
D: bool,
};
export fn entry() void {
- var a = Payload{ .A = 1234 };
+ const a: Payload = .{ .A = 1234 };
_ = a;
}
test/cases/compile_errors/union_noreturn_field_initialized.zig
@@ -9,7 +9,7 @@ pub export fn entry1() void {
};
var a = U{ .b = undefined };
- _ = a;
+ _ = &a;
}
pub export fn entry2() void {
const U = union(enum) {
@@ -25,7 +25,7 @@ pub export fn entry3() void {
};
var e = @typeInfo(U).Union.tag_type.?.a;
var u: U = undefined;
- u = e;
+ u = (&e).*;
}
// error
@@ -38,6 +38,6 @@ pub export fn entry3() void {
// :19:10: error: cannot initialize 'noreturn' field of union
// :16:9: note: field 'a' declared here
// :15:15: note: union declared here
-// :28:9: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
+// :28:13: error: runtime coercion from enum '@typeInfo(tmp.entry3.U).Union.tag_type.?' to union 'tmp.entry3.U' which has a 'noreturn' field
// :23:9: note: 'noreturn' field here
// :22:15: note: union declared here
test/cases/compile_errors/union_runtime_coercion_from_enum.zig
@@ -11,7 +11,7 @@ fn foo() E {
}
export fn doTheTest() u64 {
var u: U = foo();
- return u.b;
+ return (&u).b;
}
// error
test/cases/compile_errors/uncreachable_else_prong_err_set.zig โ test/cases/compile_errors/unreachable_else_prong_err_set.zig
@@ -1,5 +1,6 @@
pub export fn complex() void {
var a: error{ Foo, Bar } = error.Foo;
+ _ = &a;
switch (a) {
error.Foo => unreachable,
error.Bar => unreachable,
@@ -11,6 +12,7 @@ pub export fn complex() void {
pub export fn simple() void {
var a: error{ Foo, Bar } = error.Foo;
+ _ = &a;
switch (a) {
error.Foo => unreachable,
error.Bar => unreachable,
@@ -22,4 +24,4 @@ pub export fn simple() void {
// backend=llvm
// target=native
//
-// :6:14: error: unreachable else prong; all cases already handled
+// :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
@@ -1,16 +1,15 @@
export fn entry() void {
var x: i32 = 1234;
var p: *i32 = &x;
- var pp: *?*i32 = &p;
+ const pp: *?*i32 = &p;
pp.* = null;
- var y = p.*;
- _ = y;
+ _ = p.*;
}
// error
// backend=stage2
// target=native
//
-// :4:22: error: expected type '*?*i32', found '**i32'
-// :4:22: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'
-// :4:22: note: mutable '*i32' allows illegal null values stored to type '?*i32'
+// :4:24: error: expected type '*?*i32', found '**i32'
+// :4:24: note: pointer type child '*i32' cannot cast into pointer type child '?*i32'
+// :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,7 +1,7 @@
var v = 25;
export fn entry() void {
var arr: [v]u8 = undefined;
- _ = arr;
+ _ = &arr;
}
// error
test/cases/compile_errors/variable_with_type_noreturn.zig
@@ -1,6 +1,6 @@
export fn entry9() void {
var z: noreturn = return;
- _ = z;
+ _ = &z;
}
// error
test/cases/compile_errors/variadic_arg_validation.zig
@@ -7,6 +7,7 @@ pub export fn entry() void {
pub export fn entry1() void {
var arr: [2]u8 = undefined;
_ = printf("%d\n", arr);
+ _ = &arr;
}
pub export fn entry2() void {
@@ -23,7 +24,7 @@ pub export fn entry3() void {
//
// :4:33: error: integer and float literals passed to variadic function must be casted to a fixed-size number type
// :9:24: error: arrays must be passed by reference to variadic function
-// :13:24: error: cannot pass 'u48' to variadic function
-// :13:24: note: only integers with 0 or power of two bits are extern compatible
-// :17:24: error: cannot pass 'void' to variadic function
-// :17:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
+// :14:24: error: cannot pass 'u48' to variadic function
+// :14:24: note: only integers with 0 or power of two bits are extern compatible
+// :18:24: error: cannot pass 'void' to variadic function
+// :18:24: note: 'void' is a zero bit type; for C 'void' use 'anyopaque'
test/cases/compile_errors/while_loop_body_expression_ignored.zig
@@ -6,18 +6,22 @@ export fn f1() void {
}
export fn f2() void {
var x: ?i32 = null;
+ _ = &x;
while (x) |_| returns();
}
export fn f3() void {
var x: anyerror!i32 = error.Bad;
+ _ = &x;
while (x) |_| returns() else |_| unreachable;
}
export fn f4() void {
var a = true;
+ _ = &a;
while (a) {} else true;
}
export fn f5() void {
var a = true;
+ _ = &a;
const foo = while (a) returns() else true;
_ = foo;
}
@@ -29,15 +33,15 @@ export fn f5() void {
// :5:25: error: value of type 'usize' ignored
// :5:25: note: all non-void values must be used
// :5:25: note: this error can be suppressed by assigning the value to '_'
-// :9:26: error: value of type 'usize' ignored
-// :9:26: note: all non-void values must be used
-// :9:26: note: this error can be suppressed by assigning the value to '_'
-// :13:26: error: value of type 'usize' ignored
-// :13:26: note: all non-void values must be used
-// :13:26: note: this error can be suppressed by assigning the value to '_'
-// :17:23: error: value of type 'bool' ignored
-// :17:23: note: all non-void values must be used
-// :17:23: note: this error can be suppressed by assigning the value to '_'
-// :21:34: error: value of type 'usize' ignored
-// :21:34: note: all non-void values must be used
-// :21:34: note: this error can be suppressed by assigning the value to '_'
+// :10:26: error: value of type 'usize' ignored
+// :10:26: note: all non-void values must be used
+// :10:26: note: this error can be suppressed by assigning the value to '_'
+// :15:26: error: value of type 'usize' ignored
+// :15:26: note: all non-void values must be used
+// :15:26: note: this error can be suppressed by assigning the value to '_'
+// :20:23: error: value of type 'bool' ignored
+// :20:23: note: all non-void values must be used
+// :20:23: note: this error can be suppressed by assigning the value to '_'
+// :25:34: error: value of type 'usize' ignored
+// :25:34: note: all non-void values must be used
+// :25:34: note: this error can be suppressed by assigning the value to '_'
test/cases/compile_errors/while_loop_break_value_ignored.zig
@@ -7,6 +7,7 @@ export fn f1() void {
while (a) {
break returns();
}
+ _ = &a;
}
export fn f2() void {
@@ -16,6 +17,7 @@ export fn f2() void {
break :outer returns();
}
}
+ _ = &x;
}
// error
@@ -24,5 +26,5 @@ export fn f2() void {
//
// :7:5: error: incompatible types: 'usize' and 'void'
// :8:22: note: type 'usize' here
-// :14:12: error: incompatible types: 'usize' and 'void'
-// :16:33: note: type 'usize' here
+// :15:12: error: incompatible types: 'usize' and 'void'
+// :17:33: note: type 'usize' here
test/cases/compile_errors/wrong_type_passed_to_panic.zig
@@ -1,5 +1,5 @@
export fn entry() void {
- var e = error.Foo;
+ const e = error.Foo;
@panic(e);
}
test/cases/llvm/blocks.zig
@@ -5,6 +5,7 @@ fn assert(ok: bool) void {
fn foo(ok: bool) i32 {
const val: i32 = blk: {
var x: i32 = 1;
+ _ = &x;
if (!ok) break :blk x + 9;
break :blk x + 19;
};
test/cases/llvm/f_segment_address_space_reading_and_writing.zig
@@ -35,6 +35,7 @@ pub fn main() void {
assert(getFs() == @intFromPtr(&test_value));
var test_ptr: *allowzero addrspace(.fs) u64 = @ptrFromInt(0);
+ _ = &test_ptr;
assert(test_ptr.* == 12345);
test_ptr.* = 98765;
assert(test_value == 98765);
test/cases/llvm/nested_blocks.zig
@@ -10,7 +10,7 @@ fn foo(ok: bool) i32 {
};
break :blk val2 + 10;
};
- return val;
+ return (&val).*;
}
pub fn main() void {
test/cases/llvm/optionals.zig
@@ -7,8 +7,10 @@ pub fn main() void {
var null_val: ?i32 = null;
var val1: i32 = opt_val.?;
+ _ = &val1;
const val1_1: i32 = opt_val.?;
var ptr_val1 = &(opt_val.?);
+ _ = &ptr_val1;
const ptr_val1_1 = &(opt_val.?);
var val2: i32 = null_val orelse 20;
@@ -16,9 +18,11 @@ pub fn main() void {
var value: i32 = 20;
var ptr_val2 = &(null_val orelse value);
+ _ = &ptr_val2;
const val3 = opt_val orelse 30;
var val3_var = opt_val orelse 30;
+ _ = &val3_var;
assert(val1 == 10);
assert(val1_1 == 10);
test/cases/llvm/simple_addition_and_subtraction.zig
@@ -4,6 +4,7 @@ fn add(a: i32, b: i32) i32 {
pub fn main() void {
var a: i32 = -5;
+ _ = &a;
const x = add(a, 7);
var y = add(2, 0);
y -= x;
test/cases/safety/@asyncCall with too small a frame.zig
@@ -13,8 +13,9 @@ pub fn main() !void {
}
var bytes: [1]u8 align(16) = undefined;
var ptr = other;
+ _ = &ptr;
var frame = @asyncCall(&bytes, {}, ptr, .{});
- _ = frame;
+ _ = &frame;
return error.TestFailed;
}
fn other() callconv(.Async) void {
test/cases/safety/@intCast to u0.zig
@@ -14,7 +14,7 @@ pub fn main() !void {
}
fn bar(one: u1, not_zero: i32) void {
- var x = one << @as(u0, @intCast(not_zero));
+ const x = one << @intCast(not_zero);
_ = x;
}
// run
test/cases/safety/@ptrFromInt address zero to non-optional byte-aligned pointer.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var zero: usize = 0;
- var b: *u8 = @ptrFromInt(zero);
+ _ = &zero;
+ const b: *u8 = @ptrFromInt(zero);
_ = b;
return error.TestFailed;
}
test/cases/safety/@ptrFromInt address zero to non-optional pointer.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var zero: usize = 0;
- var b: *i32 = @ptrFromInt(zero);
+ _ = &zero;
+ const b: *i32 = @ptrFromInt(zero);
_ = b;
return error.TestFailed;
}
test/cases/safety/@ptrFromInt with misaligned address.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var x: usize = 5;
- var y: [*]align(4) u8 = @ptrFromInt(x);
+ _ = &x;
+ const y: [*]align(4) u8 = @ptrFromInt(x);
_ = y;
return error.TestFailed;
}
test/cases/safety/@tagName on corrupted enum value.zig
@@ -16,7 +16,7 @@ const E = enum(u32) {
pub fn main() !void {
var e: E = undefined;
@memset(@as([*]u8, @ptrCast(&e))[0..@sizeOf(E)], 0x55);
- var n = @tagName(e);
+ const n = @tagName(e);
_ = n;
return error.TestFailed;
}
test/cases/safety/@tagName on corrupted union value.zig
@@ -16,8 +16,8 @@ const U = union(enum(u32)) {
pub fn main() !void {
var u: U = undefined;
@memset(@as([*]u8, @ptrCast(&u))[0..@sizeOf(U)], 0x55);
- var t: @typeInfo(U).Union.tag_type.? = u;
- var n = @tagName(t);
+ const t: @typeInfo(U).Union.tag_type.? = u;
+ const n = @tagName(t);
_ = n;
return error.TestFailed;
}
test/cases/safety/array slice sentinel mismatch non-scalar.zig
@@ -11,7 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
const S = struct { a: u32 };
var arr = [_]S{ .{ .a = 1 }, .{ .a = 2 } };
- var s = arr[0..1 :.{ .a = 1 }];
+ const s = arr[0..1 :.{ .a = 1 }];
_ = s;
return error.TestFailed;
}
test/cases/safety/exact division failure - vectors.zig
@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
- var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
- var b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 };
+ const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
+ const b: @Vector(4, i32) = [4]i32{ 111, 222, 333, 441 };
const x = divExact(a, b);
_ = x;
return error.TestFailed;
test/cases/safety/for_len_mismatch.zig
@@ -12,6 +12,7 @@ pub fn main() !void {
var runtime_i: usize = 1;
var j: usize = 3;
var slice = "too long";
+ _ = .{ &runtime_i, &j, &slice };
for (runtime_i..j, slice) |a, b| {
_ = a;
_ = b;
test/cases/safety/for_len_mismatch_three.zig
@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var slice: []const u8 = "hello";
+ _ = &slice;
for (10..20, slice, 20..30) |a, b, c| {
_ = a;
_ = b;
test/cases/safety/integer division by zero - vectors.zig
@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
std.process.exit(1);
}
pub fn main() !void {
- var a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
- var b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 };
+ const a: @Vector(4, i32) = [4]i32{ 111, 222, 333, 444 };
+ const b: @Vector(4, i32) = [4]i32{ 111, 0, 333, 444 };
const x = div0(a, b);
_ = x;
return error.TestFailed;
test/cases/safety/memcpy_alias.zig
@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var buffer = [2]u8{ 1, 2 } ** 5;
var len: usize = 5;
+ _ = &len;
@memcpy(buffer[0..len], buffer[4 .. 4 + len]);
}
// run
test/cases/safety/memcpy_len_mismatch.zig
@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var buffer = [2]u8{ 1, 2 } ** 5;
var len: usize = 5;
+ _ = &len;
@memcpy(buffer[0..len], buffer[len .. len + 4]);
}
// run
test/cases/safety/memset_slice_undefined_bytes.zig
@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var buffer = [6]u8{ 1, 2, 3, 4, 5, 6 };
var len = buffer.len;
+ _ = &len;
@memset(buffer[0..len], undefined);
var x: u8 = buffer[1];
x += buffer[2];
test/cases/safety/memset_slice_undefined_large.zig
@@ -10,6 +10,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var buffer = [6]i32{ 1, 2, 3, 4, 5, 6 };
var len = buffer.len;
+ _ = &len;
@memset(buffer[0..len], undefined);
var x: i32 = buffer[1];
x += buffer[2];
test/cases/safety/optional unwrap operator on C pointer.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var ptr: [*c]i32 = null;
- var b = ptr.?;
+ _ = &ptr;
+ const b = ptr.?;
_ = b;
return error.TestFailed;
}
test/cases/safety/optional unwrap operator on null pointer.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var ptr: ?*i32 = null;
- var b = ptr.?;
+ _ = &ptr;
+ const b = ptr.?;
_ = b;
return error.TestFailed;
}
test/cases/safety/pointer casting null to non-optional pointer.zig
@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var c_ptr: [*c]u8 = 0;
- var zig_ptr: *u8 = c_ptr;
+ _ = &c_ptr;
+ const zig_ptr: *u8 = c_ptr;
_ = zig_ptr;
return error.TestFailed;
}
test/cases/safety/resuming a non-suspended function which has been suspended and resumed.zig
@@ -10,7 +10,7 @@ fn foo() void {
global_frame = @frame();
}
var f = async bar(@frame());
- _ = f;
+ _ = &f;
std.os.exit(1);
}
test/cases/safety/resuming a non-suspended function which never been suspended.zig
@@ -7,7 +7,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
fn foo() void {
var f = async bar(@frame());
- _ = f;
+ _ = &f;
std.os.exit(1);
}
test/cases/safety/shift left by huge amount.zig
@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var x: u24 = 42;
var y: u5 = 24;
- var z = x >> y;
+ _ = .{ &x, &y };
+ const z = x >> y;
_ = z;
return error.TestFailed;
}
test/cases/safety/shift right by huge amount.zig
@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var x: u24 = 42;
var y: u5 = 24;
- var z = x << y;
+ _ = .{ &x, &y };
+ const z = x << y;
_ = z;
return error.TestFailed;
}
test/cases/safety/signed integer division overflow - vectors.zig
@@ -9,8 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
- var a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
- var b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
+ const a: @Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
+ const b: @Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
const x = div(a, b);
if (x[2] == 32767) return error.Whatever;
return error.TestFailed;
test/cases/safety/signed integer not fitting in cast to unsigned integer - widening.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var value: c_short = -1;
- var casted: u32 = @intCast(value);
+ _ = &value;
+ const casted: u32 = @intCast(value);
_ = casted;
return error.TestFailed;
}
test/cases/safety/signed-unsigned vector cast.zig
@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var x: @Vector(4, i32) = @splat(-2147483647);
- var y: @Vector(4, u32) = @intCast(x);
+ _ = &x;
+ const y: @Vector(4, u32) = @intCast(x);
_ = y;
return error.TestFailed;
}
test/cases/safety/slice start index greater than end index.zig
@@ -11,6 +11,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var a: usize = 1;
var b: usize = 10;
+ _ = .{ &a, &b };
var buf: [16]u8 = undefined;
const slice = buf[b..a];
test/cases/safety/slice with sentinel out of bounds - runtime len.zig
@@ -12,6 +12,7 @@ pub fn main() !void {
var buf = [4]u8{ 'a', 'b', 'c', 0 };
const input: []u8 = &buf;
var len: usize = 4;
+ _ = &len;
const slice = input[0..len :0];
_ = slice;
return error.TestFailed;
test/cases/safety/slicing null C pointer - runtime len.zig
@@ -11,7 +11,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var ptr: [*c]const u32 = null;
var len: usize = 3;
- var slice = ptr[0..len];
+ _ = &len;
+ const slice = ptr[0..len];
_ = slice;
return error.TestFailed;
}
test/cases/safety/slicing null C pointer.zig
@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var ptr: [*c]const u32 = null;
- var slice = ptr[0..3];
+ _ = &ptr;
+ const slice = ptr[0..3];
_ = slice;
return error.TestFailed;
}
test/cases/safety/truncating vector cast.zig
@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var x: @Vector(4, u32) = @splat(0xdeadbeef);
- var y: @Vector(4, u16) = @intCast(x);
+ _ = &x;
+ const y: @Vector(4, u16) = @intCast(x);
_ = y;
return error.TestFailed;
}
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig
@@ -9,7 +9,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var value: u8 = 245;
- var casted: i8 = @intCast(value);
+ _ = &value;
+ const casted: i8 = @intCast(value);
_ = casted;
return error.TestFailed;
}
test/cases/safety/unsigned-signed vector cast.zig
@@ -10,7 +10,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
pub fn main() !void {
var x: @Vector(4, u32) = @splat(0x80000000);
- var y: @Vector(4, i32) = @intCast(x);
+ _ = &x;
+ const y: @Vector(4, i32) = @intCast(x);
_ = y;
return error.TestFailed;
}
test/cases/safety/vector integer addition overflow.zig
@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
std.process.exit(1);
}
pub fn main() !void {
- var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
- var b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
+ const a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
+ const b: @Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
const x = add(a, b);
_ = x;
return error.TestFailed;
test/cases/safety/vector integer multiplication overflow.zig
@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
std.process.exit(1);
}
pub fn main() !void {
- var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
- var b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
+ const a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
+ const b: @Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
const x = mul(b, a);
_ = x;
return error.TestFailed;
test/cases/safety/vector integer negation overflow.zig
@@ -9,6 +9,7 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
}
pub fn main() !void {
var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
+ _ = &a;
const x = neg(a);
_ = x;
return error.TestFailed;
test/cases/safety/vector integer subtraction overflow.zig
@@ -8,8 +8,8 @@ pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usi
std.process.exit(1);
}
pub fn main() !void {
- var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
- var b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
+ const a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
+ const b: @Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
const x = sub(b, a);
_ = x;
return error.TestFailed;
test/cases/adding_numbers_at_runtime_and_comptime.2.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var x: usize = 3;
+ _ = &x;
const y = add(1, 2, x);
if (y - 6 != 0) unreachable;
}
test/cases/array_in_anon_struct.zig
@@ -2,6 +2,7 @@ const std = @import("std");
noinline fn outer() u32 {
var a: u32 = 42;
+ _ = &a;
return inner(.{
.unused = a,
.value = [1]u32{0},
test/cases/assert_function.17.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: u64 = 0xFFEEDDCCBBAA9988;
+ _ = &i;
assert(i == 0xFFEEDDCCBBAA9988);
}
test/cases/bad_inferred_variable_type.zig
@@ -1,6 +1,6 @@
pub fn main() void {
var x = null;
- _ = x;
+ _ = &x;
}
// error
test/cases/binary_operands.1.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: i32 = 2147483647;
+ _ = &i;
if (i +% 1 != -2147483648) unreachable;
return;
}
test/cases/binary_operands.10.zig
@@ -2,6 +2,7 @@ pub fn main() void {
var i: u32 = 5;
i *= 7;
var result: u32 = foo(i, 10);
+ _ = &result;
if (result != 350) unreachable;
return;
}
test/cases/binary_operands.11.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: i32 = 2147483647;
+ _ = &i;
const result = i *% 2;
if (result != -2) unreachable;
return;
test/cases/binary_operands.12.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: u3 = 3;
+ _ = &i;
if (i *% 3 != 1) unreachable;
return;
}
test/cases/binary_operands.13.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: i4 = 3;
+ _ = &i;
if (i *% 3 != -7) unreachable;
return;
}
test/cases/binary_operands.14.zig
@@ -1,7 +1,7 @@
pub fn main() void {
var i: u32 = 352;
i /= 7; // i = 50
- var result: u32 = foo(i, 7);
+ const result: u32 = foo(i, 7);
if (result != 7) unreachable;
return;
}
test/cases/binary_operands.2.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: i4 = 7;
+ _ = &i;
if (i +% 1 != -8) unreachable;
return;
}
test/cases/binary_operands.3.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var i: u8 = 255;
+ _ = &i;
return i +% 1;
}
test/cases/binary_operands.4.zig
@@ -1,7 +1,7 @@
pub fn main() u8 {
var i: u8 = 5;
i += 20;
- var result: u8 = foo(i, 10);
+ const result: u8 = foo(i, 10);
return result - 35;
}
fn foo(x: u8, y: u8) u8 {
test/cases/binary_operands.6.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: i32 = -2147483648;
+ _ = &i;
if (i -% 1 != 2147483647) unreachable;
return;
}
test/cases/binary_operands.7.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: i7 = -64;
+ _ = &i;
if (i -% 1 != 63) unreachable;
return;
}
test/cases/binary_operands.8.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var i: u4 = 0;
+ _ = &i;
if (i -% 1 != 15) unreachable;
}
test/cases/binary_operands.9.zig
@@ -2,6 +2,7 @@ pub fn main() u8 {
var i: u8 = 5;
i -= 3;
var result: u8 = foo(i, 10);
+ _ = &result;
return result - 8;
}
fn foo(x: u8, y: u8) u8 {
test/cases/comparison_of_non-tagged_union_and_enum_literal.zig
@@ -2,7 +2,8 @@ export fn entry() void {
const U = union { A: u32, B: u64 };
var u = U{ .A = 42 };
var ok = u == .A;
- _ = ok;
+ _ = &u;
+ _ = &ok;
}
// error
test/cases/compile_log.0.zig
@@ -4,7 +4,7 @@ export fn _start() noreturn {
@compileLog(b, 20, f, x);
@compileLog(1000);
var bruh: usize = true;
- _ = bruh;
+ _ = .{ &f, &bruh };
unreachable;
}
export fn other() void {
test/cases/compile_log.1.zig
@@ -1,6 +1,7 @@
export fn _start() noreturn {
const b = true;
var f: u32 = 1;
+ _ = &f;
@compileLog(b, 20, f, x);
@compileLog(1000);
unreachable;
test/cases/comptime_var.0.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var a: u32 = 0;
+ _ = &a;
comptime var b: u32 = 0;
if (a == 0) b = 3;
}
@@ -9,5 +10,5 @@ pub fn main() void {
// target=x86_64-macos,x86_64-linux
// link_libc=true
//
-// :4:19: error: store to comptime variable depends on runtime condition
-// :4:11: note: runtime condition here
+// :5:19: error: store to comptime variable depends on runtime condition
+// :5:11: note: runtime condition here
test/cases/comptime_var.1.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var a: u32 = 0;
+ _ = &a;
comptime var b: u32 = 0;
switch (a) {
0 => {},
test/cases/comptime_var.5.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var a: u32 = 0;
+ _ = &a;
if (a == 0) {
comptime var b: u32 = 0;
b = 1;
test/cases/conditions.5.zig
@@ -10,6 +10,7 @@ fn assert(ok: bool) void {
fn foo(ok: bool) i32 {
const val: i32 = blk: {
var x: i32 = 1;
+ _ = &x;
if (!ok) break :blk x + @as(i32, 9);
break :blk x + @as(i32, 19);
};
test/cases/decl_value_arena.zig
@@ -14,7 +14,7 @@ pub const Connection = struct {
pub fn main() void {
var conn: Connection = undefined;
- _ = conn;
+ _ = &conn;
}
// run
test/cases/enum_values.0.zig
@@ -4,8 +4,8 @@ pub fn main() void {
var number1 = Number.One;
var number2: Number = .Two;
if (false) {
- number1;
- number2;
+ &number1;
+ &number2;
}
const number3: Number = @enumFromInt(2);
if (@intFromEnum(number3) != 2) {
test/cases/enum_values.1.zig
@@ -2,7 +2,9 @@ const Number = enum { One, Two, Three };
pub fn main() void {
var number1 = Number.One;
+ _ = &number1;
var number2: Number = .Two;
+ _ = &number2;
const number3: Number = @enumFromInt(2);
assert(number1 != number2);
assert(number2 != number3);
@@ -10,6 +12,7 @@ pub fn main() void {
assert(@intFromEnum(number2) == 1);
assert(@intFromEnum(number3) == 2);
var x: Number = .Two;
+ _ = &x;
assert(number2 == x);
return;
test/cases/error_in_nested_declaration.zig
@@ -19,7 +19,7 @@ const S2 = struct {
pub export fn entry2() void {
var s: S2 = undefined;
- _ = s;
+ _ = &s;
}
// error
test/cases/error_unions.0.zig
@@ -1,6 +1,7 @@
pub fn main() void {
var e1 = error.Foo;
var e2 = error.Bar;
+ _ = .{ &e1, &e2 };
assert(e1 != e2);
assert(e1 == error.Foo);
assert(e2 == error.Bar);
test/cases/error_unions.1.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var e: anyerror!u8 = 5;
+ _ = &e;
const i = e catch 10;
return i - 5;
}
test/cases/error_unions.2.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var e: anyerror!u8 = error.Foo;
+ _ = &e;
const i = e catch 10;
return i - 10;
}
test/cases/error_unions.3.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var e = foo();
+ _ = &e;
const i = e catch 69;
return i - 5;
}
test/cases/error_unions.4.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var e = foo();
+ _ = &e;
const i = e catch 69;
return i - 69;
}
test/cases/error_unions.5.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var e = foo();
+ _ = &e;
const i = e catch 42;
return i - 42;
}
test/cases/f32_passed_to_variadic_fn.zig
@@ -2,8 +2,8 @@ extern fn printf(format: [*:0]const u8, ...) c_int;
pub fn main() void {
var a: f64 = 2.0;
var b: f32 = 10.0;
- _ = printf("f64: %f\n", a);
- _ = printf("f32: %f\n", b);
+ _ = printf("f64: %f\n", (&a).*);
+ _ = printf("f32: %f\n", (&b).*);
}
// run
test/cases/inner_func_accessing_outer_var.zig
@@ -1,5 +1,6 @@
pub fn f() void {
var bar: bool = true;
+ _ = &bar;
const S = struct {
fn baz() bool {
return bar;
@@ -10,6 +11,6 @@ pub fn f() void {
// error
//
-// :5:20: error: mutable 'bar' not accessible from here
+// :6:20: error: mutable 'bar' not accessible from here
// :2:9: note: declared mutable here
-// :3:15: note: crosses namespace boundary here
+// :4:15: note: crosses namespace boundary here
test/cases/locals.0.zig
@@ -3,8 +3,8 @@ pub fn main() void {
var y: f32 = 42.0;
var x: u8 = 10;
if (false) {
- y;
- x;
+ &y;
+ &x / &i;
}
if (i != 5) unreachable;
}
test/cases/locals.1.zig
@@ -1,8 +1,9 @@
pub fn main() void {
var i: u8 = 5;
var y: f32 = 42.0;
- _ = y;
+ _ = &y;
var x: u8 = 10;
+ _ = &x;
foo(i, x);
i = x;
if (i != 10) unreachable;
test/cases/multiplying_numbers_at_runtime_and_comptime.2.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var x: usize = 5;
+ _ = &x;
const y = mul(2, 3, x);
if (y - 30 != 0) unreachable;
}
test/cases/only_1_function_and_it_gets_updated.1.zig
@@ -1,6 +1,6 @@
pub export fn _start() noreturn {
var dummy: u32 = 10;
- _ = dummy;
+ _ = &dummy;
while (true) {}
}
test/cases/optionals.0.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var x: ?u8 = 5;
+ _ = &x;
var y: u8 = 0;
if (x) |val| {
y = val;
test/cases/optionals.1.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var x: ?u8 = null;
+ _ = &x;
var y: u8 = 0;
if (x) |val| {
y = val;
test/cases/optionals.2.zig
@@ -1,5 +1,6 @@
pub fn main() u8 {
var x: ?u8 = 5;
+ _ = &x;
return x.? - 5;
}
test/cases/optionals.3.zig
@@ -1,6 +1,7 @@
pub fn main() u8 {
var x: u8 = 5;
var y: ?u8 = x;
+ _ = .{ &x, &y };
return y.? - 5;
}
test/cases/runtime_bitwise_and.zig
@@ -7,6 +7,7 @@ pub fn main() void {
var m2: u32 = 0b0000;
assert(m1 & 0b1010 == 0b1010);
assert(m2 & 0b1010 == 0b0000);
+ _ = .{ &i, &j, &m1, &m2 };
}
fn assert(b: bool) void {
if (!b) unreachable;
test/cases/runtime_bitwise_or.zig
@@ -7,6 +7,7 @@ pub fn main() void {
var m2: u32 = 0b0000;
assert(m1 | 0b1010 == 0b1111);
assert(m2 | 0b1010 == 0b1010);
+ _ = .{ &i, &j, &m1, &m2 };
}
fn assert(b: bool) void {
if (!b) unreachable;
test/cases/structs.0.zig
@@ -2,6 +2,7 @@ const Example = struct { x: u8 };
pub fn main() u8 {
var example: Example = .{ .x = 5 };
+ _ = &example;
return example.x - 5;
}
test/cases/structs.2.zig
@@ -2,6 +2,7 @@ const Example = struct { x: u8, y: u8 };
pub fn main() u8 {
var example: Example = .{ .x = 5, .y = 10 };
+ _ = &example;
return example.y + example.x - 15;
}
test/cases/structs.3.zig
@@ -3,6 +3,7 @@ const Example = struct { x: u8, y: u8 };
pub fn main() u8 {
var example: Example = .{ .x = 5, .y = 10 };
var example2: Example = .{ .x = 10, .y = 20 };
+ _ = &example2;
example = example2;
return example.y + example.x - 30;
test/cases/switch.0.zig
@@ -1,6 +1,7 @@
pub fn main() u8 {
var val: u8 = 1;
- var a: u8 = switch (val) {
+ _ = &val;
+ const a: u8 = switch (val) {
0, 1 => 2,
2 => 3,
3 => 4,
test/cases/switch.1.zig
@@ -1,11 +1,13 @@
pub fn main() u8 {
var val: u8 = 2;
+ _ = &val;
var a: u8 = switch (val) {
0, 1 => 2,
2 => 3,
3 => 4,
else => 5,
};
+ _ = &a;
return a - 3;
}
test/cases/switch.2.zig
@@ -1,6 +1,7 @@
pub fn main() u8 {
var val: u8 = 10;
- var a: u8 = switch (val) {
+ _ = &val;
+ const a: u8 = switch (val) {
0, 1 => 2,
2 => 3,
3 => 4,
test/cases/switch.3.zig
@@ -2,7 +2,8 @@ const MyEnum = enum { One, Two, Three };
pub fn main() u8 {
var val: MyEnum = .Two;
- var a: u8 = switch (val) {
+ _ = &val;
+ const a: u8 = switch (val) {
.One => 1,
.Two => 2,
.Three => 3,
test/cases/type_of.0.zig
@@ -1,5 +1,6 @@
pub fn main() void {
var x: usize = 0;
+ _ = &x;
const z = @TypeOf(x, @as(u128, 5));
assert(z == u128);
}
test/cases/while_loops.1.zig
@@ -2,6 +2,7 @@ pub fn main() u8 {
var i: u8 = 0;
while (i < @as(u8, 10)) {
var x: u8 = 1;
+ _ = &x;
i += x;
}
return i - 10;
test/cases/while_loops.2.zig
@@ -2,6 +2,7 @@ pub fn main() u8 {
var i: u8 = 0;
while (i < @as(u8, 10)) {
var x: u8 = 1;
+ _ = &x;
i += x;
if (i == @as(u8, 5)) break;
}