diff --git a/mypyc/rt_subtype.py b/mypyc/rt_subtype.py index f3fe1a442d22..004e56ed75bc 100644 --- a/mypyc/rt_subtype.py +++ b/mypyc/rt_subtype.py @@ -51,7 +51,7 @@ def visit_rinstance(self, left: RInstance) -> bool: return is_subtype(left, self.right) def visit_runion(self, left: RUnion) -> bool: - return is_subtype(left, self.right) + return not self.right.is_unboxed and is_subtype(left, self.right) def visit_rprimitive(self, left: RPrimitive) -> bool: if is_short_int_rprimitive(left) and is_int_rprimitive(self.right): diff --git a/mypyc/test-data/run-bools.test b/mypyc/test-data/run-bools.test index 522296592c54..6d4244286185 100644 --- a/mypyc/test-data/run-bools.test +++ b/mypyc/test-data/run-bools.test @@ -221,3 +221,9 @@ def test_mixed_comparisons_i64() -> None: assert neq_mixed_i64(n, x) == (n != int(x)) assert lt_mixed_i64(x, n) == (int(x) < n) assert gt_mixed_i64(n, x) == (n > int(x)) + +[case testBoolMixInt] +y = False +print((y or 0) and True) +[out] +0 \ No newline at end of file diff --git a/mypyc/test/test_typeops.py b/mypyc/test/test_typeops.py index f414edd1a2bb..0d9860d88ffe 100644 --- a/mypyc/test/test_typeops.py +++ b/mypyc/test/test_typeops.py @@ -54,6 +54,13 @@ def test_bool(self) -> None: assert not is_runtime_subtype(bool_rprimitive, bit_rprimitive) assert not is_runtime_subtype(bool_rprimitive, int_rprimitive) + def test_union(self) -> None: + bool_int_mix = RUnion([bool_rprimitive, int_rprimitive]) + assert not is_runtime_subtype(bool_int_mix, short_int_rprimitive) + assert not is_runtime_subtype(bool_int_mix, int_rprimitive) + assert not is_runtime_subtype(short_int_rprimitive, bool_int_mix) + assert not is_runtime_subtype(int_rprimitive, bool_int_mix) + class TestUnionSimplification(unittest.TestCase): def test_simple_type_result(self) -> None: