K2/Java: fix processing of built-in with value parameters to be erased in Java
In this commit we started to create and process a hidden copy for a built-in functions, which value parameters are erased in Java, in case we have an accidental Java override which value parameters are not erased. In this situation attempt to override such a Java override in Kotlin again will lead to inaccessible functions (see changes in containsAndOverload.fir.kt) #KT-64846 In Progress
This commit is contained in:
committed by
Space Team
parent
30ad532ff9
commit
ac729e28da
+23
-3
@@ -493,13 +493,13 @@ class JavaClassUseSiteMemberScope(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
val hasAccidentalOverrideWithDeclaredFunction = explicitlyDeclaredFunctionsWithNaturalName.any {
|
val accidentalOverrideWithDeclaredFunction = explicitlyDeclaredFunctionsWithNaturalName.find {
|
||||||
overrideChecker.isOverriddenFunction(
|
overrideChecker.isOverriddenFunction(
|
||||||
renamedDeclaredFunction,
|
renamedDeclaredFunction,
|
||||||
it
|
it
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!hasAccidentalOverrideWithDeclaredFunction) {
|
if (accidentalOverrideWithDeclaredFunction == null) {
|
||||||
destination += renamedDeclaredFunction
|
destination += renamedDeclaredFunction
|
||||||
directOverriddenFunctions[renamedDeclaredFunction] = listOf(resultOfIntersectionWithNaturalName)
|
directOverriddenFunctions[renamedDeclaredFunction] = listOf(resultOfIntersectionWithNaturalName)
|
||||||
for (overriddenMember in overriddenMembers) {
|
for (overriddenMember in overriddenMembers) {
|
||||||
@@ -508,9 +508,29 @@ class JavaClassUseSiteMemberScope(
|
|||||||
if (explicitlyDeclaredFunctionWithNaturalName != null) {
|
if (explicitlyDeclaredFunctionWithNaturalName != null) {
|
||||||
destination += explicitlyDeclaredFunctionWithNaturalName
|
destination += explicitlyDeclaredFunctionWithNaturalName
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
val newSymbol = FirNamedFunctionSymbol(accidentalOverrideWithDeclaredFunction.callableId)
|
||||||
|
val original = accidentalOverrideWithDeclaredFunction.fir
|
||||||
|
val hiddenFunction = buildSimpleFunctionCopy(original) {
|
||||||
|
name = naturalName
|
||||||
|
symbol = newSymbol
|
||||||
|
dispatchReceiverType = klass.defaultType()
|
||||||
|
}.apply {
|
||||||
|
initialSignatureAttr = original
|
||||||
|
isHiddenToOvercomeSignatureClash = true
|
||||||
|
}
|
||||||
|
destination += hiddenFunction.symbol
|
||||||
|
directOverriddenFunctions[hiddenFunction.symbol] = listOf(resultOfIntersectionWithNaturalName)
|
||||||
|
for (overriddenMember in overriddenMembers) {
|
||||||
|
overrideByBase[overriddenMember.member] = hiddenFunction.symbol
|
||||||
|
}
|
||||||
|
if (explicitlyDeclaredFunctionWithNaturalName != null) {
|
||||||
|
destination += explicitlyDeclaredFunctionWithNaturalName
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirNamedFunctionSymbol.hasSameJvmDescriptor(
|
private fun FirNamedFunctionSymbol.hasSameJvmDescriptor(
|
||||||
|
|||||||
+4
-4
@@ -18,8 +18,8 @@ fun foo(a: A, ka: KA) {
|
|||||||
"" in a
|
"" in a
|
||||||
<!ARGUMENT_TYPE_MISMATCH!>1<!> in a
|
<!ARGUMENT_TYPE_MISMATCH!>1<!> in a
|
||||||
|
|
||||||
ka.contains("")
|
ka.<!UNRESOLVED_REFERENCE!>contains<!>("")
|
||||||
ka.contains(<!ARGUMENT_TYPE_MISMATCH!>1<!>)
|
ka.<!UNRESOLVED_REFERENCE!>contains<!>(1)
|
||||||
"" in ka
|
"" <!UNRESOLVED_REFERENCE!>in<!> ka
|
||||||
<!ARGUMENT_TYPE_MISMATCH!>1<!> in ka
|
1 <!UNRESOLVED_REFERENCE!>in<!> ka
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+5
@@ -5,3 +5,8 @@ KA:
|
|||||||
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 3]
|
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 3]
|
||||||
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/Collection] for type kotlin/collections/MutableCollection<E> [id: 3]
|
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/Collection] for type kotlin/collections/MutableCollection<E> [id: 3]
|
||||||
[Library]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Collection [id: 4]
|
[Library]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Collection [id: 4]
|
||||||
|
[Enhancement]: /* hidden due to clash */ public open operator fun contains(x: R|kotlin/String!|): R|kotlin/Boolean| from Java enhancement scope for /A [id: 5]
|
||||||
|
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|kotlin/String!|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/MutableCollection] for type A [id: 2]
|
||||||
|
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/MutableCollection [id: 3]
|
||||||
|
[SubstitutionOverride(DeclarationSite)]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Substitution scope for [Use site scope of kotlin/collections/Collection] for type kotlin/collections/MutableCollection<E> [id: 3]
|
||||||
|
[Library]: public abstract operator fun contains(element: R|E|): R|kotlin/Boolean| from Use site scope of kotlin/collections/Collection [id: 4]
|
||||||
|
|||||||
Reference in New Issue
Block a user