[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:
+6
@@ -2718,6 +2718,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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
|
@Test
|
||||||
@TestMetadata("nested.kt")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
|
|||||||
+2
-3
@@ -56,7 +56,7 @@ class IrInlineCodegen(
|
|||||||
val isInlineParameter = irValueParameter.isInlineParameter()
|
val isInlineParameter = irValueParameter.isInlineParameter()
|
||||||
if (isInlineParameter && argumentExpression.isInlineIrExpression()) {
|
if (isInlineParameter && argumentExpression.isInlineIrExpression()) {
|
||||||
val irReference = (argumentExpression as IrBlock).statements.filterIsInstance<IrFunctionReference>().single()
|
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)
|
rememberClosure(parameterType, irValueParameter.index, lambdaInfo)
|
||||||
lambdaInfo.generateLambdaBody(sourceCompiler)
|
lambdaInfo.generateLambdaBody(sourceCompiler)
|
||||||
lambdaInfo.reference.getArgumentsWithIr().forEachIndexed { index, (_, ir) ->
|
lambdaInfo.reference.getArgumentsWithIr().forEachIndexed { index, (_, ir) ->
|
||||||
@@ -117,9 +117,8 @@ class IrInlineCodegen(
|
|||||||
class IrExpressionLambdaImpl(
|
class IrExpressionLambdaImpl(
|
||||||
codegen: ExpressionCodegen,
|
codegen: ExpressionCodegen,
|
||||||
val reference: IrFunctionReference,
|
val reference: IrFunctionReference,
|
||||||
irValueParameter: IrValueParameter
|
|
||||||
) : ExpressionLambda(), IrExpressionLambda {
|
) : 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
|
val function: IrFunction
|
||||||
get() = reference.symbol.owner
|
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")
|
||||||
|
}
|
||||||
+6
@@ -2628,6 +2628,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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
|
@Test
|
||||||
@TestMetadata("nested.kt")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
|
|||||||
+6
@@ -2718,6 +2718,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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
|
@Test
|
||||||
@TestMetadata("nested.kt")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
|
|||||||
+5
@@ -2311,6 +2311,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -1571,6 +1571,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||||
|
|||||||
Generated
+5
@@ -1571,6 +1571,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||||
|
|||||||
Generated
+5
@@ -1571,6 +1571,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||||
|
|||||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -1346,6 +1346,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
|||||||
runTest("compiler/testData/codegen/box/callableReference/kt46902.kt");
|
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")
|
@TestMetadata("nested.kt")
|
||||||
public void testNested() throws Exception {
|
public void testNested() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user