authorgravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-09-23 14:40:55-07:00
committergravatar for topolarity@tapscott.meCody Tapscott <topolarity@tapscott.me> 2022-10-21 11:22:49-07:00
log597ead5318421befba3619fed389820d241ecc78
tree53be9aa62a94066cc011c6ec0bda9a90bf187623
parentb529d8e48f2082c4e8df10d0ff26e2c7702bb693

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.

2 files changed, 5 insertions(+), 3 deletions(-)

src/Sema.zig+1
......@@ -11107,6 +11107,7 @@ fn maybeErrorUnwrapCondbr(sema: *Sema, block: *Block, body: []const Zir.Inst.Ind
1110711107 return;
1110811108 }
1110911109 if (try sema.resolveDefinedValue(block, cond_src, err_operand)) |val| {
11110 if (!operand_ty.isError()) return;
1111011111 if (val.getError() == null) return;
1111111112 try sema.maybeErrorUnwrapComptime(block, body, err_operand);
1111211113 }
src/value.zig+4-3
......@@ -2971,9 +2971,10 @@ pub const Value = extern union {
29712971 };
29722972 }
29732973
2974 /// Valid for all types. Asserts the value is not undefined and not unreachable.
2975 /// Prefer `errorUnionIsPayload` to find out whether something is an error or not
2976 /// because it works without having to figure out the string.
2974 /// Valid only for error (union) types. Asserts the value is not undefined and not
2975 /// unreachable. For error unions, prefer `errorUnionIsPayload` to find out whether
2976 /// something is an error or not because it works without having to figure out the
2977 /// string.
29772978 pub fn getError(self: Value) ?[]const u8 {
29782979 return switch (self.tag()) {
29792980 .@"error" => self.castTag(.@"error").?.data.name,