| author | |
| committer | |
| log | 3d64ed0353ba7ec1ca46f4779fe5d32af8d17358 |
| tree | 71f63ffcc5da6ea49c80d3aefa095b9178dac57b |
| parent | 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 |
| signature |
`@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.3 files changed, 24 insertions(+), 2 deletions(-)
src/AstGen.zig+1-1| ... | ... | @@ -8324,7 +8324,7 @@ fn builtinCall( |
| 8324 | 8324 | .trap => { |
| 8325 | 8325 | try emitDbgNode(gz, node); |
| 8326 | 8326 | _ = try gz.addNode(.trap, node); |
| 8327 | return rvalue(gz, ri, .void_value, node); | |
| 8327 | return rvalue(gz, ri, .unreachable_value, node); | |
| 8328 | 8328 | }, |
| 8329 | 8329 | .error_to_int => { |
| 8330 | 8330 | const operand = try expr(gz, scope, .{ .rl = .none }, params[0]); |
test/behavior/builtin_functions_returning_void_or_noreturn.zig-1| ... | ... | @@ -26,5 +26,4 @@ test { |
| 26 | 26 | try testing.expectEqual({}, @setEvalBranchQuota(0)); |
| 27 | 27 | try testing.expectEqual({}, @setFloatMode(.Optimized)); |
| 28 | 28 | try testing.expectEqual({}, @setRuntimeSafety(true)); |
| 29 | try testing.expectEqual(noreturn, @TypeOf(if (true) @trap() else {})); | |
| 30 | 29 | } |
test/cases/compile_errors/noreturn_builtins_divert_control_flow.zig created+23| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | export fn entry1() void { | |
| 2 | @trap(); | |
| 3 | @trap(); | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | @panic(""); | |
| 7 | @panic(""); | |
| 8 | } | |
| 9 | export fn entry3() void { | |
| 10 | @compileError(""); | |
| 11 | @compileError(""); | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage2 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // :3:5: error: unreachable code | |
| 19 | // :2:5: note: control flow is diverted here | |
| 20 | // :7:5: error: unreachable code | |
| 21 | // :6:5: note: control flow is diverted here | |
| 22 | // :11:5: error: unreachable code | |
| 23 | // :10:5: note: control flow is diverted here |