| ... | @@ -9998,6 +9998,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -9998,6 +9998,8 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 9998 | return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); | 9998 | return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); |
| 9999 | } | 9999 | } |
| 10000 | | 10000 | |
| | 10001 | const backend_supports_is_named_enum = sema.mod.comp.bin_file.options.use_llvm; |
| | 10002 | |
| 10001 | if (scalar_cases_len + multi_cases_len == 0 and !special.is_inline) { | 10003 | if (scalar_cases_len + multi_cases_len == 0 and !special.is_inline) { |
| 10002 | if (empty_enum) { | 10004 | if (empty_enum) { |
| 10003 | return Air.Inst.Ref.void_value; | 10005 | return Air.Inst.Ref.void_value; |
| ... | @@ -10008,6 +10010,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10008,6 +10010,12 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10008 | if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand)) { | 10010 | if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand)) { |
| 10009 | return Air.Inst.Ref.unreachable_value; | 10011 | return Air.Inst.Ref.unreachable_value; |
| 10010 | } | 10012 | } |
| | 10013 | if (backend_supports_is_named_enum and block.wantSafety() and operand_ty.zigTypeTag() == .Enum and |
| | 10014 | (!operand_ty.isNonexhaustiveEnum() or union_originally)) |
| | 10015 | { |
| | 10016 | const ok = try block.addUnOp(.is_named_enum_value, operand); |
| | 10017 | try sema.addSafetyCheck(block, ok, .corrupt_switch); |
| | 10018 | } |
| 10011 | return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); | 10019 | return sema.resolveBlockBody(block, src, &child_block, special.body, inst, merges); |
| 10012 | } | 10020 | } |
| 10013 | | 10021 | |
| ... | @@ -10465,6 +10473,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -10465,6 +10473,13 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 10465 | case_block.wip_capture_scope = wip_captures.scope; | 10473 | case_block.wip_capture_scope = wip_captures.scope; |
| 10466 | case_block.inline_case_capture = .none; | 10474 | case_block.inline_case_capture = .none; |
| 10467 | | 10475 | |
| | 10476 | if (backend_supports_is_named_enum and special.body.len != 0 and block.wantSafety() and |
| | 10477 | operand_ty.zigTypeTag() == .Enum and (!operand_ty.isNonexhaustiveEnum() or union_originally)) |
| | 10478 | { |
| | 10479 | const ok = try case_block.addUnOp(.is_named_enum_value, operand); |
| | 10480 | try sema.addSafetyCheck(&case_block, ok, .corrupt_switch); |
| | 10481 | } |
| | 10482 | |
| 10468 | const analyze_body = if (union_originally and !special.is_inline) | 10483 | const analyze_body = if (union_originally and !special.is_inline) |
| 10469 | for (seen_enum_fields) |seen_field, index| { | 10484 | for (seen_enum_fields) |seen_field, index| { |
| 10470 | if (seen_field != null) continue; | 10485 | if (seen_field != null) continue; |