mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 13:30:45 +00:00
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:
parent
b529d8e48f
commit
597ead5318
@ -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);
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user