Fix for KT-11163: Incorrect codegen in case of custom compareTo on primitives
#KT-11163 Fixed
This commit is contained in:
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
|
|||||||
import org.jetbrains.kotlin.codegen.context.*;
|
import org.jetbrains.kotlin.codegen.context.*;
|
||||||
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
|
import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension;
|
||||||
import org.jetbrains.kotlin.codegen.inline.*;
|
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.IntrinsicMethod;
|
||||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
|
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicMethods;
|
||||||
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicPropertyGetter;
|
import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicPropertyGetter;
|
||||||
@@ -3131,7 +3132,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
|
|||||||
StackValue rightValue;
|
StackValue rightValue;
|
||||||
Type leftType = expressionType(left);
|
Type leftType = expressionType(left);
|
||||||
Type rightType = expressionType(right);
|
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);
|
type = comparisonOperandType(leftType, rightType);
|
||||||
leftValue = gen(left);
|
leftValue = gen(left);
|
||||||
rightValue = gen(right);
|
rightValue = gen(right);
|
||||||
|
|||||||
@@ -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')
|
||||||
|
}
|
||||||
+6
@@ -367,6 +367,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kt6747_identityEquals.kt")
|
||||||
public void testKt6747_identityEquals() throws Exception {
|
public void testKt6747_identityEquals() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/binaryOp/kt6747_identityEquals.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user