Fix CompareTo intrinsic behavior in no-dot syntax

This commit is contained in:
Alexander Udalov
2013-01-22 19:28:06 +04:00
parent 44dcdde513
commit ab730b7dd5
5 changed files with 43 additions and 1 deletions
@@ -41,8 +41,18 @@ public class CompareTo implements IntrinsicMethod {
StackValue receiver,
@NotNull GenerationState state
) {
JetExpression argument;
assert arguments != null;
JetExpression argument = arguments.get(0);
if (arguments.size() == 1) {
argument = arguments.get(0);
}
else if (arguments.size() == 2) {
receiver = codegen.gen(arguments.get(0));
argument = arguments.get(1);
}
else {
throw new IllegalStateException("Invalid arguments to compareTo: " + arguments);
}
Type type = comparisonOperandType(receiver.type, codegen.expressionType(argument));
receiver.put(type, v);
@@ -0,0 +1,16 @@
fun box(): String {
val sb = StringBuilder()
for (i in -1..1) {
for (j in -1..1) {
val a = i compareTo j
val b = i.compareTo(j)
if (a != b) {
sb.append("$i compareTo $j: $a != $b\n")
}
}
}
if (sb.length() == 0) return "OK"
return "Fail:\n$sb"
}
@@ -0,0 +1,7 @@
fun box(): String {
return justPrint(9 compareTo 4)
}
fun justPrint(value: Int): String {
return if (value > 0) "OK" else "Fail $value"
}
@@ -199,4 +199,8 @@ public class FunctionGenTest extends CodegenTestCase {
assertFalse(text.contains("INVOKEVIRTUAL"));
assertTrue(text.contains("INVOKESPECIAL"));
}
public void testEa33909() {
blackBoxFile("regressions/ea33909.kt");
}
}
@@ -33,6 +33,11 @@ public class IntrinsicsTestGenerated extends AbstractCodegenTest {
public void testAllFilesPresentInIntrinsics() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/intrinsics"), "kt", true);
}
@TestMetadata("compareTo.kt")
public void testCompareTo() throws Exception {
blackBoxFileByFullPath("compiler/testData/codegen/intrinsics/compareTo.kt");
}
@TestMetadata("longRangeWithExplicitDot.kt")
public void testLongRangeWithExplicitDot() throws Exception {