aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2023-02-23 14:07:06 +0000
committerVeikka Tuominen <git@vexu.eu>2023-03-09 02:02:19 +0200
commit6d7fb8f19c864f04d3472e5aec161957193e1e7c (patch)
treece9c815592cf46cb5ee6ee3f59ead9554a8e4e99 /src
parent3e99afdbfe9a66bc5461148a4754c1e88b33fb88 (diff)
downloadzig-6d7fb8f19c864f04d3472e5aec161957193e1e7c.tar.gz
zig-6d7fb8f19c864f04d3472e5aec161957193e1e7c.zip
Sema: check type of comptime try operand
Resolves: #14693
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 8c6e3cf05c..840e8a4c6c 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -1612,6 +1612,12 @@ fn analyzeBodyInner(
const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
const err_union = try sema.resolveInst(extra.data.operand);
+ const err_union_ty = sema.typeOf(err_union);
+ if (err_union_ty.zigTypeTag() != .ErrorUnion) {
+ return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
+ err_union_ty.fmt(sema.mod),
+ });
+ }
const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
assert(is_non_err != .none);
const is_non_err_tv = sema.resolveInstConst(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| {
@@ -1619,7 +1625,6 @@ fn analyzeBodyInner(
return err;
};
if (is_non_err_tv.val.toBool()) {
- const err_union_ty = sema.typeOf(err_union);
break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false);
}
const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse