Commit 597ead5318

Cody Tapscott <topolarity@tapscott.me>
2022-09-23 23:40:55
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.
1 parent b529d8e
Changed files (2)
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);
     }
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,