aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-09-13 13:50:25 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-09-13 13:50:25 -0700
commit0a4cfb81bcca0ca514758049f8d7d99224537f93 (patch)
tree1acc4e8c41a4c0f2a1c80f4864f23a5b16a374eb /test
parentf9859c102d7d54ce109ee7afdbd59251c233e92c (diff)
parentc25ce5bba0d00283ad4de9077dba5a8d5255b619 (diff)
downloadzig-0a4cfb81bcca0ca514758049f8d7d99224537f93.tar.gz
zig-0a4cfb81bcca0ca514758049f8d7d99224537f93.zip
Merge remote-tracking branch 'origin/master' into llvm15
Diffstat (limited to 'test')
-rw-r--r--test/behavior/bugs/11165.zig2
-rw-r--r--test/behavior/type.zig2
-rw-r--r--test/behavior/type_info.zig8
-rw-r--r--test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig1
-rw-r--r--test/cases/compile_errors/pointless discard.zig12
-rw-r--r--test/cases/type_of.0.zig1
-rw-r--r--test/translate_c.zig114
7 files changed, 71 insertions, 69 deletions
diff --git a/test/behavior/bugs/11165.zig b/test/behavior/bugs/11165.zig
index 60677743ad..828b7f2462 100644
--- a/test/behavior/bugs/11165.zig
+++ b/test/behavior/bugs/11165.zig
@@ -14,7 +14,6 @@ test "bytes" {
.a = undefined,
.c = "12345".*, // this caused problems
};
- _ = s_1;
var u_2 = U{ .s = s_1 };
_ = u_2;
@@ -35,7 +34,6 @@ test "aggregate" {
.a = undefined,
.c = c, // this caused problems
};
- _ = s_1;
var u_2 = U{ .s = s_1 };
_ = u_2;
diff --git a/test/behavior/type.zig b/test/behavior/type.zig
index 8cef86b5dd..f59ac7cb27 100644
--- a/test/behavior/type.zig
+++ b/test/behavior/type.zig
@@ -486,7 +486,6 @@ test "Type.Union from Type.Enum" {
.decls = &.{},
},
});
- _ = T;
_ = @typeInfo(T).Union;
}
@@ -505,7 +504,6 @@ test "Type.Union from regular enum" {
.decls = &.{},
},
});
- _ = T;
_ = @typeInfo(T).Union;
}
diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig
index 968c3e7490..76d67c8aec 100644
--- a/test/behavior/type_info.zig
+++ b/test/behavior/type_info.zig
@@ -425,12 +425,8 @@ fn generic2(comptime T: type, param: T, param2: u8) void {
_ = param;
_ = param2;
}
-fn generic3(param: anytype) @TypeOf(param) {
- _ = param;
-}
-fn generic4(comptime param: anytype) @TypeOf(param) {
- _ = param;
-}
+fn generic3(param: anytype) @TypeOf(param) {}
+fn generic4(comptime param: anytype) @TypeOf(param) {}
test "typeInfo with comptime parameter in struct fn def" {
const S = struct {
diff --git a/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig b/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig
index b5495480ed..0456bc9c8e 100644
--- a/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig
+++ b/test/cases/compile_errors/non-comptime-parameter-used-as-array-size.zig
@@ -6,7 +6,6 @@ export fn entry() void {
}
fn makeLlamas(count: usize) [count]u8 {
- _ = count;
}
// error
diff --git a/test/cases/compile_errors/pointless discard.zig b/test/cases/compile_errors/pointless discard.zig
new file mode 100644
index 0000000000..048bf8ac8d
--- /dev/null
+++ b/test/cases/compile_errors/pointless discard.zig
@@ -0,0 +1,12 @@
+export fn foo() void {
+ var x: i32 = 1234;
+ x += 1;
+ _ = x;
+}
+
+// error
+// backend=stage2
+// target=native
+//
+// :4:9: error: pointless discard of local variable
+// :3:5: note: used here
diff --git a/test/cases/type_of.0.zig b/test/cases/type_of.0.zig
index d8a97d1444..5f7702ef2c 100644
--- a/test/cases/type_of.0.zig
+++ b/test/cases/type_of.0.zig
@@ -1,6 +1,5 @@
pub fn main() void {
var x: usize = 0;
- _ = x;
const z = @TypeOf(x, @as(u128, 5));
assert(z == u128);
}
diff --git a/test/translate_c.zig b/test/translate_c.zig
index e54747046a..0e38444ad2 100644
--- a/test/translate_c.zig
+++ b/test/translate_c.zig
@@ -116,10 +116,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn foo() void {
\\ while (true) if (true) {
\\ var a: c_int = 1;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ } else {
\\ var b: c_int = 2;
- \\ _ = b;
+ \\ _ = @TypeOf(b);
\\ };
\\ if (true) if (true) {};
\\}
@@ -192,7 +192,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ .B = 0,
\\ .C = 0,
\\ };
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ {
\\ const struct_Foo_1 = extern struct {
\\ A: c_int,
@@ -204,7 +204,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ .B = 0,
\\ .C = 0,
\\ };
- \\ _ = a_2;
+ \\ _ = @TypeOf(a_2);
\\ }
\\}
});
@@ -233,24 +233,24 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ B: c_int,
\\ C: c_int,
\\ };
- \\ _ = union_unnamed_1;
+ \\ _ = @TypeOf(union_unnamed_1);
\\ const Foo = union_unnamed_1;
\\ var a: Foo = Foo{
\\ .A = @as(c_int, 0),
\\ };
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ {
\\ const union_unnamed_2 = extern union {
\\ A: c_int,
\\ B: c_int,
\\ C: c_int,
\\ };
- \\ _ = union_unnamed_2;
+ \\ _ = @TypeOf(union_unnamed_2);
\\ const Foo_1 = union_unnamed_2;
\\ var a_2: Foo_1 = Foo_1{
\\ .A = @as(c_int, 0),
\\ };
- \\ _ = a_2;
+ \\ _ = @TypeOf(a_2);
\\ }
\\}
});
@@ -318,7 +318,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ const bar_1 = struct {
\\ threadlocal var static: c_int = 2;
\\ };
- \\ _ = bar_1;
+ \\ _ = @TypeOf(bar_1);
\\ return 0;
\\}
});
@@ -337,7 +337,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\}
\\pub export fn bar() c_int {
\\ var a: c_int = 2;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ return 0;
\\}
\\pub export fn baz() c_int {
@@ -352,7 +352,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub export fn main() void {
\\ var a: c_int = @bitCast(c_int, @truncate(c_uint, @alignOf(c_int)));
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\}
});
@@ -500,7 +500,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2))
, &[_][]const u8{
\\pub const foo = blk: {
- \\ _ = foo;
+ \\ _ = @TypeOf(foo);
\\ break :blk bar;
\\};
,
@@ -724,7 +724,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn function(arg_opaque_1: ?*struct_opaque) void {
\\ var opaque_1 = arg_opaque_1;
\\ var cast: ?*struct_opaque_2 = @ptrCast(?*struct_opaque_2, opaque_1);
- \\ _ = cast;
+ \\ _ = @TypeOf(cast);
\\}
});
@@ -761,7 +761,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn my_fn() align(128) void {}
\\pub export fn other_fn() void {
\\ var ARR: [16]u8 align(16) = undefined;
- \\ _ = ARR;
+ \\ _ = @TypeOf(ARR);
\\}
});
}
@@ -798,17 +798,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub export fn foo() void {
\\ var a: c_int = undefined;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ var b: u8 = 123;
- \\ _ = b;
+ \\ _ = @TypeOf(b);
\\ const c: c_int = undefined;
- \\ _ = c;
+ \\ _ = @TypeOf(c);
\\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440));
- \\ _ = d;
+ \\ _ = @TypeOf(d);
\\ var e: c_int = 10;
- \\ _ = e;
+ \\ _ = @TypeOf(e);
\\ var f: c_uint = 10;
- \\ _ = f;
+ \\ _ = @TypeOf(f);
\\}
});
@@ -867,7 +867,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ const v2 = struct {
\\ const static: [5:0]u8 = "2.2.2".*;
\\ };
- \\ _ = v2;
+ \\ _ = @TypeOf(v2);
\\}
});
@@ -911,7 +911,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn bar() void {
\\ var func_ptr: ?*anyopaque = @ptrCast(?*anyopaque, foo);
\\ var typed_func_ptr: ?*const fn () callconv(.C) void = @intToPtr(?*const fn () callconv(.C) void, @intCast(c_ulong, @ptrToInt(func_ptr)));
- \\ _ = typed_func_ptr;
+ \\ _ = @TypeOf(typed_func_ptr);
\\}
});
}
@@ -1353,7 +1353,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub export fn foo() void {
\\ var a: c_int = undefined;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\}
});
@@ -1524,23 +1524,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ var p: ?*anyopaque = undefined;
\\ {
\\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));
- \\ _ = to_char;
+ \\ _ = @TypeOf(to_char);
\\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));
- \\ _ = to_short;
+ \\ _ = @TypeOf(to_short);
\\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));
- \\ _ = to_int;
+ \\ _ = @TypeOf(to_int);
\\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));
- \\ _ = to_longlong;
+ \\ _ = @TypeOf(to_longlong);
\\ }
\\ {
\\ var to_char: [*c]u8 = @ptrCast([*c]u8, @alignCast(@import("std").meta.alignment([*c]u8), p));
- \\ _ = to_char;
+ \\ _ = @TypeOf(to_char);
\\ var to_short: [*c]c_short = @ptrCast([*c]c_short, @alignCast(@import("std").meta.alignment([*c]c_short), p));
- \\ _ = to_short;
+ \\ _ = @TypeOf(to_short);
\\ var to_int: [*c]c_int = @ptrCast([*c]c_int, @alignCast(@import("std").meta.alignment([*c]c_int), p));
- \\ _ = to_int;
+ \\ _ = @TypeOf(to_int);
\\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@import("std").meta.alignment([*c]c_longlong), p));
- \\ _ = to_longlong;
+ \\ _ = @TypeOf(to_longlong);
\\ }
\\}
});
@@ -1786,11 +1786,11 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ var arr: [10]u8 = [1]u8{
\\ 1,
\\ } ++ [1]u8{0} ** 9;
- \\ _ = arr;
+ \\ _ = @TypeOf(arr);
\\ var arr1: [10][*c]u8 = [1][*c]u8{
\\ null,
\\ } ++ [1][*c]u8{null} ** 9;
- \\ _ = arr1;
+ \\ _ = @TypeOf(arr1);
\\}
});
@@ -2038,16 +2038,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub var c: c_int = 4;
\\pub export fn foo(arg_c_1: u8) void {
\\ var c_1 = arg_c_1;
- \\ _ = c_1;
+ \\ _ = @TypeOf(c_1);
\\ var a_2: c_int = undefined;
\\ var b_3: u8 = 123;
\\ b_3 = @bitCast(u8, @truncate(i8, a_2));
\\ {
\\ var d: c_int = 5;
- \\ _ = d;
+ \\ _ = @TypeOf(d);
\\ }
\\ var d: c_uint = @bitCast(c_uint, @as(c_int, 440));
- \\ _ = d;
+ \\ _ = @TypeOf(d);
\\}
});
@@ -2146,7 +2146,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ {
\\ var i: c_int = 2;
\\ var b: c_int = 4;
- \\ _ = b;
+ \\ _ = @TypeOf(b);
\\ while ((i + @as(c_int, 2)) != 0) : (i = 2) {
\\ var a: c_int = 2;
\\ _ = blk: {
@@ -2159,7 +2159,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\ }
\\ }
\\ var i: u8 = 2;
- \\ _ = i;
+ \\ _ = @TypeOf(i);
\\}
});
@@ -2396,27 +2396,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub export fn escapes() [*c]const u8 {
\\ var a: u8 = '\'';
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ var b: u8 = '\\';
- \\ _ = b;
+ \\ _ = @TypeOf(b);
\\ var c: u8 = '\x07';
- \\ _ = c;
+ \\ _ = @TypeOf(c);
\\ var d: u8 = '\x08';
- \\ _ = d;
+ \\ _ = @TypeOf(d);
\\ var e: u8 = '\x0c';
- \\ _ = e;
+ \\ _ = @TypeOf(e);
\\ var f: u8 = '\n';
- \\ _ = f;
+ \\ _ = @TypeOf(f);
\\ var g: u8 = '\r';
- \\ _ = g;
+ \\ _ = @TypeOf(g);
\\ var h: u8 = '\t';
- \\ _ = h;
+ \\ _ = @TypeOf(h);
\\ var i: u8 = '\x0b';
- \\ _ = i;
+ \\ _ = @TypeOf(i);
\\ var j: u8 = '\x00';
- \\ _ = j;
+ \\ _ = @TypeOf(j);
\\ var k: u8 = '"';
- \\ _ = k;
+ \\ _ = @TypeOf(k);
\\ return "'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
\\}
});
@@ -2612,7 +2612,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn foo() c_int {
\\ return blk: {
\\ var a: c_int = 1;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ break :blk a;
\\ };
\\}
@@ -2716,7 +2716,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\int bar(void) { return 0; }
, &[_][]const u8{
\\pub inline fn CALL(arg: anytype) @TypeOf(bar()) {
- \\ _ = arg;
+ \\ _ = @TypeOf(arg);
\\ return bar();
\\}
});
@@ -2775,14 +2775,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn foo() void {
\\ if (true) {
\\ var a: c_int = 2;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ }
\\ if ((blk: {
\\ _ = @as(c_int, 2);
\\ break :blk @as(c_int, 5);
\\ }) != 0) {
\\ var a: c_int = 2;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\ }
\\}
});
@@ -3285,7 +3285,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\#define a 2
, &[_][]const u8{
\\pub inline fn FOO(bar: anytype) @TypeOf(baz(@import("std").zig.c_translation.cast(?*anyopaque, baz))) {
- \\ _ = bar;
+ \\ _ = @TypeOf(bar);
\\ return baz(@import("std").zig.c_translation.cast(?*anyopaque, baz));
\\}
,
@@ -3425,7 +3425,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
, &[_][]const u8{
\\pub export fn foo(arg_a: [*c]c_int) void {
\\ var a = arg_a;
- \\ _ = a;
+ \\ _ = @TypeOf(a);
\\}
\\pub export fn bar(arg_a: [*c]const c_int) void {
\\ var a = arg_a;
@@ -3785,12 +3785,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
\\pub export fn bar(arg_x: c_int, arg_y: c_int) c_int {
\\ var x = arg_x;
\\ var y = arg_y;
- \\ _ = y;
+ \\ _ = @TypeOf(y);
\\ return x;
\\}
,
\\pub inline fn FOO(A: anytype, B: anytype) @TypeOf(A) {
- \\ _ = B;
+ \\ _ = @TypeOf(B);
\\ return A;
\\}
});