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

This commit is contained in:
mlugg
2023-11-11 07:27:31 +00:00
parent 2c1acb6180
commit 21fa187abc
289 changed files with 671 additions and 489 deletions

View File

@@ -6,7 +6,7 @@ const S2 = struct {
};
pub export fn entry() void {
var s: S1 = undefined;
_ = s;
_ = &s;
}
// error

View File

@@ -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;
}

View File

@@ -1,7 +1,7 @@
export fn a() void {
var x: *anyopaque = undefined;
var y: [*c]anyopaque = x;
_ = y;
_ = .{ &x, &y };
}
// error

View File

@@ -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;
}

View File

@@ -1,5 +1,5 @@
comptime {
var a: i64 = undefined;
const a: i64 = undefined;
_ = a + a;
}

View File

@@ -6,7 +6,7 @@ const Number = enum {
// zig fmt: on
export fn entry1() void {
var x: Number = undefined;
const x: Number = undefined;
_ = x;
}

View File

@@ -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'

View File

@@ -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

View File

@@ -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];
}

View File

@@ -1,6 +1,6 @@
export fn foo() void {
var b: u8[40] = undefined;
_ = b;
_ = &b;
}
// error

View File

@@ -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'

View File

@@ -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},

View File

@@ -1,6 +1,6 @@
export fn entry() void {
var a = &b;
_ = a;
_ = &a;
}
inline fn b() void {}

View File

@@ -9,7 +9,7 @@ export fn constEntry() u32 {
export fn varEntry() u32 {
var x: u32 = g();
return x;
return (&x).*;
}
// error

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -3,7 +3,7 @@ export fn entry() void {
}
fn amain() callconv(.Async) void {
var x: [@sizeOf(@Frame(amain))]u8 = undefined;
_ = x;
_ = &x;
}
// error

View File

@@ -6,7 +6,7 @@ fn amain() callconv(.Async) void {
}
fn other() void {
var x: [@sizeOf(@Frame(amain))]u8 = undefined;
_ = x;
_ = &x;
}
// error

View File

@@ -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 {}

View File

@@ -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 {}

View File

@@ -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

View File

@@ -1,7 +1,7 @@
export fn entry() void {
var frame = async func();
var result = await frame;
_ = result;
_ = &result;
}
fn func() void {
suspend {}

View File

@@ -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 {}

View File

@@ -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 {}

View File

@@ -4,6 +4,7 @@ export fn entry() void {
fn amain() void {
var ptr = afunc;
_ = ptr();
_ = &ptr;
}
fn afunc() callconv(.Async) void {}

View File

@@ -1,6 +1,7 @@
export fn entry() void {
var ptr = afunc;
_ = async ptr();
_ = &ptr;
}
fn afunc() callconv(.Async) void {}

View File

@@ -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

View File

@@ -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'

View File

@@ -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'

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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'

View File

@@ -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'

View File

@@ -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;
}

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +1,5 @@
comptime {
var a: anyerror!bool = undefined;
const a: anyerror!bool = undefined;
if (a catch false) {}
}

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -3,7 +3,7 @@ const Foo = struct {
b: i32,
};
export fn entry() void {
var x = Foo{
const x: Foo = .{
.b = 5,
};
_ = x;

View File

@@ -1,5 +1,5 @@
comptime {
var opt_ptr: ?*i32 = null;
const opt_ptr: ?*i32 = null;
const ptr: *i32 = @ptrCast(opt_ptr);
_ = ptr;
}

View File

@@ -1,6 +1,7 @@
comptime {
var undef_ptr: *i32 = undefined;
const ptr: *i32 = @ptrCast(undef_ptr);
_ = &undef_ptr;
_ = ptr;
}

View File

@@ -6,7 +6,7 @@ const Value = union(Letter) {
};
export fn entry() void {
var x: Value = Letter.A;
_ = x;
_ = &x;
}
// error

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,7 +1,7 @@
comptime {
var a: []u8 = undefined;
var b = a[0..10];
_ = b;
_ = &b;
}
// error

View File

@@ -3,7 +3,7 @@ const Foo = struct {
};
export fn entry() void {
var f: Foo = undefined;
_ = f;
_ = &f;
}
// error

View File

@@ -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

View File

@@ -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;
}

View File

@@ -1,5 +1,5 @@
comptime {
var a: *u8 = undefined;
const a: *u8 = undefined;
_ = a.*;
}

View File

@@ -1,6 +1,7 @@
export fn entry() void {
var a: []u8 = undefined;
_ = a.*.len;
_ = &a;
}
// error

View File

@@ -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'

View File

@@ -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);

View File

@@ -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);

View File

@@ -1,6 +1,7 @@
comptime {
var a: i64 = undefined;
_ = a / a;
_ = &a;
}
// error

View File

@@ -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'

View File

@@ -1,5 +1,5 @@
export fn entry() void {
var x: u32 = 0;
const x: u32 = 0;
switch (x) {}
}

View File

@@ -1,7 +1,7 @@
pub export fn entry() void {
const E = enum(comptime_int) { a, b, c, _ };
var e: E = .a;
_ = e;
_ = &e;
}
// error

View File

@@ -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;

View File

@@ -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

View File

@@ -6,7 +6,7 @@ const MultipleChoice = enum(u32) {
E = 60,
};
export fn entry() void {
var x = MultipleChoice.C;
const x = MultipleChoice.C;
_ = x;
}

View File

@@ -4,7 +4,7 @@ pub export fn entry() void {
e: u8,
};
var a = .{@sizeOf(bitfield)};
_ = a;
_ = &a;
}
// error

View File

@@ -1,6 +1,6 @@
comptime {
const z = i32!i32;
var x: z = undefined;
const x: z = undefined;
_ = x;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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}'

View File

@@ -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'

View File

@@ -2,7 +2,7 @@ const Letter = extern union {
A,
};
export fn entry() void {
var a = Letter{ .A = {} };
const a: Letter = .{ .A = {} };
_ = a;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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'

View File

@@ -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

View File

@@ -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'

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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'

View File

@@ -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'

View File

@@ -7,7 +7,7 @@ const Small = enum(u2) {
export fn entry() void {
var x: u2 = Small.Two;
_ = x;
_ = &x;
}
// error

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +1,7 @@
pub export fn entry() void {
var a: *u32 = undefined;
_ = *a;
_ = &a;
}
// error

View File

@@ -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);
}

View File

@@ -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

View File

@@ -6,7 +6,7 @@ fn acceptRuntime(value: u64) void {
}
pub export fn entry() void {
var value: u64 = 0;
acceptRuntime(value);
acceptRuntime((&value).*);
}
// error

Some files were not shown because too many files have changed in this diff Show More