Skip to content

Commit ca8c6dd

Browse files
authored
Merge pull request #18569 from dweiller/17944-followup
17944 followup
2 parents fcc94f5 + a219c9f commit ca8c6dd

24 files changed

+246
-225
lines changed

src/Sema.zig

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28662,7 +28662,7 @@ fn coerceExtra(
2866228662
if (!dest_info.flags.is_const) {
2866328663
const err_msg = err_msg: {
2866428664
const err_msg = try sema.errMsg(block, inst_src, "cannot cast pointer to tuple to '{}'", .{dest_ty.fmt(mod)});
28665-
errdefer err_msg.deinit(sema.gpa);
28665+
errdefer err_msg.destroy(sema.gpa);
2866628666
try sema.errNote(block, dest_ty_src, err_msg, "pointers to tuples can only coerce to constant pointers", .{});
2866728667
break :err_msg err_msg;
2866828668
};
@@ -32604,31 +32604,39 @@ fn analyzeSlice(
3260432604

3260532605
if (try sema.compareScalar(start_value, .neq, end_value, Type.comptime_int)) {
3260632606
if (try sema.compareScalar(start_value, .neq, Value.zero_comptime_int, Type.comptime_int)) {
32607-
const err_msg = try sema.errMsg(block, start_src, bounds_error_message, .{});
32608-
try sema.errNote(
32609-
block,
32610-
start_src,
32611-
err_msg,
32612-
"expected '{}', found '{}'",
32613-
.{
32614-
Value.zero_comptime_int.fmtValue(Type.comptime_int, mod),
32615-
start_value.fmtValue(Type.comptime_int, mod),
32616-
},
32617-
);
32618-
return sema.failWithOwnedErrorMsg(block, err_msg);
32607+
const msg = msg: {
32608+
const msg = try sema.errMsg(block, start_src, bounds_error_message, .{});
32609+
errdefer msg.destroy(sema.gpa);
32610+
try sema.errNote(
32611+
block,
32612+
start_src,
32613+
msg,
32614+
"expected '{}', found '{}'",
32615+
.{
32616+
Value.zero_comptime_int.fmtValue(Type.comptime_int, mod),
32617+
start_value.fmtValue(Type.comptime_int, mod),
32618+
},
32619+
);
32620+
break :msg msg;
32621+
};
32622+
return sema.failWithOwnedErrorMsg(block, msg);
3261932623
} else if (try sema.compareScalar(end_value, .neq, Value.one_comptime_int, Type.comptime_int)) {
32620-
const err_msg = try sema.errMsg(block, end_src, bounds_error_message, .{});
32621-
try sema.errNote(
32622-
block,
32623-
end_src,
32624-
err_msg,
32625-
"expected '{}', found '{}'",
32626-
.{
32627-
Value.one_comptime_int.fmtValue(Type.comptime_int, mod),
32628-
end_value.fmtValue(Type.comptime_int, mod),
32629-
},
32630-
);
32631-
return sema.failWithOwnedErrorMsg(block, err_msg);
32624+
const msg = msg: {
32625+
const msg = try sema.errMsg(block, end_src, bounds_error_message, .{});
32626+
errdefer msg.destroy(sema.gpa);
32627+
try sema.errNote(
32628+
block,
32629+
end_src,
32630+
msg,
32631+
"expected '{}', found '{}'",
32632+
.{
32633+
Value.one_comptime_int.fmtValue(Type.comptime_int, mod),
32634+
end_value.fmtValue(Type.comptime_int, mod),
32635+
},
32636+
);
32637+
break :msg msg;
32638+
};
32639+
return sema.failWithOwnedErrorMsg(block, msg);
3263232640
}
3263332641
} else {
3263432642
if (try sema.compareScalar(end_value, .gt, Value.one_comptime_int, Type.comptime_int)) {

test/behavior/align.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const assert = std.debug.assert;
77
var foo: u8 align(4) = 100;
88

99
test "global variable alignment" {
10-
try comptime expect(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
11-
try comptime expect(@TypeOf(&foo) == *align(4) u8);
10+
comptime assert(@typeInfo(@TypeOf(&foo)).Pointer.alignment == 4);
11+
comptime assert(@TypeOf(&foo) == *align(4) u8);
1212
{
1313
const slice = @as(*align(4) [1]u8, &foo)[0..];
14-
try comptime expect(@TypeOf(slice) == *align(4) [1]u8);
14+
comptime assert(@TypeOf(slice) == *align(4) [1]u8);
1515
}
1616
}
1717

@@ -455,10 +455,10 @@ test "runtime-known array index has best alignment possible" {
455455
try testIndex2(&array, 3, *u8);
456456
}
457457
fn testIndex(smaller: [*]align(2) u32, index: usize, comptime T: type) !void {
458-
try comptime expect(@TypeOf(&smaller[index]) == T);
458+
comptime assert(@TypeOf(&smaller[index]) == T);
459459
}
460460
fn testIndex2(ptr: [*]align(4) u8, index: usize, comptime T: type) !void {
461-
try comptime expect(@TypeOf(&ptr[index]) == T);
461+
comptime assert(@TypeOf(&ptr[index]) == T);
462462
}
463463

464464
test "alignment of function with c calling convention" {
@@ -524,7 +524,7 @@ test "struct field explicit alignment" {
524524
var node: S.Node = undefined;
525525
node.massive_byte = 100;
526526
try expect(node.massive_byte == 100);
527-
try comptime expect(@TypeOf(&node.massive_byte) == *align(64) u8);
527+
comptime assert(@TypeOf(&node.massive_byte) == *align(64) u8);
528528
try expect(@intFromPtr(&node.massive_byte) % 64 == 0);
529529
}
530530

test/behavior/alignof.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const std = @import("std");
2+
const assert = std.debug.assert;
23
const expect = std.testing.expect;
34
const builtin = @import("builtin");
45
const native_arch = builtin.target.cpu.arch;
@@ -11,9 +12,9 @@ const Foo = struct {
1112
};
1213

1314
test "@alignOf(T) before referencing T" {
14-
try comptime expect(@alignOf(Foo) != maxInt(usize));
15+
comptime assert(@alignOf(Foo) != maxInt(usize));
1516
if (native_arch == .x86_64) {
16-
try comptime expect(@alignOf(Foo) == 4);
17+
comptime assert(@alignOf(Foo) == 4);
1718
}
1819
}
1920

test/behavior/array.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const std = @import("std");
22
const builtin = @import("builtin");
33
const testing = std.testing;
44
const mem = std.mem;
5+
const assert = std.debug.assert;
56
const expect = testing.expect;
67
const expectEqual = testing.expectEqual;
78

@@ -149,9 +150,9 @@ test "array len field" {
149150
var arr = [4]u8{ 0, 0, 0, 0 };
150151
const ptr = &arr;
151152
try expect(arr.len == 4);
152-
try comptime expect(arr.len == 4);
153+
comptime assert(arr.len == 4);
153154
try expect(ptr.len == 4);
154-
try comptime expect(ptr.len == 4);
155+
comptime assert(ptr.len == 4);
155156
try expect(@TypeOf(arr.len) == usize);
156157
}
157158

@@ -904,7 +905,7 @@ test "store array of array of structs at comptime" {
904905
};
905906

906907
try expect(S.storeArrayOfArrayOfStructs() == 15);
907-
try comptime expect(S.storeArrayOfArrayOfStructs() == 15);
908+
comptime assert(S.storeArrayOfArrayOfStructs() == 15);
908909
}
909910

910911
test "accessing multidimensional global array at comptime" {

test/behavior/async_fn.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3+
const assert = std.debug.assert;
34
const expect = std.testing.expect;
45
const expectEqual = std.testing.expectEqual;
56
const expectEqualStrings = std.testing.expectEqualStrings;
@@ -221,7 +222,7 @@ var a_promise: anyframe = undefined;
221222
var global_result = false;
222223
fn testSuspendBlock() callconv(.Async) void {
223224
suspend {
224-
comptime expect(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
225+
comptime assert(@TypeOf(@frame()) == *@Frame(testSuspendBlock)) catch unreachable;
225226
a_promise = @frame();
226227
}
227228

@@ -334,7 +335,7 @@ test "async fn pointer in a struct field" {
334335
_ = &foo;
335336
var bytes: [64]u8 align(16) = undefined;
336337
const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
337-
try comptime expect(@TypeOf(f) == anyframe->void);
338+
comptime assert(@TypeOf(f) == anyframe->void);
338339
try expect(data == 2);
339340
resume f;
340341
try expect(data == 4);
@@ -1150,7 +1151,7 @@ test "@asyncCall using the result location inside the frame" {
11501151
_ = &foo;
11511152
var bytes: [64]u8 align(16) = undefined;
11521153
const f = @asyncCall(&bytes, {}, foo.bar, .{&data});
1153-
try comptime expect(@TypeOf(f) == anyframe->i32);
1154+
comptime assert(@TypeOf(f) == anyframe->i32);
11541155
try expect(data == 2);
11551156
resume f;
11561157
try expect(data == 4);
@@ -1165,7 +1166,7 @@ test "@TypeOf an async function call of generic fn with error union type" {
11651166
const S = struct {
11661167
fn func(comptime x: anytype) anyerror!i32 {
11671168
const T = @TypeOf(async func(x));
1168-
try comptime expect(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
1169+
comptime assert(T == @typeInfo(@TypeOf(@frame())).Pointer.child);
11691170
return undefined;
11701171
}
11711172
};

test/behavior/basic.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test "empty function with comments" {
1717

1818
test "truncate" {
1919
try expect(testTruncate(0x10fd) == 0xfd);
20-
try comptime expect(testTruncate(0x10fd) == 0xfd);
20+
comptime assert(testTruncate(0x10fd) == 0xfd);
2121
}
2222
fn testTruncate(x: u32) u8 {
2323
return @as(u8, @truncate(x));
@@ -568,7 +568,7 @@ fn emptyFn() void {}
568568
const addr1 = @as(*const u8, @ptrCast(&emptyFn));
569569
test "comptime cast fn to ptr" {
570570
const addr2 = @as(*const u8, @ptrCast(&emptyFn));
571-
try comptime expect(addr1 == addr2);
571+
comptime assert(addr1 == addr2);
572572
}
573573

574574
test "equality compare fn ptrs" {
@@ -678,8 +678,8 @@ test "string concatenation" {
678678
const a = "OK" ++ " IT " ++ "WORKED";
679679
const b = "OK IT WORKED";
680680

681-
try comptime expect(@TypeOf(a) == *const [12:0]u8);
682-
try comptime expect(@TypeOf(b) == *const [12:0]u8);
681+
comptime assert(@TypeOf(a) == *const [12:0]u8);
682+
comptime assert(@TypeOf(b) == *const [12:0]u8);
683683

684684
const len = b.len;
685685
const len_with_null = len + 1;
@@ -747,7 +747,7 @@ test "auto created variables have correct alignment" {
747747
}
748748
};
749749
try expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
750-
try comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
750+
comptime assert(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
751751
}
752752

753753
test "extern variable with non-pointer opaque type" {

test/behavior/bitcast.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const std = @import("std");
22
const builtin = @import("builtin");
3+
const assert = std.debug.assert;
34
const expect = std.testing.expect;
45
const expectEqual = std.testing.expectEqual;
56
const math = std.math;
@@ -273,7 +274,7 @@ test "comptime bitcast used in expression has the correct type" {
273274
test "bitcast passed as tuple element" {
274275
const S = struct {
275276
fn foo(args: anytype) !void {
276-
try comptime expect(@TypeOf(args[0]) == f32);
277+
comptime assert(@TypeOf(args[0]) == f32);
277278
try expect(args[0] == 12.34);
278279
}
279280
};
@@ -283,7 +284,7 @@ test "bitcast passed as tuple element" {
283284
test "triple level result location with bitcast sandwich passed as tuple element" {
284285
const S = struct {
285286
fn foo(args: anytype) !void {
286-
try comptime expect(@TypeOf(args[0]) == f64);
287+
comptime assert(@TypeOf(args[0]) == f64);
287288
try expect(args[0] > 12.33 and args[0] < 12.35);
288289
}
289290
};

test/behavior/call.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const builtin = @import("builtin");
22
const std = @import("std");
3+
const assert = std.debug.assert;
34
const expect = std.testing.expect;
45
const expectEqual = std.testing.expectEqual;
56

@@ -10,11 +11,11 @@ test "super basic invocations" {
1011
}
1112
}.foo;
1213
try expect(@call(.auto, foo, .{}) == 1234);
13-
try comptime expect(@call(.always_inline, foo, .{}) == 1234);
14+
comptime assert(@call(.always_inline, foo, .{}) == 1234);
1415
{
1516
// comptime call without comptime keyword
1617
const result = @call(.compile_time, foo, .{}) == 1234;
17-
try comptime expect(result);
18+
comptime assert(result);
1819
}
1920
}
2021

@@ -42,7 +43,7 @@ test "basic invocations" {
4243
{
4344
// comptime call without comptime keyword
4445
const result = @call(.compile_time, foo, .{}) == 1234;
45-
try comptime expect(result);
46+
comptime assert(result);
4647
}
4748
{
4849
// call of non comptime-known function
@@ -73,7 +74,7 @@ test "tuple parameters" {
7374
try expect(@call(.auto, add, .{ a, b }) == 46);
7475
try expect(@call(.auto, add, .{ 12, 34 }) == 46);
7576
if (false) {
76-
try comptime expect(@call(.auto, add, .{ 12, 34 }) == 46); // TODO
77+
comptime assert(@call(.auto, add, .{ 12, 34 }) == 46); // TODO
7778
}
7879
try expect(comptime @call(.auto, add, .{ 12, 34 }) == 46);
7980
{

0 commit comments

Comments
 (0)