Commit 970f954039

Mitchell Hashimoto <mitchell.hashimoto@gmail.com>
2022-02-01 06:24:37
stage2: cmp_eq between untyped undefines values results in undef bool
1 parent 3e99495
Changed files (2)
src
test
behavior
src/Sema.zig
@@ -9244,9 +9244,9 @@ fn cmpSelf(
     const resolved_type = sema.typeOf(casted_lhs);
     const runtime_src: LazySrcLoc = src: {
         if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| {
-            if (lhs_val.isUndef()) return sema.addConstUndef(resolved_type);
+            if (lhs_val.isUndef()) return sema.addConstUndef(Type.initTag(.bool));
             if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {
-                if (rhs_val.isUndef()) return sema.addConstUndef(resolved_type);
+                if (rhs_val.isUndef()) return sema.addConstUndef(Type.initTag(.bool));
 
                 if (lhs_val.compare(op, rhs_val, resolved_type)) {
                     return Air.Inst.Ref.bool_true;
@@ -9265,7 +9265,7 @@ fn cmpSelf(
             // bool eq/neq more efficiently.
             if (resolved_type.zigTypeTag() == .Bool) {
                 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {
-                    if (rhs_val.isUndef()) return sema.addConstUndef(resolved_type);
+                    if (rhs_val.isUndef()) return sema.addConstUndef(Type.initTag(.bool));
                     return sema.runtimeBoolCmp(block, op, casted_lhs, rhs_val.toBool(), lhs_src);
                 }
             }
test/behavior/math.zig
@@ -1024,8 +1024,6 @@ test "vector comparison" {
 }
 
 test "compare undefined literal with comptime_int" {
-    if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
-
     var x = undefined == 1;
     // x is now undefined with type bool
     x = true;