authorgravatar for sinon@vortan.devDavid Rubin <sinon@vortan.dev> 2026-06-16 21:25:49-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-19 16:08:32+02:00
logf7e6d757f2cec02fbd9bf58eda8f88618d67b80a
treea8190414cdb3eb6d90952def975104e5efe1b81d
parentd004f775ce4a288c03d6986518bc6fe423c99e3c

Sema: correctly populate runtime_{cond,loop} for inline returns


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

src/Sema.zig+6
......@@ -18069,6 +18069,12 @@ fn analyzeRet(
1806918069 try inlining.merges.results.append(sema.gpa, operand);
1807018070 try inlining.merges.br_list.append(sema.gpa, br_inst.toIndex().?);
1807118071 try inlining.merges.src_locs.append(sema.gpa, operand_src);
18072 var body_block = block;
18073 while (body_block.parent) |parent| body_block = parent;
18074 if (body_block.runtime_cond == null and body_block.runtime_loop == null) {
18075 body_block.runtime_cond = block.runtime_cond orelse block.runtime_loop;
18076 body_block.runtime_loop = block.runtime_loop;
18077 }
1807218078 } else {
1807318079 try sema.validateRuntimeValue(block, operand_src, operand);
1807418080 const ret_tag: Air.Inst.Tag = if (block.wantSafety()) .ret_safe else .ret;
test/cases/compile_errors/inline_return.zig created+16
......@@ -0,0 +1,16 @@
1inline fn select(cond: bool, a: anytype, b: anytype) @TypeOf(a, b) {
2 if (cond) {
3 return a;
4 } else {
5 return b;
6 }
7}
8export fn f(x: u32) u32 {
9 return select(x > 0, 2, 1);
10}
11
12// error
13//
14// :9:18: error: value with comptime-only type 'comptime_int' depends on runtime control flow
15// :2:9: note: runtime control flow here
16// :9:18: note: called inline here