aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-01-22 04:16:16 +0000
committermlugg <mlugg@mlugg.co.uk>2025-01-22 04:18:43 +0000
commite864c38cc38095a1496229803465fdd0d079f9c3 (patch)
tree1912a3efcf6a8fe67c36d960a980d7ad87ecd6c4 /src
parent8470b6ea37a82330be2c5ab41460fe58b8cfd4f6 (diff)
downloadzig-e864c38cc38095a1496229803465fdd0d079f9c3.tar.gz
zig-e864c38cc38095a1496229803465fdd0d079f9c3.zip
Sema: fix crash when `inline` loop condition is not comptime-known
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 978396e371..fb9b27a8cd 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -1824,7 +1824,14 @@ fn analyzeBodyInner(
);
const uncasted_cond = try sema.resolveInst(extra.data.condition);
const cond = try sema.coerce(block, Type.bool, uncasted_cond, cond_src);
- const cond_val = try sema.resolveConstDefinedValue(block, cond_src, cond, null);
+ const cond_val = try sema.resolveConstDefinedValue(
+ block,
+ cond_src,
+ cond,
+ // If this block is comptime, it's more helpful to just give the outer message.
+ // This is particularly true if this came from a comptime `condbr` above.
+ if (block.isComptime()) null else .{ .simple = .inline_loop_operand },
+ );
const inline_body = if (cond_val.toBool()) then_body else else_body;
try sema.maybeErrorUnwrapCondbr(block, inline_body, extra.data.condition, cond_src);