zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 7f91be9c80f8d79e4a2c6cf0b15197cdd454cef6 (tree)
parent bcf2eb1a003d076c166d4ce9cba20f6ed9b53887
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Thu, 24 Mar 2022 22:45:10 -0700

AstGen: emit break_inline from inline while loop

Diffstat:
Msrc/AstGen.zig | 4++--
Mtest/behavior/while.zig | 10++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/AstGen.zig b/src/AstGen.zig @@ -1878,8 +1878,8 @@ fn continueExpr(parent_gz: *GenZir, parent_scope: *Scope, node: Ast.Node.Index) continue; } - // TODO emit a break_inline if the loop being continued is inline - _ = try parent_gz.addBreak(.@"break", continue_block, .void_value); + const break_tag: Zir.Inst.Tag = if (gen_zir.is_inline) .break_inline else .@"break"; + _ = try parent_gz.addBreak(break_tag, continue_block, .void_value); return Zir.Inst.Ref.unreachable_value; }, .local_val => scope = scope.cast(Scope.LocalVal).?.parent, diff --git a/test/behavior/while.zig b/test/behavior/while.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const expect = std.testing.expect; +const assert = std.debug.assert; test "while loop" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; @@ -326,3 +327,12 @@ test "while error 2 break statements and an else" { try S.entry(true, false); comptime try S.entry(true, false); } + +test "continue inline while loop" { + comptime var i = 0; + inline while (i < 10) : (i += 1) { + if (i < 5) continue; + break; + } + comptime assert(i == 5); +}