commit f7e6d757f2cec02fbd9bf58eda8f88618d67b80a (tree)
parent d004f775ce4a288c03d6986518bc6fe423c99e3c
Author: David Rubin <sinon@vortan.dev>
Date: Tue, 16 Jun 2026 21:25:49 -0700
Sema: correctly populate runtime_{cond,loop} for inline returns
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/Sema.zig b/src/Sema.zig
@@ -18069,6 +18069,12 @@ fn analyzeRet(
try inlining.merges.results.append(sema.gpa, operand);
try inlining.merges.br_list.append(sema.gpa, br_inst.toIndex().?);
try inlining.merges.src_locs.append(sema.gpa, operand_src);
+ var body_block = block;
+ while (body_block.parent) |parent| body_block = parent;
+ if (body_block.runtime_cond == null and body_block.runtime_loop == null) {
+ body_block.runtime_cond = block.runtime_cond orelse block.runtime_loop;
+ body_block.runtime_loop = block.runtime_loop;
+ }
} else {
try sema.validateRuntimeValue(block, operand_src, operand);
const ret_tag: Air.Inst.Tag = if (block.wantSafety()) .ret_safe else .ret;
diff --git a/test/cases/compile_errors/inline_return.zig b/test/cases/compile_errors/inline_return.zig
@@ -0,0 +1,16 @@
+inline fn select(cond: bool, a: anytype, b: anytype) @TypeOf(a, b) {
+ if (cond) {
+ return a;
+ } else {
+ return b;
+ }
+}
+export fn f(x: u32) u32 {
+ return select(x > 0, 2, 1);
+}
+
+// error
+//
+// :9:18: error: value with comptime-only type 'comptime_int' depends on runtime control flow
+// :2:9: note: runtime control flow here
+// :9:18: note: called inline here