Fix equality comparison of inline classes with primitive underlying type
^KT-54455 Fixed
This commit is contained in:
committed by
teamcity
parent
57f1405d95
commit
aeccc2e787
+6
-2
@@ -9,6 +9,7 @@ import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.*
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.isSmartcastFromHigherThanNullable
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.receiverAndArgs
|
||||
import org.jetbrains.kotlin.backend.jvm.mapping.mapTypeAsDeclaration
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil.isPrimitive
|
||||
import org.jetbrains.kotlin.codegen.DescriptorAsmUtil.genAreEqualCall
|
||||
@@ -18,10 +19,12 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.ir.declarations.isSingleFieldValueClass
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedKotlinType
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.types.isNullable
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.kotlin.types.isNullable
|
||||
@@ -74,12 +77,12 @@ class Equals(val operator: IElementType) : IntrinsicMethod() {
|
||||
}
|
||||
}
|
||||
|
||||
val leftType = with(codegen) { a.asmType }
|
||||
val leftType = codegen.typeMapper.mapTypeAsDeclaration(a.type)
|
||||
if (expression.origin == IrStatementOrigin.EQEQEQ || expression.origin == IrStatementOrigin.EXCLEQEQ) {
|
||||
return referenceEquals(a, b, leftType, codegen, data)
|
||||
}
|
||||
|
||||
val rightType = with(codegen) { b.asmType }
|
||||
val rightType = codegen.typeMapper.mapTypeAsDeclaration(b.type)
|
||||
|
||||
// Avoid boxing for `primitive == object` and `boxed primitive == primitive` where we know
|
||||
// what comparison means. The optimization does not apply to `object == primitive` as equals
|
||||
@@ -113,6 +116,7 @@ class Equals(val operator: IElementType) : IntrinsicMethod() {
|
||||
val rightValue = codegen.generateClassLiteralReference(b, wrapIntoKClass = false, wrapPrimitives = true, data = data)
|
||||
BooleanComparison(operator, leftValue, rightValue)
|
||||
}
|
||||
|
||||
else -> {
|
||||
a.accept(codegen, data).materializeAt(AsmTypes.OBJECT_TYPE, codegen.context.irBuiltIns.anyNType)
|
||||
b.accept(codegen, data).materializeAt(AsmTypes.OBJECT_TYPE, codegen.context.irBuiltIns.anyNType)
|
||||
|
||||
Reference in New Issue
Block a user