[JVM_IR] Fix inlining of callable references to extension methods.

Check directly that the referenced function is an extension
function instead of relying on the annotation on the type.

^ KT-47988 Fixed.
This commit is contained in:
Mads Ager
2021-08-09 16:01:20 +02:00
committed by max-kammerer
parent 1760befa37
commit 608b88996a
10 changed files with 62 additions and 3 deletions
@@ -2718,6 +2718,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@Test
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@Test
@TestMetadata("nested.kt")
public void testNested() throws Exception {
@@ -56,7 +56,7 @@ class IrInlineCodegen(
val isInlineParameter = irValueParameter.isInlineParameter()
if (isInlineParameter && argumentExpression.isInlineIrExpression()) {
val irReference = (argumentExpression as IrBlock).statements.filterIsInstance<IrFunctionReference>().single()
val lambdaInfo = IrExpressionLambdaImpl(codegen, irReference, irValueParameter)
val lambdaInfo = IrExpressionLambdaImpl(codegen, irReference)
rememberClosure(parameterType, irValueParameter.index, lambdaInfo)
lambdaInfo.generateLambdaBody(sourceCompiler)
lambdaInfo.reference.getArgumentsWithIr().forEachIndexed { index, (_, ir) ->
@@ -117,9 +117,8 @@ class IrInlineCodegen(
class IrExpressionLambdaImpl(
codegen: ExpressionCodegen,
val reference: IrFunctionReference,
irValueParameter: IrValueParameter
) : ExpressionLambda(), IrExpressionLambda {
override val isExtensionLambda: Boolean = irValueParameter.type.isExtensionFunctionType && reference.extensionReceiver == null
override val isExtensionLambda: Boolean = function.extensionReceiverParameter != null && reference.extensionReceiver == null
val function: IrFunction
get() = reference.symbol.owner
@@ -0,0 +1,17 @@
class A(var x: String)
fun f(s: String): String {
fun A.localX() {
x = s + "K"
}
val a: A = A("FAIL")
a.apply(A::localX)
if (a.x != "OK") return a.x
a.apply { localX() }
return a.x
}
fun box(): String {
return f("O")
}
@@ -2628,6 +2628,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@Test
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@Test
@TestMetadata("nested.kt")
public void testNested() throws Exception {
@@ -2718,6 +2718,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@Test
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@Test
@TestMetadata("nested.kt")
public void testNested() throws Exception {
@@ -2311,6 +2311,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1571,6 +1571,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1571,6 +1571,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1571,6 +1571,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1346,6 +1346,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
}
@TestMetadata("kt47988.kt")
public void testKt47988() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt47988.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");