From 61290d12259339a8480097d0d318d3c9961a6bcf Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 6 Jun 2016 14:41:19 +0300 Subject: [PATCH] Temporarily disable inline for bound function references --- .../jetbrains/kotlin/codegen/inline/InlineCodegen.java | 8 ++++++++ .../box/callableReference/bound/inline/simpleVal.kt | 8 ++++++++ .../kotlin/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 compiler/testData/codegen/box/callableReference/bound/inline/simpleVal.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index a7107ce8747..bf9c1cab85b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -47,6 +47,7 @@ import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor; +import org.jetbrains.kotlin.types.expressions.DoubleColonLHS; import org.jetbrains.kotlin.types.expressions.LabelResolver; import org.jetbrains.org.objectweb.asm.Label; import org.jetbrains.org.objectweb.asm.MethodVisitor; @@ -699,6 +700,13 @@ public class InlineCodegen extends CallGenerator { // TODO: support inline of property references passed to inlinable function parameters SimpleFunctionDescriptor functionReference = state.getBindingContext().get(BindingContext.FUNCTION, deparenthesized); if (functionReference == null) return false; + + KtExpression receiverExpression = ((KtCallableReferenceExpression) deparenthesized).getReceiverExpression(); + if (receiverExpression != null) { + // TODO (!): support inline for bound function references + DoubleColonLHS lhs = state.getBindingContext().get(BindingContext.DOUBLE_COLON_LHS, receiverExpression); + if (lhs instanceof DoubleColonLHS.Expression) return false; + } } return InlineUtil.isInlineLambdaParameter(valueParameterDescriptor) && diff --git a/compiler/testData/codegen/box/callableReference/bound/inline/simpleVal.kt b/compiler/testData/codegen/box/callableReference/bound/inline/simpleVal.kt new file mode 100644 index 00000000000..fea3e21c688 --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/bound/inline/simpleVal.kt @@ -0,0 +1,8 @@ +inline fun go(f: () -> String) = f() + +fun String.id(): String = this + +fun box(): String { + val x = "OK" + return go(x::id) +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index bfb29438430..20c60db384f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1471,6 +1471,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/inline/simple.kt"); doTest(fileName); } + + @TestMetadata("simpleVal.kt") + public void testSimpleVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/inline/simpleVal.kt"); + doTest(fileName); + } } }