[FIR2IR] Don't generate fake overrides for clashing synthetic properties
If a synthetic prop clashes with a real property (e.g. @JvmField property from parent Kotlin class), don't generate fake override for the synthetic property. This fixes a CONFLICTING_INHERITED_JVM_DECLARATIONS error in a mixed hierarchy. ^KT-56538 Fixed
This commit is contained in:
committed by
Space Team
parent
d84490dcfa
commit
7f8dc56d36
+11
-6
@@ -83,12 +83,17 @@ class FakeOverrideGenerator(
|
||||
// This parameter is only needed for data-class methods that is irrelevant for lazy library classes
|
||||
realDeclarationSymbols = emptySet()
|
||||
)
|
||||
FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(session, firClass.defaultType(), useSiteMemberScope)?.let {
|
||||
generateFakeOverridesForName(
|
||||
irClass, it, name, firClass, this,
|
||||
// This parameter is only needed for data-class methods that is irrelevant for lazy library classes
|
||||
realDeclarationSymbols = emptySet()
|
||||
)
|
||||
// Only add synthetic properties if no real properties were found. This can happen in a mixed hierarchy when a Java class
|
||||
// inherits an @JvmField property. When a Kotlin class extends that Java class, CONFLICTING_INHERITED_JVM_DECLARATIONS will be
|
||||
// reported otherwise. See KT-56538.
|
||||
if (none { it is IrProperty }) {
|
||||
FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(session, firClass.defaultType(), useSiteMemberScope)?.let {
|
||||
generateFakeOverridesForName(
|
||||
irClass, it, name, firClass, this,
|
||||
// This parameter is only needed for data-class methods that is irrelevant for lazy library classes
|
||||
realDeclarationSymbols = emptySet()
|
||||
)
|
||||
}
|
||||
}
|
||||
if (firClass.isEnumClass) return@buildList // F/O for values/valueOf/entries aren't needed, for other members aren't possible
|
||||
val staticScope = firClass.scopeProvider.getStaticMemberScopeForCallables(firClass, session, scopeSession)
|
||||
|
||||
+6
@@ -28827,6 +28827,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropClashingWithJvmField.kt")
|
||||
public void testSyntheticPropClashingWithJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/syntheticPropClashingWithJvmField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-56538
|
||||
|
||||
// FILE: SerializableScheme.java
|
||||
|
||||
public interface SerializableScheme {
|
||||
String getSchemeState();
|
||||
}
|
||||
|
||||
// FILE: NewInspectionProfile.kt
|
||||
|
||||
abstract class NewInspectionProfile : SerializableScheme {
|
||||
@JvmField
|
||||
internal var schemeState: String? = "OK"
|
||||
|
||||
override fun getSchemeState(): String? = schemeState
|
||||
}
|
||||
|
||||
// FILE: InspectionProfileImpl.java
|
||||
|
||||
public class InspectionProfileImpl extends NewInspectionProfile {
|
||||
}
|
||||
|
||||
// FILE: InspectionProfileModifiableModel.kt
|
||||
|
||||
class InspectionProfileModifiableModel : InspectionProfileImpl()
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun box(): String {
|
||||
return InspectionProfileModifiableModel().schemeState.toString()
|
||||
}
|
||||
+6
@@ -27585,6 +27585,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropClashingWithJvmField.kt")
|
||||
public void testSyntheticPropClashingWithJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/syntheticPropClashingWithJvmField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
|
||||
+6
@@ -28827,6 +28827,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("syntheticPropClashingWithJvmField.kt")
|
||||
public void testSyntheticPropClashingWithJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/syntheticPropClashingWithJvmField.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
|
||||
+5
@@ -23283,6 +23283,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/javaInterop/superCallOfPrintStackTrace.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticPropClashingWithJvmField.kt")
|
||||
public void testSyntheticPropClashingWithJvmField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/syntheticPropClashingWithJvmField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedJavaClassInDifferentFile.kt")
|
||||
public void testUnresolvedJavaClassInDifferentFile() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/javaInterop/unresolvedJavaClassInDifferentFile.kt");
|
||||
|
||||
Reference in New Issue
Block a user