[FIR] Don't create synthetic property if getter and property came from the same class

Usually we create synthetic property in java class if there is a property
  from the base kotlin class and getter/setter with a corresponding name
  in the declared scope or one of supertype scopes. But there is a case,
  where the same supertype contains both property and getter:
```
// FILE: Base.kt
open class Base {
    open val b = "O"

    @JvmName("getBJava")
    fun getB() : String = "K"
}

// FILE: Derived.java
public class Derived extends Base {}
```

In this case we shouldn't create synthetic property, because `getB()`
  function is invisible for `Derived` class

^KT-66020 Fixed
This commit is contained in:
Dmitriy Novozhilov
2024-02-26 13:09:21 +02:00
committed by Space Team
parent 513f86f8fc
commit 6a94a3331f
12 changed files with 89 additions and 3 deletions
@@ -35668,6 +35668,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35668,6 +35668,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35519,6 +35519,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35519,6 +35519,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35519,6 +35519,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -175,12 +175,13 @@ class JavaClassUseSiteMemberScope(
}
internal fun syntheticPropertyFromOverride(overriddenProperty: ResultOfIntersection<FirPropertySymbol>): FirSyntheticPropertySymbol? {
val overrideInClass = overriddenProperty.overriddenMembers.firstNotNullOfOrNull { (symbol, _) ->
val overrideInClass = overriddenProperty.overriddenMembers.firstNotNullOfOrNull superMember@{ (symbol, baseScope) ->
// We may call this function at the STATUS phase, which means that using resolved status may lead to cycle
// So we need to use raw status here
if (!symbol.isVisibleInClass(klass.symbol, symbol.rawStatus)) return@firstNotNullOfOrNull null
if (!symbol.isVisibleInClass(klass.symbol, symbol.rawStatus)) return@superMember null
symbol.createOverridePropertyIfExists(declaredMemberScope, takeModalityFromGetter = true)
?: superTypeScopes.firstNotNullOfOrNull { scope ->
?: superTypeScopes.firstNotNullOfOrNull superScope@{ scope ->
if (scope == baseScope) return@superScope null
symbol.createOverridePropertyIfExists(scope, takeModalityFromGetter = false)
}
}
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM_IR
// WITH_STDLIB
// ISSUE: KT-66020
// FILE: Base.kt
open class Base {
open val b = "O"
@JvmName("getBJava")
fun getB() : String = "K"
}
// FILE: Derived.java
public class Derived extends Base {
public static String box() {
Impl x = new Impl();
return x.getB() + x.getBJava();
}
}
// FILE: Impl.kt
class Impl : Derived()
fun box(): String {
return Derived.box()
}
@@ -35519,6 +35519,12 @@ public class JvmAbiConsistencyTestBoxGenerated extends AbstractJvmAbiConsistency
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35519,6 +35519,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35519,6 +35519,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -35519,6 +35519,12 @@ public class FirBlackBoxCodegenTestWithInlineScopesGenerated extends AbstractFir
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@Test
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@Test
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
@@ -30217,6 +30217,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/jvmName/classMembers.kt");
}
@TestMetadata("conflictingGetterAndPropertyInBaseKotlinClass.kt")
public void testConflictingGetterAndPropertyInBaseKotlinClass() {
runTest("compiler/testData/codegen/box/jvmName/conflictingGetterAndPropertyInBaseKotlinClass.kt");
}
@TestMetadata("fakeJvmNameInJava.kt")
public void testFakeJvmNameInJava() {
runTest("compiler/testData/codegen/box/jvmName/fakeJvmNameInJava.kt");