KT-57103 Don't inline references to generic synthetic Java properties in K1

This commit is contained in:
Pavel Mikhailovskii
2023-03-07 17:35:04 +00:00
committed by Space Team
parent 5ddd60a015
commit 9db5ea66a6
6 changed files with 53 additions and 4 deletions
@@ -50193,6 +50193,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/syntheticExtensions/kt56154.kt");
}
@Test
@TestMetadata("kt57103.kt")
public void testKt57103() throws Exception {
runTest("compiler/testData/codegen/box/syntheticExtensions/kt57103.kt");
}
@Test
@TestMetadata("overrideKotlinPropertyByJavaMethod.kt")
public void testOverrideKotlinPropertyByJavaMethod() throws Exception {
@@ -50193,6 +50193,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/syntheticExtensions/kt56154.kt");
}
@Test
@TestMetadata("kt57103.kt")
public void testKt57103() throws Exception {
runTest("compiler/testData/codegen/box/syntheticExtensions/kt57103.kt");
}
@Test
@TestMetadata("overrideKotlinPropertyByJavaMethod.kt")
public void testOverrideKotlinPropertyByJavaMethod() throws Exception {
@@ -78,8 +78,16 @@ private class InlineCallableReferenceToLambdaVisitor(val context: JvmBackendCont
this is IrFunctionReference -> // ::function -> { args... -> function(args...) }
wrapFunction(symbol.owner).toLambda(this, scope!!)
this is IrPropertyReference -> // ::property -> { receiver -> receiver.property }; prefer direct field access if allowed.
(if (field != null) wrapField(field!!.owner) else wrapFunction(getter!!.owner)).toLambda(this, scope!!)
this is IrPropertyReference ->
// References to generic synthetic Java properties aren't inlined in K1. Fixes KT-57103
if (typeArgumentsCount > 0 &&
symbol.owner.origin.let {
it == IrDeclarationOrigin.SYNTHETIC_JAVA_PROPERTY_DELEGATE || it == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
}
) this
// ::property -> { receiver -> receiver.property }; prefer direct field access if allowed.
else (if (field != null) wrapField(field!!.owner) else wrapFunction(getter!!.owner)).toLambda(this, scope!!)
else -> this // not an inline argument
}
@@ -1,6 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_K1: JVM_IR
// K1_STATUS: Broken because of KT-57103
// FILE: J.java
@@ -0,0 +1,25 @@
// !LANGUAGE: +ReferencesToSyntheticJavaProperties
// TARGET_BACKEND: JVM_IR
// FILE: J.java
public class J<T> {
private final T value;
public J(T value) {
this.value = value;
}
public T getValue() {
return value;
}
public T foo() {
return value;
}
}
// FILE: test.kt
fun box(): String {
val j = J("OK")
return run(j::value)
}
@@ -50193,6 +50193,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/syntheticExtensions/kt56154.kt");
}
@Test
@TestMetadata("kt57103.kt")
public void testKt57103() throws Exception {
runTest("compiler/testData/codegen/box/syntheticExtensions/kt57103.kt");
}
@Test
@TestMetadata("overrideKotlinPropertyByJavaMethod.kt")
public void testOverrideKotlinPropertyByJavaMethod() throws Exception {