Fix CompareTo intrinsic behavior in no-dot syntax
This commit is contained in:
@@ -41,8 +41,18 @@ public class CompareTo implements IntrinsicMethod {
|
|||||||
StackValue receiver,
|
StackValue receiver,
|
||||||
@NotNull GenerationState state
|
@NotNull GenerationState state
|
||||||
) {
|
) {
|
||||||
|
JetExpression argument;
|
||||||
assert arguments != null;
|
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));
|
Type type = comparisonOperandType(receiver.type, codegen.expressionType(argument));
|
||||||
|
|
||||||
receiver.put(type, v);
|
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"));
|
assertFalse(text.contains("INVOKEVIRTUAL"));
|
||||||
assertTrue(text.contains("INVOKESPECIAL"));
|
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 {
|
public void testAllFilesPresentInIntrinsics() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/intrinsics"), "kt", true);
|
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")
|
@TestMetadata("longRangeWithExplicitDot.kt")
|
||||||
public void testLongRangeWithExplicitDot() throws Exception {
|
public void testLongRangeWithExplicitDot() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user