Do not compare boxed values with 0 via IFEQ/IFNE
This commit is contained in:
@@ -2362,11 +2362,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return genCmpWithNull(left, leftType, opToken);
|
return genCmpWithNull(left, leftType, opToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isIntZero(left, leftType)) {
|
if (isIntZero(left, leftType) && isIntPrimitive(rightType)) {
|
||||||
return genCmpWithZero(right, rightType, opToken);
|
return genCmpWithZero(right, rightType, opToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isIntZero(right, rightType)) {
|
if (isIntZero(right, rightType) && isIntPrimitive(leftType)) {
|
||||||
return genCmpWithZero(left, leftType, opToken);
|
return genCmpWithZero(left, leftType, opToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun box(): String {
|
||||||
|
val x: Int? = 0
|
||||||
|
if (x != 0) return "Fail $x"
|
||||||
|
if (0 != x) return "Fail $x"
|
||||||
|
if (!(x == 0)) return "Fail $x"
|
||||||
|
if (!(0 == x)) return "Fail $x"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -250,6 +250,11 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
assertEquals(false, main.invoke(null, 1, 0));
|
assertEquals(false, main.invoke(null, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCompareBoxedIntegerToZero() {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("controlStructures/compareBoxedIntegerToZero.kt");
|
||||||
|
}
|
||||||
|
|
||||||
public void testCompareToNull() throws Exception {
|
public void testCompareToNull() throws Exception {
|
||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b");
|
loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b");
|
||||||
|
|||||||
Reference in New Issue
Block a user