Fix over-optimized comparison with null

This commit is contained in:
Alexander Udalov
2013-02-07 16:49:27 +04:00
committed by Alexander Udalov
parent 1670831269
commit 83b93071d3
3 changed files with 20 additions and 2 deletions
@@ -2386,11 +2386,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
Type leftType = expressionType(left);
Type rightType = expressionType(right);
if (leftType.equals(JET_NOTHING_TYPE)) {
if (JetPsiUtil.isNullConstant(left)) {
return genCmpWithNull(right, rightType, opToken);
}
if (rightType.equals(JET_NOTHING_TYPE)) {
if (JetPsiUtil.isNullConstant(right)) {
return genCmpWithNull(left, leftType, opToken);
}
@@ -0,0 +1,13 @@
var entered = 0
fun foo<T>(t: T): T {
entered++
return t
}
fun box(): String {
if (foo(null) == null) {}
if (null == foo(null)) {}
if (foo(null) == foo(null)) {}
return if (entered == 4) "OK" else "Fail $entered"
}
@@ -2775,6 +2775,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/primitiveTypes"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("comparisonWithNullCallsFun.kt")
public void testComparisonWithNullCallsFun() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/comparisonWithNullCallsFun.kt");
}
@TestMetadata("ea35963.kt")
public void testEa35963() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/box/primitiveTypes/ea35963.kt");