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.
This commit is contained in:
Cody Tapscott 2022-09-23 14:40:55 -07:00
parent b529d8e48f
commit 597ead5318
2 changed files with 5 additions and 3 deletions

View File

@ -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);
}

View File

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