mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
make @trap return unreachable/noreturn (#15749)
`@trap` is a special function that we know never returns so it should behave just like `@panic` and `@compileError` do currently and cause the "unreachable code" + "control flow is diverted here" compile error. Currently, `@trap(); @trap();` does not cause this error. Now it does.
This commit is contained in:
parent
7cf2cbb33e
commit
3d64ed0353
@ -8324,7 +8324,7 @@ fn builtinCall(
|
||||
.trap => {
|
||||
try emitDbgNode(gz, node);
|
||||
_ = try gz.addNode(.trap, node);
|
||||
return rvalue(gz, ri, .void_value, node);
|
||||
return rvalue(gz, ri, .unreachable_value, node);
|
||||
},
|
||||
.error_to_int => {
|
||||
const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);
|
||||
|
||||
@ -26,5 +26,4 @@ test {
|
||||
try testing.expectEqual({}, @setEvalBranchQuota(0));
|
||||
try testing.expectEqual({}, @setFloatMode(.Optimized));
|
||||
try testing.expectEqual({}, @setRuntimeSafety(true));
|
||||
try testing.expectEqual(noreturn, @TypeOf(if (true) @trap() else {}));
|
||||
}
|
||||
|
||||
@ -0,0 +1,23 @@
|
||||
export fn entry1() void {
|
||||
@trap();
|
||||
@trap();
|
||||
}
|
||||
export fn entry2() void {
|
||||
@panic("");
|
||||
@panic("");
|
||||
}
|
||||
export fn entry3() void {
|
||||
@compileError("");
|
||||
@compileError("");
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :3:5: error: unreachable code
|
||||
// :2:5: note: control flow is diverted here
|
||||
// :7:5: error: unreachable code
|
||||
// :6:5: note: control flow is diverted here
|
||||
// :11:5: error: unreachable code
|
||||
// :10:5: note: control flow is diverted here
|
||||
Loading…
x
Reference in New Issue
Block a user