[IR] Consider extension receivers during expect functions actualization
^KT-56199 Fixed
This commit is contained in:
committed by
Space Team
parent
0f9107c153
commit
c89770c450
+6
@@ -33028,6 +33028,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectActualDifferentExtensionReceiversOnOverloads.kt")
|
||||
public void testExpectActualDifferentExtensionReceiversOnOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualDifferentExtensionReceiversOnOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectActualDifferentPackages.kt")
|
||||
public void testExpectActualDifferentPackages() throws Exception {
|
||||
|
||||
+22
-2
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
@@ -18,14 +19,33 @@ fun checkParameters(
|
||||
actualFunction: IrFunction,
|
||||
expectActualTypesMap: Map<IrSymbol, IrSymbol>
|
||||
): Boolean {
|
||||
if (expectFunction.valueParameters.size != actualFunction.valueParameters.size) return false
|
||||
for ((expectParameter, actualParameter) in expectFunction.valueParameters.zip(actualFunction.valueParameters)) {
|
||||
fun checkParameter(expectParameter: IrValueParameter?, actualParameter: IrValueParameter?): Boolean {
|
||||
if (expectParameter == null) {
|
||||
return actualParameter == null
|
||||
}
|
||||
if (actualParameter == null) {
|
||||
return false
|
||||
}
|
||||
|
||||
val expectParameterTypeSymbol = expectParameter.type.classifierOrFail
|
||||
val actualizedParameterTypeSymbol = expectActualTypesMap[expectParameterTypeSymbol] ?: expectParameterTypeSymbol
|
||||
if (actualizedParameterTypeSymbol != actualParameter.type.classifierOrFail) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
if (expectFunction.valueParameters.size != actualFunction.valueParameters.size ||
|
||||
!checkParameter(expectFunction.extensionReceiverParameter, actualFunction.extensionReceiverParameter)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
for ((expectParameter, actualParameter) in expectFunction.valueParameters.zip(actualFunction.valueParameters)) {
|
||||
if (!checkParameter(expectParameter, actualParameter)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
|
||||
// MODULE: common
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: common.kt
|
||||
|
||||
expect fun <T> Array<T>.getChecked(index: Int): T
|
||||
|
||||
expect fun BooleanArray.getChecked(index: Int): Boolean
|
||||
|
||||
fun ok() = if (!BooleanArray(1).getChecked(0)) "OK" else "FAIL"
|
||||
|
||||
// MODULE: jvm()()(common)
|
||||
// TARGET_PLATFORM: JVM
|
||||
// FILE: main.kt
|
||||
|
||||
actual fun <T> Array<T>.getChecked(index: Int) = get(index)
|
||||
|
||||
actual fun BooleanArray.getChecked(index: Int) = get(index)
|
||||
|
||||
fun box() = ok()
|
||||
+6
@@ -31762,6 +31762,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/enumEntryNameCall.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectActualDifferentExtensionReceiversOnOverloads.kt")
|
||||
public void testExpectActualDifferentExtensionReceiversOnOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualDifferentExtensionReceiversOnOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectActualMultiCommon.kt")
|
||||
public void testExpectActualMultiCommon() throws Exception {
|
||||
|
||||
+6
@@ -33028,6 +33028,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualCallableReference.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectActualDifferentExtensionReceiversOnOverloads.kt")
|
||||
public void testExpectActualDifferentExtensionReceiversOnOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualDifferentExtensionReceiversOnOverloads.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("expectActualDifferentPackages.kt")
|
||||
public void testExpectActualDifferentPackages() throws Exception {
|
||||
|
||||
+5
@@ -27039,6 +27039,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/enumEntryNameCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expectActualDifferentExtensionReceiversOnOverloads.kt")
|
||||
public void testExpectActualDifferentExtensionReceiversOnOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualDifferentExtensionReceiversOnOverloads.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expectActualMultiCommon.kt")
|
||||
public void testExpectActualMultiCommon() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/multiModule/expectActualMultiCommon.kt");
|
||||
|
||||
Reference in New Issue
Block a user