authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-09 17:12:40+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-09 17:12:40+02:00
log01b454f8515312531ff0c70985203f9aecb022db
treee5ac6ea062d051f5b062d3d11643d17e6dfd58ff
parentbb1fa0bdbd7235308362528e5c1ca408681064e9

AstGen: ensure lableld block implicitly ends in a break


2 files changed, 10 insertions(+), 0 deletions(-)

src/AstGen.zig+3
...@@ -1991,6 +1991,9 @@ fn labeledBlockExpr(...@@ -1991,6 +1991,9 @@ fn labeledBlockExpr(
1991 defer block_scope.labeled_breaks.deinit(astgen.gpa);1991 defer block_scope.labeled_breaks.deinit(astgen.gpa);
19921992
1993 try blockExprStmts(&block_scope, &block_scope.base, statements);1993 try blockExprStmts(&block_scope, &block_scope.base, statements);
1994 if (!block_scope.endsWithNoReturn()) {
1995 _ = try block_scope.addBreak(.break_inline, block_inst, .void_value);
1996 }
19941997
1995 if (!block_scope.label.?.used) {1998 if (!block_scope.label.?.used) {
1996 try astgen.appendErrorTok(label_token, "unused block label", .{});1999 try astgen.appendErrorTok(label_token, "unused block label", .{});
test/behavior/basic.zig+7
...@@ -846,3 +846,10 @@ test "discarding the result of various expressions" {...@@ -846,3 +846,10 @@ test "discarding the result of various expressions" {
846 _ = while (S.bar()) |some| break some else {};846 _ = while (S.bar()) |some| break some else {};
847 _ = for ("foo") |char| break char else {};847 _ = for ("foo") |char| break char else {};
848}848}
849
850test "labeled block implicitly ends in a break" {
851 var a = false;
852 blk: {
853 if (a) break :blk;
854 }
855}