add type check to zirSwitchBlockErrUnion

This commit is contained in:
David Rubin 2024-01-17 16:46:00 -08:00 committed by GitHub
parent ec358d6db5
commit 6e5bdb5397
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 3 deletions

View File

@ -11255,10 +11255,18 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp
defer seen_errors.deinit(); defer seen_errors.deinit();
const operand_ty = sema.typeOf(raw_operand_val); const operand_ty = sema.typeOf(raw_operand_val);
const operand_err_set_ty = if (extra.data.bits.payload_is_ref) const operand_err_set = if (extra.data.bits.payload_is_ref)
operand_ty.childType(mod).errorUnionSet(mod) operand_ty.childType(mod)
else 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); const block_inst: Air.Inst.Index = @enumFromInt(sema.air_instructions.len);
try sema.air_instructions.append(gpa, .{ try sema.air_instructions.append(gpa, .{

View File

@ -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'