FIR: Fix regression-like CONFLICTING_JVM_DECLARATIONS

See the class org.ini4j.Ini used in intelliJ (derived kt class MyIni)
It contains inherited remove override with the following signature:
String remove(Object sectionName, Object optionName)

While also, from kotlin.collections.MutableMap we inherit
boolean remove(Object, Object)

And we should treat them as different methods to have correct signatures
in resulting class scope
This commit is contained in:
Denis.Zharkov
2022-04-25 13:12:16 +03:00
committed by teamcity
parent 784a911d1a
commit 40119cb041
7 changed files with 29 additions and 4 deletions
@@ -63,6 +63,8 @@ class JavaClassUseSiteMemberScope(
private val canUseSpecialGetters: Boolean by lazy { !klass.hasKotlinSuper(session) }
private val javaOverrideChecker: JavaOverrideChecker get() = overrideChecker as JavaOverrideChecker
private fun generateSyntheticPropertySymbol(
getterSymbol: FirNamedFunctionSymbol,
setterSymbol: FirNamedFunctionSymbol?,
@@ -343,8 +345,9 @@ class JavaClassUseSiteMemberScope(
destination: MutableCollection<FirNamedFunctionSymbol>
) {
val resultsOfIntersectionToSaveInCache = mutableListOf<ResultOfIntersection<FirNamedFunctionSymbol>>()
val list = supertypeScopeContext.convertGroupedCallablesToIntersectionResults(functionsFromSupertypesWithRequestedName)
for (resultOfIntersectionWithNaturalName in list) {
val intersectionResults =
supertypeScopeContext.convertGroupedCallablesToIntersectionResults(functionsFromSupertypesWithRequestedName)
for (resultOfIntersectionWithNaturalName in intersectionResults) {
val someSymbolWithNaturalNameFromSuperType = resultOfIntersectionWithNaturalName.extractSomeSymbolFromSuperType()
val explicitlyDeclaredFunctionWithNaturalName = explicitlyDeclaredFunctionsWithNaturalName.firstOrNull {
overrideChecker.isOverriddenFunction(it, someSymbolWithNaturalNameFromSuperType)
@@ -415,7 +418,8 @@ class JavaClassUseSiteMemberScope(
?.symbol as? FirNamedFunctionSymbol
?: unwrappedSubstitutionOverride.symbol
val originalDeclaredFunction = declaredMemberScope.getFunctions(naturalName).firstOrNull {
it.hasSameJvmDescriptor(functionFromSupertypeWithErasedParameterType) && it.hasErasedParameters()
it.hasSameJvmDescriptor(functionFromSupertypeWithErasedParameterType) && it.hasErasedParameters() &&
javaOverrideChecker.doesReturnTypesHaveSameKind(functionFromSupertypeWithErasedParameterType.fir, it.fir)
} ?: return false
val renamedDeclaredFunction = buildJavaMethodCopy(originalDeclaredFunction.fir as FirJavaMethod) {
name = naturalName
@@ -90,7 +90,7 @@ class JavaOverrideChecker internal constructor(
// In most cases checking erasure of value parameters should be enough, but in some cases there might be semi-valid Java hierarchies
// with same value parameters, but different return type kinds, so it's worth distinguishing them as different non-overridable members
private fun doesReturnTypesHaveSameKind(
fun doesReturnTypesHaveSameKind(
candidate: FirSimpleFunction,
base: FirSimpleFunction,
): Boolean {
@@ -0,0 +1,4 @@
package test;
public interface A extends java.util.Map<String, String> {
String remove(Object x, Object y);
}
@@ -0,0 +1,4 @@
package test;
public abstract class B implements java.util.Map<String, String>, A {
public String remove(Object x, Object y) { return x; }
}
@@ -0,0 +1,3 @@
package test
abstract class C : B()
@@ -638,6 +638,15 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration
)
}
fun testFirIncorrectRemoveSignature() {
compileKotlin(
"source.kt", tmpdir,
listOf(),
additionalOptions = listOf("-Xuse-k2"),
additionalSources = listOf("A.java", "B.java"),
)
}
fun testOldJvmAgainstJvmIr() {
val library = compileLibrary("library", additionalOptions = listOf("-Xuse-ir"))
compileKotlin("source.kt", tmpdir, listOf(library))