aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorDavid Rubin <87927264+Rexicon226@users.noreply.github.com>2024-01-17 16:46:00 -0800
committerGitHub <noreply@github.com>2024-01-18 00:46:00 +0000
commit6e5bdb5397b5ec5ff3dd6e3ca6f7f93a9b6bfde9 (patch)
tree305f2ad46eb3fc5d37dbf3bfb82a9e0ddf64bf71 /src/Sema.zig
parentec358d6db5a10989590e11bbbbd3bed9f81cf1f4 (diff)
downloadzig-6e5bdb5397b5ec5ff3dd6e3ca6f7f93a9b6bfde9.tar.gz
zig-6e5bdb5397b5ec5ff3dd6e3ca6f7f93a9b6bfde9.zip
add type check to `zirSwitchBlockErrUnion`
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index aa624e06e7..89a5ba0920 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -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, .{