From 597ead5318421befba3619fed389820d241ecc78 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Fri, 23 Sep 2022 14:40:55 -0700 Subject: [PATCH] stage2: Fix usage of getError() Despite the old doc-comment, this function cannot be valid for all types since it operates with only a value and Error (Union) types have overlapping Value representations with other Types. --- src/Sema.zig | 1 + src/value.zig | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 70cff08e29..6daedd12cc 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -11107,6 +11107,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind return; } if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| { + if (!operand_ty.isError()) return; if (val.getError() == null) return; try sema.maybeErrorUnwrapComptime(block, body, err_operand); } diff --git a/src/value.zig b/src/value.zig index ee5b357a70..d24c5a1c17 100644 --- a/src/value.zig +++ b/src/value.zig @@ -2971,9 +2971,10 @@ pub const Value = extern union { }; } - /// Valid for all types. Asserts the value is not undefined and not unreachable. - /// Prefer `errorUnionIsPayload` to find out whether something is an error or not - /// because it works without having to figure out the string. + /// Valid only for error (union) types. Asserts the value is not undefined and not + /// unreachable. For error unions, prefer `errorUnionIsPayload` to find out whether + /// something is an error or not because it works without having to figure out the + /// string. pub fn getError(self: Value) ?[]const u8 { return switch (self.tag()) { .@"error" => self.castTag(.@"error").?.data.name,