[FIR] Ignore private properties in accessor override check

JavaClassUseSiteMemberScope won't return a Java method getFoo if there
is an inherited Kotlin property foo in scope because calling this method
would effectively call the property accessor which is not possible in
Kotlin.
This commit excludes private properties from this consideration because
no accessor methods are generated for them, and so calling a Java method
getFoo is ok.

#KT-58577 Fixed
This commit is contained in:
Kirill Rakhman
2023-05-10 17:48:31 +02:00
committed by Space Team
parent 442844f165
commit 993925f656
8 changed files with 82 additions and 0 deletions
@@ -19732,6 +19732,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
}
@Test
@TestMetadata("privatePropertyAndSetterMultiModule.kt")
public void testPrivatePropertyAndSetterMultiModule() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {
@@ -19732,6 +19732,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
}
@Test
@TestMetadata("privatePropertyAndSetterMultiModule.kt")
public void testPrivatePropertyAndSetterMultiModule() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {
@@ -9,6 +9,9 @@ C:
D:
[Source]: public open override fun getName(): R|kotlin/String| from Java enhancement scope for /D [id: 0]
[Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
[Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Java enhancement scope for /D [id: 0]
[SubstitutionOverride]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1]
[Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft<T & Any, T?>| from Java enhancement scope for /B [id: 2]
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Java enhancement scope for /D [id: 0]
[Source]: private final var name: R|kotlin/String| = R|<local>/name| from Use site scope of /C [id: 0]
@@ -19732,6 +19732,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
}
@Test
@TestMetadata("privatePropertyAndSetterMultiModule.kt")
public void testPrivatePropertyAndSetterMultiModule() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {
@@ -19738,6 +19738,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
}
@Test
@TestMetadata("privatePropertyAndSetterMultiModule.kt")
public void testPrivatePropertyAndSetterMultiModule() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.java.scopes
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.declarations.builder.buildSimpleFunctionCopy
@@ -549,6 +550,8 @@ class JavaClassUseSiteMemberScope(
}
private fun FirPropertySymbol.isOverriddenInClassBy(functionSymbol: FirNamedFunctionSymbol): Boolean {
if (rawStatus.visibility == Visibilities.Private) return false
val accessorDescriptors = when (val fir = fir) {
is FirSyntheticProperty -> {
if (fir.getter.delegate.symbol == functionSymbol || fir.setter?.delegate?.symbol == functionSymbol) return true
@@ -0,0 +1,46 @@
// FIR_IDENTICAL
// SKIP_TXT
// MODULE: lib
// FILE: JBaseInterface.java
public interface JBaseInterface {
String getData2();
void setData2(String data);
String getData4();
void setData4(String data);
String getData5();
void setData5(String data);
}
// FILE: KIntermediateClass.kt
open class KIntermediateClass : JBaseInterface {
private var data2: String? = ""
override fun getData2(): String = ""
override fun setData2(data: String) {}
private var data4: String? = ""
override fun getData4(): String? = ""
override fun setData4(data: String) {}
private var data5: String = ""
override fun getData5(): String = ""
override fun setData5(data: String?) {}
}
// FILE: JChildClass.java
public class JChildClass extends KIntermediateClass {}
// MODULE: main(lib)
// FILE: Main.kt
fun main(editorTabs: JChildClass) {
editorTabs.getData2()
editorTabs.setData2("")
editorTabs.getData4()
editorTabs.setData4("")
editorTabs.getData5()
editorTabs.setData5("")
}
@@ -19738,6 +19738,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/j+k/privateNestedClassStaticMember.kt");
}
@Test
@TestMetadata("privatePropertyAndSetterMultiModule.kt")
public void testPrivatePropertyAndSetterMultiModule() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {