Fix for KT-11163: Incorrect codegen in case of custom compareTo on primitives

#KT-11163 Fixed
This commit is contained in:
Michael Bogdanov
2016-02-24 14:41:19 +03:00
parent 36e84ff23a
commit 582b1c5e66
3 changed files with 21 additions and 1 deletions
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
import org.jetbrains.kotlin.codegen.context.*;
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
import org.jetbrains.kotlin.codegen.inline.*;
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicCallable;
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethod;
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicPropertyGetter;
@@ -3131,7 +3132,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
StackValue rightValue;
Type leftType = expressionType(left);
Type rightType = expressionType(right);
if (isPrimitive(leftType) && isPrimitive(rightType)) {
Callable callable = resolveToCallable((FunctionDescriptor) resolvedCall.getResultingDescriptor(), false, resolvedCall);
if (callable instanceof IntrinsicCallable) {
type = comparisonOperandType(leftType, rightType);
leftValue = gen(left);
rightValue = gen(right);
+12
View File
@@ -0,0 +1,12 @@
operator fun Int.compareTo(c: Char) = 0
fun foo(x: Int, y: Char): String {
if (x < y) {
throw Error()
}
return "${y}K"
}
fun box(): String {
return foo(42, 'O')
}
@@ -367,6 +367,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("kt11163.kt")
public void testKt11163() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/kt11163.kt");
doTest(fileName);
}
@TestMetadata("kt6747_identityEquals.kt")
public void testKt6747_identityEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt");