commit 970f954039ae91ffae51b71f408f1f787aadc98a (tree)
parent 3e99495ed8d2a384501338edb4885e709d51bf74
Author: Mitchell Hashimoto <mitchell.hashimoto@gmail.com>
Date: Mon, 31 Jan 2022 21:24:37 -0800
stage2: cmp_eq between untyped undefines values results in undef bool
Diffstat:
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/Sema.zig b/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);
}
}
diff --git a/test/behavior/math.zig b/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;