From adcaad6d91c309fab20ea208231c3e7d33fcc21f Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:41:28 +1100 Subject: [PATCH] sema: fix err union switch with inferred empty error sets --- src/Sema.zig | 79 ++++++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 752bc4da6f9629240a96819d8149bd145e0cca71..eebf31a2389d1589e9d4bfa3431a9f21a6854459 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -11237,6 +11237,48 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp const operand_ty = sema.typeOf(raw_operand_val); const operand_err_set_ty = operand_ty.errorUnionSet(mod); + const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); + try sema.air_instructions.append(gpa, .{ + .tag = .block, + .data = undefined, + }); + var label: Block.Label = .{ + .zir_block = inst, + .merges = .{ + .src_locs = .{}, + .results = .{}, + .br_list = .{}, + .block_inst = block_inst, + }, + }; + + var child_block: Block = .{ + .parent = block, + .sema = sema, + .src_decl = block.src_decl, + .namespace = block.namespace, + .wip_capture_scope = block.wip_capture_scope, + .instructions = .{}, + .label = &label, + .inlining = block.inlining, + .is_comptime = block.is_comptime, + .comptime_reason = block.comptime_reason, + .is_typeof = block.is_typeof, + .c_import_buf = block.c_import_buf, + .runtime_cond = block.runtime_cond, + .runtime_loop = block.runtime_loop, + .runtime_index = block.runtime_index, + .error_return_trace_index = block.error_return_trace_index, + }; + const merges = &child_block.label.?.merges; + defer child_block.instructions.deinit(gpa); + defer merges.deinit(gpa); + + const resolved_err_set = try sema.resolveInferredErrorSetTy(block, src, operand_err_set_ty.toIntern()); + if (Type.fromInterned(resolved_err_set).errorSetIsEmpty(mod)) { + return sema.resolveBlockBody(block, operand_src, &child_block, non_error_case.body, inst, merges); + } + const else_error_ty: ?Type = try validateErrSetSwitch( sema, block, @@ -11261,43 +11303,6 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp .tag_capture_inst = undefined, }; - const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len); - try sema.air_instructions.append(gpa, .{ - .tag = .block, - .data = undefined, - }); - var label: Block.Label = .{ - .zir_block = inst, - .merges = .{ - .src_locs = .{}, - .results = .{}, - .br_list = .{}, - .block_inst = block_inst, - }, - }; - - var child_block: Block = .{ - .parent = block, - .sema = sema, - .src_decl = block.src_decl, - .namespace = block.namespace, - .wip_capture_scope = block.wip_capture_scope, - .instructions = .{}, - .label = &label, - .inlining = block.inlining, - .is_comptime = block.is_comptime, - .comptime_reason = block.comptime_reason, - .is_typeof = block.is_typeof, - .c_import_buf = block.c_import_buf, - .runtime_cond = block.runtime_cond, - .runtime_loop = block.runtime_loop, - .runtime_index = block.runtime_index, - .error_return_trace_index = block.error_return_trace_index, - }; - const merges = &child_block.label.?.merges; - defer child_block.instructions.deinit(gpa); - defer merges.deinit(gpa); - if (try sema.resolveDefinedValue(&child_block, src, raw_operand_val)) |operand_val| { if (operand_val.errorUnionIsPayload(mod)) { return sema.resolveBlockBody(block, operand_src, &child_block, non_error_case.body, inst, merges); -- 2.54.0