authorgravatar for mitchell.hashimoto@gmail.comMitchell Hashimoto <mitchell.hashimoto@gmail.com> 2022-01-31 21:24:37-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-01 11:21:23-07:00
log970f954039ae91ffae51b71f408f1f787aadc98a
tree9ba8fc7d7a11ed8c294485b7f7b802679cca9cca
parent3e99495ed8d2a384501338edb4885e709d51bf74

stage2: cmp_eq between untyped undefines values results in undef bool


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

src/Sema.zig+3-3
...@@ -9244,9 +9244,9 @@ fn cmpSelf(...@@ -9244,9 +9244,9 @@ fn cmpSelf(
9244 const resolved_type = sema.typeOf(casted_lhs);9244 const resolved_type = sema.typeOf(casted_lhs);
9245 const runtime_src: LazySrcLoc = src: {9245 const runtime_src: LazySrcLoc = src: {
9246 if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| {9246 if (try sema.resolveMaybeUndefVal(block, lhs_src, casted_lhs)) |lhs_val| {
9247 if (lhs_val.isUndef()) return sema.addConstUndef(resolved_type);9247 if (lhs_val.isUndef()) return sema.addConstUndef(Type.initTag(.bool));
9248 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {9248 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {
9249 if (rhs_val.isUndef()) return sema.addConstUndef(resolved_type);9249 if (rhs_val.isUndef()) return sema.addConstUndef(Type.initTag(.bool));
92509250
9251 if (lhs_val.compare(op, rhs_val, resolved_type)) {9251 if (lhs_val.compare(op, rhs_val, resolved_type)) {
9252 return Air.Inst.Ref.bool_true;9252 return Air.Inst.Ref.bool_true;
...@@ -9265,7 +9265,7 @@ fn cmpSelf(...@@ -9265,7 +9265,7 @@ fn cmpSelf(
9265 // bool eq/neq more efficiently.9265 // bool eq/neq more efficiently.
9266 if (resolved_type.zigTypeTag() == .Bool) {9266 if (resolved_type.zigTypeTag() == .Bool) {
9267 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {9267 if (try sema.resolveMaybeUndefVal(block, rhs_src, casted_rhs)) |rhs_val| {
9268 if (rhs_val.isUndef()) return sema.addConstUndef(resolved_type);9268 if (rhs_val.isUndef()) return sema.addConstUndef(Type.initTag(.bool));
9269 return sema.runtimeBoolCmp(block, op, casted_lhs, rhs_val.toBool(), lhs_src);9269 return sema.runtimeBoolCmp(block, op, casted_lhs, rhs_val.toBool(), lhs_src);
9270 }9270 }
9271 }9271 }
test/behavior/math.zig-2
...@@ -1024,8 +1024,6 @@ test "vector comparison" {...@@ -1024,8 +1024,6 @@ test "vector comparison" {
1024}1024}
10251025
1026test "compare undefined literal with comptime_int" {1026test "compare undefined literal with comptime_int" {
1027 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
1028
1029 var x = undefined == 1;1027 var x = undefined == 1;
1030 // x is now undefined with type bool1028 // x is now undefined with type bool
1031 x = true;1029 x = true;