[FIR2IR] Consider isExpect flag for generated synthetic functions
It's actual for value classes ^KT-51969 Fixed
This commit is contained in:
committed by
Space Team
parent
4374ca390a
commit
12a083af25
+6
-1
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDeclarationStatusImpl
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isExpect
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.moduleData
|
||||
import org.jetbrains.kotlin.fir.scopes.unsubstitutedScope
|
||||
@@ -218,6 +219,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
||||
val equalsFunction = createSyntheticIrFunction(
|
||||
EQUALS,
|
||||
components.irBuiltIns.booleanType,
|
||||
isExpect = klass.isExpect,
|
||||
otherParameterNeeded = true
|
||||
)
|
||||
irDataClassMembersGenerator.generateEqualsMethod(equalsFunction, properties)
|
||||
@@ -230,6 +232,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
||||
val hashCodeFunction = createSyntheticIrFunction(
|
||||
HASHCODE_NAME,
|
||||
components.irBuiltIns.intType,
|
||||
isExpect = klass.isExpect
|
||||
)
|
||||
irDataClassMembersGenerator.generateHashCodeMethod(hashCodeFunction, properties)
|
||||
irClass.declarations.add(hashCodeFunction)
|
||||
@@ -241,6 +244,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
||||
val toStringFunction = createSyntheticIrFunction(
|
||||
TO_STRING,
|
||||
components.irBuiltIns.stringType,
|
||||
isExpect = klass.isExpect
|
||||
)
|
||||
irDataClassMembersGenerator.generateToStringMethod(toStringFunction, properties)
|
||||
irClass.declarations.add(toStringFunction)
|
||||
@@ -262,6 +266,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
||||
private fun createSyntheticIrFunction(
|
||||
name: Name,
|
||||
returnType: IrType,
|
||||
isExpect: Boolean,
|
||||
otherParameterNeeded: Boolean = false
|
||||
): IrFunction {
|
||||
val functionSymbol = FirNamedFunctionSymbol(CallableId(lookupTag.classId, name))
|
||||
@@ -269,7 +274,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) : Fir2IrCompon
|
||||
origin = FirDeclarationOrigin.Synthetic
|
||||
this.name = name
|
||||
this.symbol = functionSymbol
|
||||
this.status = FirDeclarationStatusImpl(Visibilities.Public, Modality.FINAL)
|
||||
this.status = FirDeclarationStatusImpl(Visibilities.Public, Modality.FINAL).also { it.isExpect = isExpect }
|
||||
moduleData = components.session.moduleData
|
||||
this.returnTypeRef = when (returnType) {
|
||||
components.irBuiltIns.booleanType -> FirImplicitBooleanTypeRef(null)
|
||||
|
||||
+6
@@ -33129,6 +33129,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
public void testKt_56329() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/kt-56329.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClasses.kt")
|
||||
public void testValueClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/valueClasses.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// ISSUE: KT-51969
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// WITH_STDLIB
|
||||
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: expect.kt
|
||||
|
||||
expect value class ExpectValue(val x: String)
|
||||
|
||||
// MODULE: main()()(common)
|
||||
// TARGET_PLATFORM: JVM
|
||||
// FILE: actual.kt
|
||||
|
||||
@JvmInline
|
||||
actual value class ExpectValue actual constructor(actual val x: String)
|
||||
|
||||
fun box() = ExpectValue("OK").x
|
||||
+6
@@ -33129,6 +33129,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
public void testKt_56329() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/kt-56329.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("valueClasses.kt")
|
||||
public void testValueClasses() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/valueClasses.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user