Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11255,10 +11255,18 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
defer seen_errors.deinit();

const operand_ty = sema.typeOf(raw_operand_val);
const operand_err_set_ty = if (extra.data.bits.payload_is_ref)
operand_ty.childType(mod).errorUnionSet(mod)
const operand_err_set = if (extra.data.bits.payload_is_ref)
operand_ty.childType(mod)
else
operand_ty.errorUnionSet(mod);
operand_ty;

if (operand_err_set.zigTypeTag(mod) != .ErrorUnion) {
return sema.fail(block, switch_src, "expected error union type, found '{}'", .{
operand_ty.fmt(mod),
});
}

const operand_err_set_ty = operand_err_set.errorUnionSet(mod);

const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
try sema.air_instructions.append(gpa, .{
Expand Down
11 changes: 11 additions & 0 deletions test/cases/compile_errors/switch_on_non_err_union.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub fn main() void {
false catch |err| switch (err) {
else => {},
};
}

// error
// backend=stage2
// target=native
//
// :2:23: error: expected error union type, found 'bool'