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:
+7
-3
@@ -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 {
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package test;
|
||||
public interface A extends java.util.Map<String, String> {
|
||||
String remove(Object x, Object y);
|
||||
}
|
||||
+4
@@ -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; }
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
abstract class C : B()
|
||||
+9
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user