@@ -1658,21 +1658,27 @@ fn analyzeBodyInner(
16581658 const extra = sema.code.extraData(Zir.Inst.BlockComptime, pl_node.payload_index);
16591659 const block_body = sema.code.bodySlice(extra.end, extra.data.body_len);
16601660
1661- if (block.isComptime()) {
1662- // No need for a sub-block; just resolve the other body directly!
1663- break :inst try sema.resolveInlineBody(block, block_body, inst);
1664- }
1665-
16661661 var child_block = block.makeSubBlock();
16671662 defer child_block.instructions.deinit(sema.gpa);
1663+
1664+ // We won't have any merges, but we must ensure this block is properly labeled for
1665+ // any `.restore_err_ret_index_*` instructions.
1666+ var label: Block.Label = .{
1667+ .zir_block = inst,
1668+ .merges = undefined,
1669+ };
1670+ child_block.label = &label;
1671+
16681672 child_block.comptime_reason = .{ .reason = .{
16691673 .src = src,
16701674 .r = .{ .simple = extra.data.reason },
16711675 } };
16721676
16731677 const result = try sema.resolveInlineBody(&child_block, block_body, inst);
16741678
1675- if (!try sema.isComptimeKnown(result)) {
1679+ // Only check for the result being comptime-known in the outermost `block_comptime`.
1680+ // That way, AstGen can safely elide redundant `block_comptime` without affecting semantics.
1681+ if (!block.isComptime() and !try sema.isComptimeKnown(result)) {
16761682 return sema.failWithNeededComptime(&child_block, src, null);
16771683 }
16781684
0 commit comments