[K2, MPP] Support arguments with expect types in actual functions
This commit is contained in:
committed by
Space Team
parent
ec34b9fa7b
commit
ce7af9ff2b
+6
@@ -33256,6 +33256,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/accessToLocalClassFromBackend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualFunctionWithArgumentOfExpectType.kt")
|
||||
public void testActualFunctionWithArgumentOfExpectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/actualFunctionWithArgumentOfExpectType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
|
||||
+6
@@ -33256,6 +33256,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/accessToLocalClassFromBackend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualFunctionWithArgumentOfExpectType.kt")
|
||||
public void testActualFunctionWithArgumentOfExpectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/actualFunctionWithArgumentOfExpectType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
|
||||
+22
-16
@@ -35,10 +35,24 @@ fun Map<String, List<IrDeclaration>>.getMatch(
|
||||
}
|
||||
|
||||
private fun IrFunction.match(actualFunction: IrFunction, expectActualTypesMap: Map<IrSymbol, IrSymbol>): Boolean {
|
||||
fun getActualizedValueParameterSymbol(
|
||||
expectParameter: IrValueParameter,
|
||||
localTypeParametersMap: Map<IrTypeParameterSymbol, IrTypeParameterSymbol>? = null
|
||||
): IrSymbol {
|
||||
return expectParameter.type.classifierOrFail.let {
|
||||
val localMappedSymbol = if (localTypeParametersMap != null && it is IrTypeParameterSymbol) {
|
||||
localTypeParametersMap[it]
|
||||
} else {
|
||||
null
|
||||
}
|
||||
localMappedSymbol ?: expectActualTypesMap[it] ?: it
|
||||
}
|
||||
}
|
||||
|
||||
fun checkParameter(
|
||||
expectParameter: IrValueParameter?,
|
||||
actualParameter: IrValueParameter?,
|
||||
typeParametersMap: Map<IrTypeParameterSymbol, IrTypeParameterSymbol>
|
||||
localTypeParametersMap: Map<IrTypeParameterSymbol, IrTypeParameterSymbol>
|
||||
): Boolean {
|
||||
if (expectParameter == null) {
|
||||
return actualParameter == null
|
||||
@@ -47,17 +61,9 @@ private fun IrFunction.match(actualFunction: IrFunction, expectActualTypesMap: M
|
||||
return false
|
||||
}
|
||||
|
||||
val actualizedParameterTypeSymbol = expectParameter.type.classifierOrFail.let {
|
||||
var mappedSymbol: IrSymbol? = null
|
||||
if (it is IrTypeParameterSymbol) {
|
||||
mappedSymbol = typeParametersMap[it]
|
||||
}
|
||||
if (mappedSymbol == null) {
|
||||
mappedSymbol = expectActualTypesMap[it] ?: it
|
||||
}
|
||||
mappedSymbol
|
||||
}
|
||||
if (actualizedParameterTypeSymbol != actualParameter.type.classifierOrFail) {
|
||||
if (getActualizedValueParameterSymbol(expectParameter, localTypeParametersMap) !=
|
||||
getActualizedValueParameterSymbol(actualParameter)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -67,20 +73,20 @@ private fun IrFunction.match(actualFunction: IrFunction, expectActualTypesMap: M
|
||||
return false
|
||||
}
|
||||
|
||||
val typeParametersMap = mutableMapOf<IrTypeParameterSymbol, IrTypeParameterSymbol>()
|
||||
val localTypeParametersMap = mutableMapOf<IrTypeParameterSymbol, IrTypeParameterSymbol>()
|
||||
for ((expectTypeParameter, actualTypeParameter) in typeParameters.zip(actualFunction.typeParameters)) {
|
||||
if (expectTypeParameter.name != actualTypeParameter.name) {
|
||||
return false
|
||||
}
|
||||
typeParametersMap[expectTypeParameter.symbol] = actualTypeParameter.symbol
|
||||
localTypeParametersMap[expectTypeParameter.symbol] = actualTypeParameter.symbol
|
||||
}
|
||||
|
||||
if (!checkParameter(extensionReceiverParameter, actualFunction.extensionReceiverParameter, typeParametersMap)) {
|
||||
if (!checkParameter(extensionReceiverParameter, actualFunction.extensionReceiverParameter, localTypeParametersMap)) {
|
||||
return false
|
||||
}
|
||||
|
||||
for ((expectParameter, actualParameter) in valueParameters.zip(actualFunction.valueParameters)) {
|
||||
if (!checkParameter(expectParameter, actualParameter, typeParametersMap)) {
|
||||
if (!checkParameter(expectParameter, actualParameter, localTypeParametersMap)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// !LANGUAGE: +MultiPlatformProjects
|
||||
|
||||
// MODULE: common0
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: common0.kt
|
||||
|
||||
expect fun f0(s: S): S
|
||||
|
||||
expect class S
|
||||
|
||||
// MODULE: common1()()(common0)
|
||||
// TARGET_PLATFORM: Common
|
||||
// FILE: common1.kt
|
||||
|
||||
actual fun f0(s: S): S = s
|
||||
|
||||
// MODULE: jvm()()(common1)
|
||||
// TARGET_PLATFORM: JVM
|
||||
// FILE: jvm.kt
|
||||
|
||||
actual typealias S = String
|
||||
|
||||
fun box() = f0("OK")
|
||||
+6
@@ -31888,6 +31888,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/accessToLocalClassFromBackend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualFunctionWithArgumentOfExpectType.kt")
|
||||
public void testActualFunctionWithArgumentOfExpectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/actualFunctionWithArgumentOfExpectType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
|
||||
+6
@@ -33256,6 +33256,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/accessToLocalClassFromBackend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualFunctionWithArgumentOfExpectType.kt")
|
||||
public void testActualFunctionWithArgumentOfExpectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/actualFunctionWithArgumentOfExpectType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
|
||||
+6
@@ -33256,6 +33256,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/accessToLocalClassFromBackend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("actualFunctionWithArgumentOfExpectType.kt")
|
||||
public void testActualFunctionWithArgumentOfExpectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/actualFunctionWithArgumentOfExpectType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
|
||||
+5
@@ -27168,6 +27168,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/accessToLocalClassFromBackend.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("actualFunctionWithArgumentOfExpectType.kt")
|
||||
public void testActualFunctionWithArgumentOfExpectType() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/multiplatform/k2/basic/actualFunctionWithArgumentOfExpectType.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/multiplatform/k2/basic"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user