Fix wrong checkcast for === on objects

#KT-6747 Fixed
This commit is contained in:
Alexander Udalov
2015-02-11 03:07:57 +03:00
parent 37ec103d6a
commit a280599969
5 changed files with 33 additions and 12 deletions
@@ -527,10 +527,6 @@ public class AsmUtil {
return StackValue.cmp(opToken, leftType, left, right);
}
if (opToken == JetTokens.EQEQEQ || opToken == JetTokens.EXCLEQEQEQ) {
return StackValue.cmp(opToken, leftType, left, right);
}
return StackValue.operation(Type.BOOLEAN_TYPE, new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
@@ -3056,7 +3056,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
rightType = boxType(rightType);
}
return genEqualsForExpressionsOnStack(opToken, genLazy(left, leftType), genLazy(right, rightType));
StackValue leftValue = genLazy(left, leftType);
StackValue rightValue = genLazy(right, rightType);
if (opToken == JetTokens.EQEQEQ || opToken == JetTokens.EXCLEQEQEQ) {
// TODO: always casting to the type of the left operand in case of primitives looks wrong
Type operandType = isPrimitive(leftType) ? leftType : OBJECT_TYPE;
return StackValue.cmp(opToken, operandType, leftValue, rightValue);
}
return genEqualsForExpressionsOnStack(opToken, leftValue, rightValue);
}
private boolean isIntZero(JetExpression expr, Type exprType) {
@@ -0,0 +1,10 @@
class Test {
fun check(a: Any?): String {
if (this === a) return "Fail 1"
if (!(this !== a)) return "Fail 2"
if (this.identityEquals(a)) return "Fail 3"
return "OK"
}
}
fun box(): String = Test().check("String")
@@ -17,4 +17,4 @@ fun box(): String {
if (!y2) return "Fail (y2): $y"
return "OK"
}
}
@@ -282,6 +282,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt6747_identityEquals.kt")
public void testKt6747_identityEquals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt");
doTest(fileName);
}
@TestMetadata("longOverflow.kt")
public void testLongOverflow() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/longOverflow.kt");
@@ -5276,6 +5282,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("identityEquals.kt")
public void testIdentityEquals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/identityEquals.kt");
doTest(fileName);
}
@TestMetadata("inc.kt")
public void testInc() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/inc.kt");
@@ -5342,12 +5354,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("udentityEquals.kt")
public void testUdentityEquals() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/udentityEquals.kt");
doTest(fileName);
}
@TestMetadata("unaryMinus.kt")
public void testUnaryMinus() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/platformTypes/primitives/unaryMinus.kt");