JVM_IR: resolve fake overrides of inline delegated property operators

before checking whether they use the KProperty parameter. (Otherwise the
body is empty and the check always says that the parameter is unused.)

^KT-48825 Fixed
This commit is contained in:
pyos
2021-09-20 16:29:31 +02:00
committed by Alexander Udalov
parent e9d5d9da48
commit 783c3d1500
9 changed files with 71 additions and 1 deletions
@@ -13879,6 +13879,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt42253.kt");
}
@Test
@TestMetadata("kt48825.kt")
public void testKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
@Test
@TestMetadata("lazy.kt")
public void testLazy() throws Exception {
@@ -287,7 +287,8 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : IrEle
for (index in expression.symbol.owner.valueParameters.indices) {
val value = expression.getValueArgument(index)
if (value is IrCallableReference<*> && value.origin == IrStatementOrigin.PROPERTY_REFERENCE_FOR_DELEGATE) {
if (!usesPropertyParameterCache.getOrPut(expression.symbol) { expression.symbol.owner.usesParameter(index) }) {
val resolved = expression.symbol.owner.resolveFakeOverride() ?: expression.symbol.owner
if (!usesPropertyParameterCache.getOrPut(resolved.symbol) { resolved.usesParameter(index) }) {
expression.putValueArgument(index, IrConstImpl.constNull(value.startOffset, value.endOffset, value.type))
}
}
@@ -0,0 +1,31 @@
// IGNORE_BACKEND: JVM
// MODULE: lib
// FILE: lib.kt
import kotlin.reflect.KProperty
open class A {
inline operator fun Int.getValue(thisRef: Any?, property: KProperty<*>): String =
property.name
}
// MODULE: main(lib)
// FILE: main.kt
import kotlin.reflect.KProperty
open class B : A() {
var result = "fail"
inline operator fun String.getValue(thisRef: Any?, property: KProperty<*>): String =
property.name
inline operator fun String.setValue(thisRef: Any?, property: KProperty<*>, value: String) {
result = this + property.name
}
}
class C : B() {
val O by 1
var K by O
}
fun box() = C().run { K = "..."; result }
@@ -13801,6 +13801,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt42253.kt");
}
@Test
@TestMetadata("kt48825.kt")
public void testKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
@Test
@TestMetadata("lazy.kt")
public void testLazy() throws Exception {
@@ -13879,6 +13879,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt42253.kt");
}
@Test
@TestMetadata("kt48825.kt")
public void testKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
@Test
@TestMetadata("lazy.kt")
public void testLazy() throws Exception {
@@ -11185,6 +11185,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class OptimizedDelegatedProperties extends AbstractLightAnalysisModeTest {
@TestMetadata("kt48825.kt")
public void ignoreKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -10027,6 +10027,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt42253.kt");
}
@TestMetadata("kt48825.kt")
public void testKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
@TestMetadata("lazy.kt")
public void testLazy() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/lazy.kt");
@@ -9433,6 +9433,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt42253.kt");
}
@TestMetadata("kt48825.kt")
public void testKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
@TestMetadata("lazy.kt")
public void testLazy() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/lazy.kt");
@@ -9413,6 +9413,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt42253.kt");
}
@TestMetadata("kt48825.kt")
public void testKt48825() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/kt48825.kt");
}
@TestMetadata("lazy.kt")
public void testLazy() throws Exception {
runTest("compiler/testData/codegen/box/delegatedProperty/optimizedDelegatedProperties/lazy.kt");