diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-11-27 03:30:39 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-11-27 03:37:50 -0500 |
| commit | bf3ac6615051143a9ef41180cd74e88de5dd573d (patch) | |
| tree | 94571f5e6d408287928091c4dad6451d946d6434 /test | |
| parent | 379d547603badb2667089c85454a2e3f5ede3342 (diff) | |
| download | zig-bf3ac6615051143a9ef41180cd74e88de5dd573d.tar.gz zig-bf3ac6615051143a9ef41180cd74e88de5dd573d.zip | |
remove type coercion from array values to references
* Implements #3768. This is a sweeping breaking change that requires
many (trivial) edits to Zig source code. Array values no longer
coerced to slices; however one may use `&` to obtain a reference to
an array value, which may then be coerced to a slice.
* Adds `IrInstruction::dump`, for debugging purposes. It's useful to
call to inspect the instruction when debugging Zig IR.
* Fixes bugs with result location semantics. See the new behavior test
cases, and compile error test cases.
* Fixes bugs with `@typeInfo` not properly resolving const values.
* Behavior tests are passing but std lib tests are not yet. There
is more work to do before merging this branch.
Diffstat (limited to 'test')
| -rw-r--r-- | test/compare_output.zig | 4 | ||||
| -rw-r--r-- | test/stage1/behavior/array.zig | 44 | ||||
| -rw-r--r-- | test/stage1/behavior/async_fn.zig | 12 | ||||
| -rw-r--r-- | test/stage1/behavior/await_struct.zig | 2 | ||||
| -rw-r--r-- | test/stage1/behavior/bugs/1607.zig | 4 | ||||
| -rw-r--r-- | test/stage1/behavior/bugs/1914.zig | 4 | ||||
| -rw-r--r-- | test/stage1/behavior/cast.zig | 49 | ||||
| -rw-r--r-- | test/stage1/behavior/eval.zig | 6 | ||||
| -rw-r--r-- | test/stage1/behavior/for.zig | 10 | ||||
| -rw-r--r-- | test/stage1/behavior/generics.zig | 4 | ||||
| -rw-r--r-- | test/stage1/behavior/misc.zig | 6 | ||||
| -rw-r--r-- | test/stage1/behavior/ptrcast.zig | 2 | ||||
| -rw-r--r-- | test/stage1/behavior/shuffle.zig | 14 | ||||
| -rw-r--r-- | test/stage1/behavior/slice.zig | 6 | ||||
| -rw-r--r-- | test/stage1/behavior/struct.zig | 9 | ||||
| -rw-r--r-- | test/stage1/behavior/struct_contains_slice_of_itself.zig | 16 | ||||
| -rw-r--r-- | test/stage1/behavior/type.zig | 24 | ||||
| -rw-r--r-- | test/stage1/behavior/union.zig | 2 | ||||
| -rw-r--r-- | test/stage1/behavior/vector.zig | 54 | ||||
| -rw-r--r-- | test/tests.zig | 32 |
20 files changed, 164 insertions, 140 deletions
diff --git a/test/compare_output.zig b/test/compare_output.zig index 1535d0ae52..03f71d380e 100644 --- a/test/compare_output.zig +++ b/test/compare_output.zig @@ -465,7 +465,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ ); - tc.setCommandLineArgs([_][]const u8{ + tc.setCommandLineArgs(&[_][]const u8{ "first arg", "'a' 'b' \\", "bare", @@ -506,7 +506,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void { \\ ); - tc.setCommandLineArgs([_][]const u8{ + tc.setCommandLineArgs(&[_][]const u8{ "first arg", "'a' 'b' \\", "bare", diff --git a/test/stage1/behavior/array.zig b/test/stage1/behavior/array.zig index 47e74cd310..1d51f822d0 100644 --- a/test/stage1/behavior/array.zig +++ b/test/stage1/behavior/array.zig @@ -20,7 +20,7 @@ test "arrays" { } expect(accumulator == 15); - expect(getArrayLen(array) == 5); + expect(getArrayLen(&array) == 5); } fn getArrayLen(a: []const u32) usize { return a.len; @@ -182,29 +182,29 @@ fn plusOne(x: u32) u32 { test "runtime initialize array elem and then implicit cast to slice" { var two: i32 = 2; - const x: []const i32 = [_]i32{two}; + const x: []const i32 = &[_]i32{two}; expect(x[0] == 2); } test "array literal as argument to function" { const S = struct { fn entry(two: i32) void { - foo([_]i32{ + foo(&[_]i32{ 1, 2, 3, }); - foo([_]i32{ + foo(&[_]i32{ 1, two, 3, }); - foo2(true, [_]i32{ + foo2(true, &[_]i32{ 1, 2, 3, }); - foo2(true, [_]i32{ + foo2(true, &[_]i32{ 1, two, 3, @@ -230,17 +230,17 @@ test "double nested array to const slice cast in array literal" { const S = struct { fn entry(two: i32) void { const cases = [_][]const []const i32{ - [_][]const i32{[_]i32{1}}, - [_][]const i32{[_]i32{ 2, 3 }}, - [_][]const i32{ - [_]i32{4}, - [_]i32{ 5, 6, 7 }, + &[_][]const i32{&[_]i32{1}}, + &[_][]const i32{&[_]i32{ 2, 3 }}, + &[_][]const i32{ + &[_]i32{4}, + &[_]i32{ 5, 6, 7 }, }, }; - check(cases); + check(&cases); const cases2 = [_][]const i32{ - [_]i32{1}, + &[_]i32{1}, &[_]i32{ two, 3 }, }; expect(cases2.len == 2); @@ -251,14 +251,14 @@ test "double nested array to const slice cast in array literal" { expect(cases2[1][1] == 3); const cases3 = [_][]const []const i32{ - [_][]const i32{[_]i32{1}}, + &[_][]const i32{&[_]i32{1}}, &[_][]const i32{&[_]i32{ two, 3 }}, - [_][]const i32{ - [_]i32{4}, - [_]i32{ 5, 6, 7 }, + &[_][]const i32{ + &[_]i32{4}, + &[_]i32{ 5, 6, 7 }, }, }; - check(cases3); + check(&cases3); } fn check(cases: []const []const []const i32) void { @@ -316,7 +316,7 @@ test "implicit cast zero sized array ptr to slice" { test "anonymous list literal syntax" { const S = struct { fn doTheTest() void { - var array: [4]u8 = .{1, 2, 3, 4}; + var array: [4]u8 = .{ 1, 2, 3, 4 }; expect(array[0] == 1); expect(array[1] == 2); expect(array[2] == 3); @@ -335,8 +335,8 @@ test "anonymous literal in array" { }; fn doTheTest() void { var array: [2]Foo = .{ - .{.a = 3}, - .{.b = 3}, + .{ .a = 3 }, + .{ .b = 3 }, }; expect(array[0].a == 3); expect(array[0].b == 4); @@ -351,7 +351,7 @@ test "anonymous literal in array" { test "access the null element of a null terminated array" { const S = struct { fn doTheTest() void { - var array: [4:0]u8 = .{'a', 'o', 'e', 'u'}; + var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' }; comptime expect(array[4] == 0); var len: usize = 4; expect(array[len] == 0); diff --git a/test/stage1/behavior/async_fn.zig b/test/stage1/behavior/async_fn.zig index 67411601da..78db00cc08 100644 --- a/test/stage1/behavior/async_fn.zig +++ b/test/stage1/behavior/async_fn.zig @@ -143,7 +143,7 @@ test "coroutine suspend, resume" { resume frame; seq('h'); - expect(std.mem.eql(u8, points, "abcdefgh")); + expect(std.mem.eql(u8, &points, "abcdefgh")); } fn amain() void { @@ -206,7 +206,7 @@ test "coroutine await" { resume await_a_promise; await_seq('i'); expect(await_final_result == 1234); - expect(std.mem.eql(u8, await_points, "abcdefghi")); + expect(std.mem.eql(u8, &await_points, "abcdefghi")); } async fn await_amain() void { await_seq('b'); @@ -240,7 +240,7 @@ test "coroutine await early return" { var p = async early_amain(); early_seq('f'); expect(early_final_result == 1234); - expect(std.mem.eql(u8, early_points, "abcdef")); + expect(std.mem.eql(u8, &early_points, "abcdef")); } async fn early_amain() void { early_seq('b'); @@ -1166,7 +1166,7 @@ test "suspend in for loop" { } fn atest() void { - expect(func([_]u8{ 1, 2, 3 }) == 6); + expect(func(&[_]u8{ 1, 2, 3 }) == 6); } fn func(stuff: []const u8) u32 { global_frame = @frame(); @@ -1211,7 +1211,7 @@ test "spill target expr in a for loop" { fn doTheTest() void { var foo = Foo{ - .slice = [_]i32{ 1, 2 }, + .slice = &[_]i32{ 1, 2 }, }; expect(atest(&foo) == 3); } @@ -1242,7 +1242,7 @@ test "spill target expr in a for loop, with a var decl in the loop body" { fn doTheTest() void { var foo = Foo{ - .slice = [_]i32{ 1, 2 }, + .slice = &[_]i32{ 1, 2 }, }; expect(atest(&foo) == 3); } diff --git a/test/stage1/behavior/await_struct.zig b/test/stage1/behavior/await_struct.zig index 6e4d330ea3..2d4faadc27 100644 --- a/test/stage1/behavior/await_struct.zig +++ b/test/stage1/behavior/await_struct.zig @@ -16,7 +16,7 @@ test "coroutine await struct" { resume await_a_promise; await_seq('i'); expect(await_final_result.x == 1234); - expect(std.mem.eql(u8, await_points, "abcdefghi")); + expect(std.mem.eql(u8, &await_points, "abcdefghi")); } async fn await_amain() void { await_seq('b'); diff --git a/test/stage1/behavior/bugs/1607.zig b/test/stage1/behavior/bugs/1607.zig index 3a1de80a86..ffc1aa85dc 100644 --- a/test/stage1/behavior/bugs/1607.zig +++ b/test/stage1/behavior/bugs/1607.zig @@ -10,6 +10,6 @@ fn checkAddress(s: []const u8) void { } test "slices pointing at the same address as global array." { - checkAddress(a); - comptime checkAddress(a); + checkAddress(&a); + comptime checkAddress(&a); } diff --git a/test/stage1/behavior/bugs/1914.zig b/test/stage1/behavior/bugs/1914.zig index 22269590d9..2c9e836e6a 100644 --- a/test/stage1/behavior/bugs/1914.zig +++ b/test/stage1/behavior/bugs/1914.zig @@ -7,7 +7,7 @@ const B = struct { a_pointer: *const A, }; -const b_list: []B = [_]B{}; +const b_list: []B = &[_]B{}; const a = A{ .b_list_pointer = &b_list }; test "segfault bug" { @@ -24,7 +24,7 @@ pub const B2 = struct { pointer_array: []*A2, }; -var b_value = B2{ .pointer_array = [_]*A2{} }; +var b_value = B2{ .pointer_array = &[_]*A2{} }; test "basic stuff" { std.debug.assert(&b_value == &b_value); diff --git a/test/stage1/behavior/cast.zig b/test/stage1/behavior/cast.zig index fec4494ad9..ba538a0ebb 100644 --- a/test/stage1/behavior/cast.zig +++ b/test/stage1/behavior/cast.zig @@ -150,7 +150,7 @@ test "peer type resolution: [0]u8 and []const u8" { } fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { if (a) { - return [_]u8{}; + return &[_]u8{}; } return slice[0..1]; @@ -175,7 +175,7 @@ fn testCastZeroArrayToErrSliceMut() void { } fn gimmeErrOrSlice() anyerror![]u8 { - return [_]u8{}; + return &[_]u8{}; } test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" { @@ -200,7 +200,7 @@ test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" { } fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { if (a) { - return [_]u8{}; + return &[_]u8{}; } return slice[0..1]; @@ -457,7 +457,7 @@ fn incrementVoidPtrValue(value: ?*c_void) void { test "implicit cast from [*]T to ?*c_void" { var a = [_]u8{ 3, 2, 1 }; incrementVoidPtrArray(a[0..].ptr, 3); - expect(std.mem.eql(u8, a, [_]u8{ 4, 3, 2 })); + expect(std.mem.eql(u8, &a, &[_]u8{ 4, 3, 2 })); } fn incrementVoidPtrArray(array: ?*c_void, len: usize) void { @@ -606,7 +606,12 @@ test "*const [N]null u8 to ?[]const u8" { test "peer resolution of string literals" { const S = struct { - const E = extern enum { a, b, c, d}; + const E = extern enum { + a, + b, + c, + d, + }; fn doTheTest(e: E) void { const cmd = switch (e) { @@ -627,15 +632,15 @@ test "type coercion related to sentinel-termination" { fn doTheTest() void { // [:x]T to []T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var slice: [:0]i32 = &array; var dest: []i32 = slice; - expect(mem.eql(i32, dest, &[_]i32{1,2,3,4})); + expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } // [*:x]T to [*]T { - var array = [4:99]i32{1,2,3,4}; + var array = [4:99]i32{ 1, 2, 3, 4 }; var dest: [*]i32 = &array; expect(dest[0] == 1); expect(dest[1] == 2); @@ -646,21 +651,21 @@ test "type coercion related to sentinel-termination" { // [N:x]T to [N]T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var dest: [4]i32 = array; - expect(mem.eql(i32, dest, &[_]i32{1,2,3,4})); + expect(mem.eql(i32, &dest, &[_]i32{ 1, 2, 3, 4 })); } // *[N:x]T to *[N]T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var dest: *[4]i32 = &array; - expect(mem.eql(i32, dest, &[_]i32{1,2,3,4})); + expect(mem.eql(i32, dest, &[_]i32{ 1, 2, 3, 4 })); } // [:x]T to [*:x]T { - var array = [4:0]i32{1,2,3,4}; + var array = [4:0]i32{ 1, 2, 3, 4 }; var slice: [:0]i32 = &array; var dest: [*:0]i32 = slice; expect(dest[0] == 1); @@ -674,3 +679,21 @@ test "type coercion related to sentinel-termination" { S.doTheTest(); comptime S.doTheTest(); } + +test "cast i8 fn call peers to i32 result" { + const S = struct { + fn doTheTest() void { + var cond = true; + const value: i32 = if (cond) smallBoi() else bigBoi(); + expect(value == 123); + } + fn smallBoi() i8 { + return 123; + } + fn bigBoi() i16 { + return 1234; + } + }; + S.doTheTest(); + comptime S.doTheTest(); +} diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index b7bce26568..be7226d94c 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -717,7 +717,7 @@ test "@bytesToslice on a packed struct" { }; var b = [1]u8{9}; - var f = @bytesToSlice(F, b); + var f = @bytesToSlice(F, &b); expect(f[0].a == 9); } @@ -774,12 +774,12 @@ test "*align(1) u16 is the same as *align(1:0:2) u16" { test "array concatenation forces comptime" { var a = oneItem(3) ++ oneItem(4); - expect(std.mem.eql(i32, a, [_]i32{ 3, 4 })); + expect(std.mem.eql(i32, &a, &[_]i32{ 3, 4 })); } test "array multiplication forces comptime" { var a = oneItem(3) ** scalar(2); - expect(std.mem.eql(i32, a, [_]i32{ 3, 3 })); + expect(std.mem.eql(i32, &a, &[_]i32{ 3, 3 })); } fn oneItem(x: i32) [1]i32 { diff --git a/test/stage1/behavior/for.zig b/test/stage1/behavior/for.zig index cfa68bd216..5cf75ed497 100644 --- a/test/stage1/behavior/for.zig +++ b/test/stage1/behavior/for.zig @@ -26,7 +26,7 @@ test "for loop with pointer elem var" { var target: [source.len]u8 = undefined; mem.copy(u8, target[0..], source); mangleString(target[0..]); - expect(mem.eql(u8, target, "bcdefgh")); + expect(mem.eql(u8, &target, "bcdefgh")); for (source) |*c, i| expect(@typeOf(c) == *const u8); @@ -64,7 +64,7 @@ test "basic for loop" { buffer[buf_index] = @intCast(u8, index); buf_index += 1; } - const unknown_size: []const u8 = array; + const unknown_size: []const u8 = &array; for (unknown_size) |item| { buffer[buf_index] = item; buf_index += 1; @@ -74,7 +74,7 @@ test "basic for loop" { buf_index += 1; } - expect(mem.eql(u8, buffer[0..buf_index], expected_result)); + expect(mem.eql(u8, buffer[0..buf_index], &expected_result)); } test "break from outer for loop" { @@ -139,6 +139,6 @@ test "for with null and T peer types and inferred result location type" { } } }; - S.doTheTest([_]u8{ 1, 2 }); - comptime S.doTheTest([_]u8{ 1, 2 }); + S.doTheTest(&[_]u8{ 1, 2 }); + comptime S.doTheTest(&[_]u8{ 1, 2 }); } diff --git a/test/stage1/behavior/generics.zig b/test/stage1/behavior/generics.zig index 664b982c21..dc15ae1b8c 100644 --- a/test/stage1/behavior/generics.zig +++ b/test/stage1/behavior/generics.zig @@ -120,8 +120,8 @@ fn aGenericFn(comptime T: type, comptime a: T, b: T) T { } test "generic fn with implicit cast" { - expect(getFirstByte(u8, [_]u8{13}) == 13); - expect(getFirstByte(u16, [_]u16{ + expect(getFirstByte(u8, &[_]u8{13}) == 13); + expect(getFirstByte(u16, &[_]u16{ 0, 13, }) == 0); diff --git a/test/stage1/behavior/misc.zig b/test/stage1/behavior/misc.zig index 6ac745f5c5..a3da752f0d 100644 --- a/test/stage1/behavior/misc.zig +++ b/test/stage1/behavior/misc.zig @@ -241,7 +241,7 @@ fn memFree(comptime T: type, memory: []T) void {} test "cast undefined" { const array: [100]u8 = undefined; - const slice = @as([]const u8, array); + const slice = @as([]const u8, &array); testCastUndefined(slice); } fn testCastUndefined(x: []const u8) void {} @@ -614,7 +614,7 @@ test "slicing zero length array" { expect(s1.len == 0); expect(s2.len == 0); expect(mem.eql(u8, s1, "")); - expect(mem.eql(u32, s2, [_]u32{})); + expect(mem.eql(u32, s2, &[_]u32{})); } const addr1 = @ptrCast(*const u8, emptyFn); @@ -710,7 +710,7 @@ test "result location zero sized array inside struct field implicit cast to slic const E = struct { entries: []u32, }; - var foo = E{ .entries = [_]u32{} }; + var foo = E{ .entries = &[_]u32{} }; expect(foo.entries.len == 0); } diff --git a/test/stage1/behavior/ptrcast.zig b/test/stage1/behavior/ptrcast.zig index ddb5a63eee..4c17b38e6e 100644 --- a/test/stage1/behavior/ptrcast.zig +++ b/test/stage1/behavior/ptrcast.zig @@ -37,7 +37,7 @@ fn testReinterpretBytesAsExternStruct() void { test "reinterpret struct field at comptime" { const numLittle = comptime Bytes.init(0x12345678); - expect(std.mem.eql(u8, [_]u8{ 0x78, 0x56, 0x34, 0x12 }, numLittle.bytes)); + expect(std.mem.eql(u8, &[_]u8{ 0x78, 0x56, 0x34, 0x12 }, &numLittle.bytes)); } const Bytes = struct { diff --git a/test/stage1/behavior/shuffle.zig b/test/stage1/behavior/shuffle.zig index 1985c8dc76..2189b3e0e1 100644 --- a/test/stage1/behavior/shuffle.zig +++ b/test/stage1/behavior/shuffle.zig @@ -9,28 +9,28 @@ test "@shuffle" { var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; const mask: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }; var res = @shuffle(i32, v, x, mask); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); // Implicit cast from array (of mask) res = @shuffle(i32, v, x, [4]i32{ 0, ~@as(i32, 2), 3, ~@as(i32, 3) }); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 40, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 40, 4 })); // Undefined const mask2: @Vector(4, i32) = [4]i32{ 3, 1, 2, 0 }; res = @shuffle(i32, v, undefined, mask2); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 40, -2, 30, 2147483647 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 40, -2, 30, 2147483647 })); // Upcasting of b var v2: @Vector(2, i32) = [2]i32{ 2147483647, undefined }; const mask3: @Vector(4, i32) = [4]i32{ ~@as(i32, 0), 2, ~@as(i32, 0), 3 }; res = @shuffle(i32, x, v2, mask3); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, 2147483647, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, 2147483647, 4 })); // Upcasting of a var v3: @Vector(2, i32) = [2]i32{ 2147483647, -2 }; const mask4: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 2), 1, ~@as(i32, 3) }; res = @shuffle(i32, v3, x, mask4); - expect(mem.eql(i32, @as([4]i32,res), [4]i32{ 2147483647, 3, -2, 4 })); + expect(mem.eql(i32, &@as([4]i32, res), &[4]i32{ 2147483647, 3, -2, 4 })); // bool // Disabled because of #3317 @@ -39,7 +39,7 @@ test "@shuffle" { var v4: @Vector(2, bool) = [2]bool{ true, false }; const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; var res2 = @shuffle(bool, x2, v4, mask5); - expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false })); } // TODO re-enable when LLVM codegen is fixed @@ -49,7 +49,7 @@ test "@shuffle" { var v4: @Vector(2, bool) = [2]bool{ true, false }; const mask5: @Vector(4, i32) = [4]i32{ 0, ~@as(i32, 1), 1, 2 }; var res2 = @shuffle(bool, x2, v4, mask5); - expect(mem.eql(bool, @as([4]bool,res2), [4]bool{ false, false, true, false })); + expect(mem.eql(bool, &@as([4]bool, res2), &[4]bool{ false, false, true, false })); } } }; diff --git a/test/stage1/behavior/slice.zig b/test/stage1/behavior/slice.zig index 3c394e39a1..e325c6c8c8 100644 --- a/test/stage1/behavior/slice.zig +++ b/test/stage1/behavior/slice.zig @@ -28,7 +28,7 @@ fn sliceFromLenToLen(a_slice: []u8, start: usize, end: usize) []u8 { test "implicitly cast array of size 0 to slice" { var msg = [_]u8{}; - assertLenIsZero(msg); + assertLenIsZero(&msg); } fn assertLenIsZero(msg: []const u8) void { @@ -51,8 +51,8 @@ fn sliceSum(comptime q: []const u8) i32 { } test "comptime slices are disambiguated" { - expect(sliceSum([_]u8{ 1, 2 }) == 3); - expect(sliceSum([_]u8{ 3, 4 }) == 7); + expect(sliceSum(&[_]u8{ 1, 2 }) == 3); + expect(sliceSum(&[_]u8{ 3, 4 }) == 7); } test "slice type with custom alignment" { diff --git a/test/stage1/behavior/struct.zig b/test/stage1/behavior/struct.zig index 7c2e58f2cb..408f5da687 100644 --- a/test/stage1/behavior/struct.zig +++ b/test/stage1/behavior/struct.zig @@ -184,7 +184,7 @@ fn testReturnEmptyStructFromFn() EmptyStruct2 { } test "pass slice of empty struct to fn" { - expect(testPassSliceOfEmptyStructToFn([_]EmptyStruct2{EmptyStruct2{}}) == 1); + expect(testPassSliceOfEmptyStructToFn(&[_]EmptyStruct2{EmptyStruct2{}}) == 1); } fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) usize { return slice.len; @@ -432,7 +432,7 @@ const Expr = union(enum) { }; fn alloc(comptime T: type) []T { - return [_]T{}; + return &[_]T{}; } test "call method with mutable reference to struct with no fields" { @@ -495,7 +495,8 @@ test "non-byte-aligned array inside packed struct" { .a = true, .b = "abcdefghijklmnopqurstu".*, }; - bar(foo.b); + const value = foo.b; + bar(&value); } }; S.doTheTest(); @@ -783,7 +784,7 @@ test "struct with var field" { x: var, y: var, }; - const pt = Point { + const pt = Point{ .x = 1, .y = 2, }; diff --git a/test/stage1/behavior/struct_contains_slice_of_itself.zig b/test/stage1/behavior/struct_contains_slice_of_itself.zig index 2f3b5f41df..14bf0320a2 100644 --- a/test/stage1/behavior/struct_contains_slice_of_itself.zig +++ b/test/stage1/behavior/struct_contains_slice_of_itself.zig @@ -14,21 +14,21 @@ test "struct contains slice of itself" { var other_nodes = [_]Node{ Node{ .payload = 31, - .children = [_]Node{}, + .children = &[_]Node{}, }, Node{ .payload = 32, - .children = [_]Node{}, + .children = &[_]Node{}, }, }; var nodes = [_]Node{ Node{ .payload = 1, - .children = [_]Node{}, + .children = &[_]Node{}, }, Node{ .payload = 2, - .children = [_]Node{}, + .children = &[_]Node{}, }, Node{ .payload = 3, @@ -51,21 +51,21 @@ test "struct contains aligned slice of itself" { var other_nodes = [_]NodeAligned{ NodeAligned{ .payload = 31, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, NodeAligned{ .payload = 32, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, }; var nodes = [_]NodeAligned{ NodeAligned{ .payload = 1, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, NodeAligned{ .payload = 2, - .children = [_]NodeAligned{}, + .children = &[_]NodeAligned{}, }, NodeAligned{ .payload = 3, diff --git a/test/stage1/behavior/type.zig b/test/stage1/behavior/type.zig index f083359d1d..432a1e0e94 100644 --- a/test/stage1/behavior/type.zig +++ b/test/stage1/behavior/type.zig @@ -12,22 +12,22 @@ fn testTypes(comptime types: []const type) void { test "Type.MetaType" { testing.expect(type == @Type(TypeInfo{ .Type = undefined })); - testTypes([_]type{type}); + testTypes(&[_]type{type}); } test "Type.Void" { testing.expect(void == @Type(TypeInfo{ .Void = undefined })); - testTypes([_]type{void}); + testTypes(&[_]type{void}); } test "Type.Bool" { testing.expect(bool == @Type(TypeInfo{ .Bool = undefined })); - testTypes([_]type{bool}); + testTypes(&[_]type{bool}); } test "Type.NoReturn" { testing.expect(noreturn == @Type(TypeInfo{ .NoReturn = undefined })); - testTypes([_]type{noreturn}); + testTypes(&[_]type{noreturn}); } test "Type.Int" { @@ -37,7 +37,7 @@ test "Type.Int" { testing.expect(i8 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 8 } })); testing.expect(u64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = false, .bits = 64 } })); testing.expect(i64 == @Type(TypeInfo{ .Int = TypeInfo.Int{ .is_signed = true, .bits = 64 } })); - testTypes([_]type{ u8, u32, i64 }); + testTypes(&[_]type{ u8, u32, i64 }); } test "Type.Float" { @@ -45,11 +45,11 @@ test "Type.Float" { testing.expect(f32 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 32 } })); testing.expect(f64 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 64 } })); testing.expect(f128 == @Type(TypeInfo{ .Float = TypeInfo.Float{ .bits = 128 } })); - testTypes([_]type{ f16, f32, f64, f128 }); + testTypes(&[_]type{ f16, f32, f64, f128 }); } test "Type.Pointer" { - testTypes([_]type{ + testTypes(&[_]type{ // One Value Pointer Types *u8, *const u8, *volatile u8, *const volatile u8, @@ -115,18 +115,18 @@ test "Type.Array" { .sentinel = 0, }, })); - testTypes([_]type{ [1]u8, [30]usize, [7]bool }); + testTypes(&[_]type{ [1]u8, [30]usize, [7]bool }); } test "Type.ComptimeFloat" { - testTypes([_]type{comptime_float}); + testTypes(&[_]type{comptime_float}); } test "Type.ComptimeInt" { - testTypes([_]type{comptime_int}); + testTypes(&[_]type{comptime_int}); } test "Type.Undefined" { - testTypes([_]type{@typeOf(undefined)}); + testTypes(&[_]type{@typeOf(undefined)}); } test "Type.Null" { - testTypes([_]type{@typeOf(null)}); + testTypes(&[_]type{@typeOf(null)}); } diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig index d7481b21c7..43b26b79b8 100644 --- a/test/stage1/behavior/union.zig +++ b/test/stage1/behavior/union.zig @@ -241,7 +241,7 @@ pub const PackThis = union(enum) { }; test "constant packed union" { - testConstPackedUnion([_]PackThis{PackThis{ .StringLiteral = 1 }}); + testConstPackedUnion(&[_]PackThis{PackThis{ .StringLiteral = 1 }}); } fn testConstPackedUnion(expected_tokens: []const PackThis) void { diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig index f7b98b294f..b6033ea660 100644 --- a/test/stage1/behavior/vector.zig +++ b/test/stage1/behavior/vector.zig @@ -8,7 +8,7 @@ test "implicit cast vector to array - bool" { fn doTheTest() void { const a: @Vector(4, bool) = [_]bool{ true, false, true, false }; const result_array: [4]bool = a; - expect(mem.eql(bool, result_array, [4]bool{ true, false, true, false })); + expect(mem.eql(bool, &result_array, &[4]bool{ true, false, true, false })); } }; S.doTheTest(); @@ -20,11 +20,11 @@ test "vector wrap operators" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 3, 4 }; - expect(mem.eql(i32, @as([4]i32, v +% x), [4]i32{ -2147483648, 2147483645, 33, 44 })); - expect(mem.eql(i32, @as([4]i32, v -% x), [4]i32{ 2147483646, 2147483647, 27, 36 })); - expect(mem.eql(i32, @as([4]i32, v *% x), [4]i32{ 2147483647, 2, 90, 160 })); + expect(mem.eql(i32, &@as([4]i32, v +% x), &[4]i32{ -2147483648, 2147483645, 33, 44 })); + expect(mem.eql(i32, &@as([4]i32, v -% x), &[4]i32{ 2147483646, 2147483647, 27, 36 })); + expect(mem.eql(i32, &@as([4]i32, v *% x), &[4]i32{ 2147483647, 2, 90, 160 })); var z: @Vector(4, i32) = [4]i32{ 1, 2, 3, -2147483648 }; - expect(mem.eql(i32, @as([4]i32, -%z), [4]i32{ -1, -2, -3, -2147483648 })); + expect(mem.eql(i32, &@as([4]i32, -%z), &[4]i32{ -1, -2, -3, -2147483648 })); } }; S.doTheTest(); @@ -36,12 +36,12 @@ test "vector bin compares with mem.eql" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 2147483647, -2, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2147483647, 30, 4 }; - expect(mem.eql(bool, @as([4]bool, v == x), [4]bool{ false, false, true, false })); - expect(mem.eql(bool, @as([4]bool, v != x), [4]bool{ true, true, false, true })); - expect(mem.eql(bool, @as([4]bool, v < x), [4]bool{ false, true, false, false })); - expect(mem.eql(bool, @as([4]bool, v > x), [4]bool{ true, false, false, true })); - expect(mem.eql(bool, @as([4]bool, v <= x), [4]bool{ false, true, true, false })); - expect(mem.eql(bool, @as([4]bool, v >= x), [4]bool{ true, false, true, true })); + expect(mem.eql(bool, &@as([4]bool, v == x), &[4]bool{ false, false, true, false })); + expect(mem.eql(bool, &@as([4]bool, v != x), &[4]bool{ true, true, false, true })); + expect(mem.eql(bool, &@as([4]bool, v < x), &[4]bool{ false, true, false, false })); + expect(mem.eql(bool, &@as([4]bool, v > x), &[4]bool{ true, false, false, true })); + expect(mem.eql(bool, &@as([4]bool, v <= x), &[4]bool{ false, true, true, false })); + expect(mem.eql(bool, &@as([4]bool, v >= x), &[4]bool{ true, false, true, true })); } }; S.doTheTest(); @@ -53,10 +53,10 @@ test "vector int operators" { fn doTheTest() void { var v: @Vector(4, i32) = [4]i32{ 10, 20, 30, 40 }; var x: @Vector(4, i32) = [4]i32{ 1, 2, 3, 4 }; - expect(mem.eql(i32, @as([4]i32, v + x), [4]i32{ 11, 22, 33, 44 })); - expect(mem.eql(i32, @as([4]i32, v - x), [4]i32{ 9, 18, 27, 36 })); - expect(mem.eql(i32, @as([4]i32, v * x), [4]i32{ 10, 40, 90, 160 })); - expect(mem.eql(i32, @as([4]i32, -v), [4]i32{ -10, -20, -30, -40 })); + expect(mem.eql(i32, &@as([4]i32, v + x), &[4]i32{ 11, 22, 33, 44 })); + expect(mem.eql(i32, &@as([4]i32, v - x), &[4]i32{ 9, 18, 27, 36 })); + expect(mem.eql(i32, &@as([4]i32, v * x), &[4]i32{ 10, 40, 90, 160 })); + expect(mem.eql(i32, &@as([4]i32, -v), &[4]i32{ -10, -20, -30, -40 })); } }; S.doTheTest(); @@ -68,10 +68,10 @@ test "vector float operators" { fn doTheTest() void { var v: @Vector(4, f32) = [4]f32{ 10, 20, 30, 40 }; var x: @Vector(4, f32) = [4]f32{ 1, 2, 3, 4 }; - expect(mem.eql(f32, @as([4]f32, v + x), [4]f32{ 11, 22, 33, 44 })); - expect(mem.eql(f32, @as([4]f32, v - x), [4]f32{ 9, 18, 27, 36 })); - expect(mem.eql(f32, @as([4]f32, v * x), [4]f32{ 10, 40, 90, 160 })); - expect(mem.eql(f32, @as([4]f32, -x), [4]f32{ -1, -2, -3, -4 })); + expect(mem.eql(f32, &@as([4]f32, v + x), &[4]f32{ 11, 22, 33, 44 })); + expect(mem.eql(f32, &@as([4]f32, v - x), &[4]f32{ 9, 18, 27, 36 })); + expect(mem.eql(f32, &@as([4]f32, v * x), &[4]f32{ 10, 40, 90, 160 })); + expect(mem.eql(f32, &@as([4]f32, -x), &[4]f32{ -1, -2, -3, -4 })); } }; S.doTheTest(); @@ -83,9 +83,9 @@ test "vector bit operators" { fn doTheTest() void { var v: @Vector(4, u8) = [4]u8{ 0b10101010, 0b10101010, 0b10101010, 0b10101010 }; var x: @Vector(4, u8) = [4]u8{ 0b11110000, 0b00001111, 0b10101010, 0b01010101 }; - expect(mem.eql(u8, @as([4]u8, v ^ x), [4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); - expect(mem.eql(u8, @as([4]u8, v | x), [4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); - expect(mem.eql(u8, @as([4]u8, v & x), [4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); + expect(mem.eql(u8, &@as([4]u8, v ^ x), &[4]u8{ 0b01011010, 0b10100101, 0b00000000, 0b11111111 })); + expect(mem.eql(u8, &@as([4]u8, v | x), &[4]u8{ 0b11111010, 0b10101111, 0b10101010, 0b11111111 })); + expect(mem.eql(u8, &@as([4]u8, v & x), &[4]u8{ 0b10100000, 0b00001010, 0b10101010, 0b00000000 })); } }; S.doTheTest(); @@ -98,7 +98,7 @@ test "implicit cast vector to array" { var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 }; var result_array: [4]i32 = a; result_array = a; - expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 })); + expect(mem.eql(i32, &result_array, &[4]i32{ 1, 2, 3, 4 })); } }; S.doTheTest(); @@ -120,22 +120,22 @@ test "vector casts of sizes not divisable by 8" { { var v: @Vector(4, u3) = [4]u3{ 5, 2, 3, 0 }; var x: [4]u3 = v; - expect(mem.eql(u3, x, @as([4]u3, v))); + expect(mem.eql(u3, &x, &@as([4]u3, v))); } { var v: @Vector(4, u2) = [4]u2{ 1, 2, 3, 0 }; var x: [4]u2 = v; - expect(mem.eql(u2, x, @as([4]u2, v))); + expect(mem.eql(u2, &x, &@as([4]u2, v))); } { var v: @Vector(4, u1) = [4]u1{ 1, 0, 1, 0 }; var x: [4]u1 = v; - expect(mem.eql(u1, x, @as([4]u1, v))); + expect(mem.eql(u1, &x, &@as([4]u1, v))); } { var v: @Vector(4, bool) = [4]bool{ false, false, true, false }; var x: [4]bool = v; - expect(mem.eql(bool, x, @as([4]bool, v))); + expect(mem.eql(bool, &x, &@as([4]bool, v))); } } }; diff --git a/test/tests.zig b/test/tests.zig index 2bb0f33487..513c960f95 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -325,7 +325,7 @@ pub fn addCliTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const M const exe = b.addExecutable("test-cli", "test/cli.zig"); const run_cmd = exe.run(); - run_cmd.addArgs([_][]const u8{ + run_cmd.addArgs(&[_][]const u8{ fs.realpathAlloc(b.allocator, b.zig_exe) catch unreachable, b.pathFromRoot(b.cache_root), }); @@ -411,7 +411,7 @@ pub fn addPkgTests( const ArchTag = @TagType(builtin.Arch); if (test_target.disable_native and test_target.target.getOs() == builtin.os and - @as(ArchTag,test_target.target.getArch()) == @as(ArchTag,builtin.arch)) + @as(ArchTag, test_target.target.getArch()) == @as(ArchTag, builtin.arch)) { continue; } @@ -429,7 +429,7 @@ pub fn addPkgTests( "bare"; const triple_prefix = if (test_target.target == .Native) - @as([]const u8,"native") + @as([]const u8, "native") else test_target.target.zigTripleNoSubArch(b.allocator) catch unreachable; @@ -626,7 +626,7 @@ pub const CompareOutputContext = struct { warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name); - const child = std.ChildProcess.init([_][]const u8{full_exe_path}, b.allocator) catch unreachable; + const child = std.ChildProcess.init(&[_][]const u8{full_exe_path}, b.allocator) catch unreachable; defer child.deinit(); child.env_map = b.env_map; @@ -667,7 +667,7 @@ pub const CompareOutputContext = struct { .expected_output = expected_output, .link_libc = false, .special = special, - .cli_args = [_][]const u8{}, + .cli_args = &[_][]const u8{}, }; const root_src_name = if (special == Special.Asm) "source.s" else "source.zig"; tc.addSourceFile(root_src_name, source); @@ -704,7 +704,7 @@ pub const CompareOutputContext = struct { const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, case.sources.items[0].filename }, ) catch unreachable; switch (case.special) { @@ -720,7 +720,7 @@ pub const CompareOutputContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); exe.step.dependOn(&write_src.step); @@ -752,7 +752,7 @@ pub const CompareOutputContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); exe.step.dependOn(&write_src.step); @@ -783,7 +783,7 @@ pub const CompareOutputContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); exe.step.dependOn(&write_src.step); @@ -816,7 +816,7 @@ pub const StackTracesContext = struct { const source_pathname = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, "source.zig" }, + &[_][]const u8{ b.cache_root, "source.zig" }, ) catch unreachable; for (self.modes) |mode| { @@ -1073,7 +1073,7 @@ pub const CompileErrorContext = struct { const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, ) catch unreachable; var zig_args = ArrayList([]const u8).init(b.allocator); @@ -1270,7 +1270,7 @@ pub const CompileErrorContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); compile_and_cmp_errors.step.dependOn(&write_src.step); @@ -1404,7 +1404,7 @@ pub const TranslateCContext = struct { const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, self.case.sources.items[0].filename }, ) catch unreachable; var zig_args = ArrayList([]const u8).init(b.allocator); @@ -1577,7 +1577,7 @@ pub const TranslateCContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); translate_c_and_cmp.step.dependOn(&write_src.step); @@ -1700,7 +1700,7 @@ pub const GenHContext = struct { const b = self.b; const root_src = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, case.sources.items[0].filename }, + &[_][]const u8{ b.cache_root, case.sources.items[0].filename }, ) catch unreachable; const mode = builtin.Mode.Debug; @@ -1715,7 +1715,7 @@ pub const GenHContext = struct { for (case.sources.toSliceConst()) |src_file| { const expanded_src_path = fs.path.join( b.allocator, - [_][]const u8{ b.cache_root, src_file.filename }, + &[_][]const u8{ b.cache_root, src_file.filename }, ) catch unreachable; const write_src = b.addWriteFile(expanded_src_path, src_file.source); obj.step.dependOn(&write_src.step); |
