mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
AstGen: ensure lableld block implicitly ends in a break
This commit is contained in:
parent
bb1fa0bdbd
commit
01b454f851
@ -1991,6 +1991,9 @@ fn labeledBlockExpr(
|
||||
defer block_scope.labeled_breaks.deinit(astgen.gpa);
|
||||
|
||||
try blockExprStmts(&block_scope, &block_scope.base, statements);
|
||||
if (!block_scope.endsWithNoReturn()) {
|
||||
_ = try block_scope.addBreak(.break_inline, block_inst, .void_value);
|
||||
}
|
||||
|
||||
if (!block_scope.label.?.used) {
|
||||
try astgen.appendErrorTok(label_token, "unused block label", .{});
|
||||
|
||||
@ -846,3 +846,10 @@ test "discarding the result of various expressions" {
|
||||
_ = while (S.bar()) |some| break some else {};
|
||||
_ = for ("foo") |char| break char else {};
|
||||
}
|
||||
|
||||
test "labeled block implicitly ends in a break" {
|
||||
var a = false;
|
||||
blk: {
|
||||
if (a) break :blk;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user