Do not generate non-standard compareTo as primitive comparison in all backends
Previous changes related to this in the old JVM backend were in582b1c5e66and0482f7e9c5, but they did not affect the `ProperIeee754Comparisons` mode which became the default in 1.4.0. As a result, we had a regression here. Since the `PRIMITIVE_NUMERIC_COMPARISON_INFO` slice is used in psi2ir to determine how to generate the comparison, this fixes the regression both in the old JVM backend, and in all IR backends. #KT-41426 Fixed
This commit is contained in:
+9
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.resolve.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
@@ -36,6 +37,8 @@ object PrimitiveNumericComparisonCallChecker : CallChecker {
|
||||
val binaryExpression = resolvedCall.call.callElement as? KtBinaryExpression ?: return
|
||||
if (!comparisonOperatorTokens.contains(binaryExpression.operationReference.getReferencedNameElementType())) return
|
||||
|
||||
if (!resolvedCall.isStandardComparison()) return
|
||||
|
||||
val leftExpr = binaryExpression.left ?: return
|
||||
val rightExpr = binaryExpression.right ?: return
|
||||
|
||||
@@ -68,6 +71,11 @@ object PrimitiveNumericComparisonCallChecker : CallChecker {
|
||||
)
|
||||
}
|
||||
|
||||
private fun ResolvedCall<*>.isStandardComparison(): Boolean =
|
||||
extensionReceiver == null &&
|
||||
dispatchReceiver != null &&
|
||||
KotlinBuiltIns.isUnderKotlinPackage(resultingDescriptor)
|
||||
|
||||
private fun leastCommonPrimitiveNumericType(t1: KotlinType, t2: KotlinType): KotlinType {
|
||||
val pt1 = t1.promoteIntegerTypeToIntIfRequired()
|
||||
val pt2 = t2.promoteIntegerTypeToIntIfRequired()
|
||||
@@ -112,4 +120,4 @@ object PrimitiveNumericComparisonCallChecker : CallChecker {
|
||||
else ->
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user