From 01b454f8515312531ff0c70985203f9aecb022db Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Wed, 9 Mar 2022 17:12:40 +0200 Subject: [PATCH] AstGen: ensure lableld block implicitly ends in a break --- src/AstGen.zig | 3 +++ test/behavior/basic.zig | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/AstGen.zig b/src/AstGen.zig index bd8f06ae5951843b4c5b3fb95d1e49f843a94157..e39c7abffea9b63f50cf234f8c569b52d5235572 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -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", .{}); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 1ed7ea9fafce0ed3b90521d4f4b858496dd198a2..25a302398b88f09ab9d573e789df6aae1db7761d 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -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; + } +} -- 2.54.0