Generate compareTo() properly

Take into account:
1) resolved call to compareTo (instead of always calling Comparable's method)
2) types of both caller and callee, when primitive, to avoid wrong casting
(instead of always using caller's type)

 #KT-3078 Fixed
This commit is contained in:
Alexander Udalov
2012-11-27 22:09:57 +04:00
parent 0c5960922a
commit c9bdfd2f07
16 changed files with 261 additions and 22 deletions
@@ -460,4 +460,8 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testUnboxComparable() {
blackBoxFile("primitiveTypes/unboxComparable.kt");
}
public void testKt3078() {
blackBoxFile("regressions/kt3078.kt");
}
}
@@ -0,0 +1,96 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.codegen.generated;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.codegen.generated.AbstractCodegenTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@TestMetadata("compiler/testData/codegen/operatorConventions")
@InnerTestClasses({OperatorConventionsTestGenerated.CompareTo.class})
public class OperatorConventionsTestGenerated extends AbstractCodegenTest {
public void testAllFilesPresentInOperatorConventions() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/operatorConventions"), "kt", true);
}
@TestMetadata("compiler/testData/codegen/operatorConventions/compareTo")
public static class CompareTo extends AbstractCodegenTest {
public void testAllFilesPresentInCompareTo() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/operatorConventions/compareTo"), "kt", true);
}
@TestMetadata("comparable.kt")
public void testComparable() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/comparable.kt");
}
@TestMetadata("doubleInt.kt")
public void testDoubleInt() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/doubleInt.kt");
}
@TestMetadata("doubleLong.kt")
public void testDoubleLong() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/doubleLong.kt");
}
@TestMetadata("extensionArray.kt")
public void testExtensionArray() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/extensionArray.kt");
}
@TestMetadata("extensionObject.kt")
public void testExtensionObject() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/extensionObject.kt");
}
@TestMetadata("intDouble.kt")
public void testIntDouble() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/intDouble.kt");
}
@TestMetadata("intLong.kt")
public void testIntLong() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/intLong.kt");
}
@TestMetadata("longDouble.kt")
public void testLongDouble() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/longDouble.kt");
}
@TestMetadata("longInt.kt")
public void testLongInt() throws Exception {
doTest("compiler/testData/codegen/operatorConventions/compareTo/longInt.kt");
}
}
public static Test suite() {
TestSuite suite = new TestSuite("OperatorConventionsTestGenerated");
suite.addTestSuite(OperatorConventionsTestGenerated.class);
suite.addTestSuite(CompareTo.class);
return suite;
}
}