diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LambdaInfo.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LambdaInfo.kt index b679543f105..f43e6cc26b8 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LambdaInfo.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/LambdaInfo.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCallWithAssert -import org.jetbrains.kotlin.resolve.jvm.AsmTypes +import org.jetbrains.kotlin.resolve.jvm.AsmTypes.* import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.org.objectweb.asm.ClassReader @@ -60,7 +60,7 @@ abstract class LambdaInfo(@JvmField val isCrossInline: Boolean) : FunctionalArgu open val hasDispatchReceiver = true fun addAllParameters(remapper: FieldRemapper): Parameters { - val builder = ParametersBuilder.initializeBuilderFrom(AsmTypes.OBJECT_TYPE, invokeMethod.descriptor, this) + val builder = ParametersBuilder.initializeBuilderFrom(OBJECT_TYPE, invokeMethod.descriptor, this) for (info in capturedVars) { val field = remapper.findField(FieldInsnNode(0, info.containingLambdaName, info.fieldName, "")) @@ -140,8 +140,8 @@ abstract class DefaultLambda( superName: String?, interfaces: Array? ) { - isPropertyReference = superName?.startsWith("kotlin/jvm/internal/PropertyReference") ?: false - isFunctionReference = "kotlin/jvm/internal/FunctionReference" == superName + isPropertyReference = superName in PROPERTY_REFERENCE_SUPER_CLASSES + isFunctionReference = superName == FUNCTION_REFERENCE.internalName super.visit(version, access, name, signature, superName, interfaces) } @@ -202,6 +202,13 @@ abstract class DefaultLambda( } protected abstract fun mapAsmSignature(sourceCompiler: SourceCompilerForInline): Method + + private companion object { + val PROPERTY_REFERENCE_SUPER_CLASSES = listOf( + PROPERTY_REFERENCE0, PROPERTY_REFERENCE1, PROPERTY_REFERENCE2, + MUTABLE_PROPERTY_REFERENCE0, MUTABLE_PROPERTY_REFERENCE1, MUTABLE_PROPERTY_REFERENCE2 + ).mapTo(HashSet(), Type::getInternalName) + } } internal fun Type.boxReceiverForBoundReference() = diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt new file mode 100644 index 00000000000..f240eec619d --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +class A { + var ok: String + get() = "OK" + set(value) {} +} + +inline fun inlineFun(lambda: () -> String = A()::ok): String { + return lambda() +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return inlineFun() +} diff --git a/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt new file mode 100644 index 00000000000..98a4f3a9ac7 --- /dev/null +++ b/compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt @@ -0,0 +1,21 @@ +// FILE: 1.kt +// SKIP_INLINE_CHECK_IN: inlineFun$default +package test + +class A { + var ok: String + get() = "OK" + set(value) {} +} + +inline fun inlineFun(a: A, lambda: (A) -> String = A::ok): String { + return lambda(a) +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return inlineFun(A()) +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index d8c70903a59..9928a668700 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1556,6 +1556,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/innerClassConstuctorReference.kt"); } + @TestMetadata("mutableBoundPropertyReferenceFromClass.kt") + public void testMutableBoundPropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt"); + } + + @TestMetadata("mutablePropertyReferenceFromClass.kt") + public void testMutablePropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt"); + } + @TestMetadata("privateFunctionReference.kt") public void testPrivateFunctionReference() throws Exception { runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/privateFunctionReference.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index ff180f01845..eb8a4507258 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1556,6 +1556,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/innerClassConstuctorReference.kt"); } + @TestMetadata("mutableBoundPropertyReferenceFromClass.kt") + public void testMutableBoundPropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt"); + } + + @TestMetadata("mutablePropertyReferenceFromClass.kt") + public void testMutablePropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt"); + } + @TestMetadata("privateFunctionReference.kt") public void testPrivateFunctionReference() throws Exception { runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/privateFunctionReference.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index e4c98505524..ede7432e6a6 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -1556,6 +1556,16 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/innerClassConstuctorReference.kt"); } + @TestMetadata("mutableBoundPropertyReferenceFromClass.kt") + public void testMutableBoundPropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt"); + } + + @TestMetadata("mutablePropertyReferenceFromClass.kt") + public void testMutablePropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt"); + } + @TestMetadata("privateFunctionReference.kt") public void testPrivateFunctionReference() throws Exception { runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/privateFunctionReference.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index aeb7c4e4b33..3bf2fd54722 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1556,6 +1556,16 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/innerClassConstuctorReference.kt"); } + @TestMetadata("mutableBoundPropertyReferenceFromClass.kt") + public void testMutableBoundPropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt"); + } + + @TestMetadata("mutablePropertyReferenceFromClass.kt") + public void testMutablePropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt"); + } + @TestMetadata("privateFunctionReference.kt") public void testPrivateFunctionReference() throws Exception { runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/privateFunctionReference.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineDefaultValuesTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineDefaultValuesTestsGenerated.java index f88838e5765..61759b626f5 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineDefaultValuesTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrInlineDefaultValuesTestsGenerated.java @@ -373,6 +373,16 @@ public class IrInlineDefaultValuesTestsGenerated extends AbstractIrInlineDefault runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/innerClassConstuctorReference.kt"); } + @TestMetadata("mutableBoundPropertyReferenceFromClass.kt") + public void testMutableBoundPropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt"); + } + + @TestMetadata("mutablePropertyReferenceFromClass.kt") + public void testMutablePropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt"); + } + @TestMetadata("privateFunctionReference.kt") public void testPrivateFunctionReference() throws Exception { runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/privateFunctionReference.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java index f283d9ea379..b94834cf283 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/InlineDefaultValuesTestsGenerated.java @@ -373,6 +373,16 @@ public class InlineDefaultValuesTestsGenerated extends AbstractInlineDefaultValu runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/innerClassConstuctorReference.kt"); } + @TestMetadata("mutableBoundPropertyReferenceFromClass.kt") + public void testMutableBoundPropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutableBoundPropertyReferenceFromClass.kt"); + } + + @TestMetadata("mutablePropertyReferenceFromClass.kt") + public void testMutablePropertyReferenceFromClass() throws Exception { + runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/mutablePropertyReferenceFromClass.kt"); + } + @TestMetadata("privateFunctionReference.kt") public void testPrivateFunctionReference() throws Exception { runTest("compiler/testData/codegen/boxInline/defaultValues/lambdaInlining/callableReferences/privateFunctionReference.kt");