Restore correct overloads ambiguity accidentally removed in 1.3.60

This problem is only relevant when isTypeRefinementEnabled == true (HMPP projects)

Ambiguity accidentally was removed after 471134d
There, for areCallableDescriptorsEquivalent we stopped assuming
as impossible a situation of having identity-different descriptors
in the same containing declaraton that still might be considered equal

So, before 471134d we were comparing
"fun foo(x: String)" with "[substituted] fun foo(x: String)"
and areCallableDescriptorsEquivalent returned false for such case.
Thus, both overrides were left in the resulting set.

After 471134d, those two descriptors
becamed considered as equal thus having a possibility to remove any of them.

The problem is that "areCallableDescriptorsEquivalent" has kind of
unclear contract. Effectively it checks whether two descriptors match
to the same declaration.

But some of the usages expect that it also makes sure that descriptors
have the same substitution (see org.jetbrains.kotlin.resolve.calls.smartcasts.IdentifierInfo.Variable#equals)

So, the straight solution is using original descriptors for the cases
where we need to make sure that descriptors relates to actually different
declarations

^KT-34027 Fixed
This commit is contained in:
Denis Zharkov
2019-09-30 17:18:43 +03:00
parent 67410f7a57
commit f91db5f0b8
10 changed files with 77 additions and 2 deletions
@@ -124,8 +124,8 @@ open class OverloadingConflictResolver<C : Any>(
val result = LinkedHashSet<C>()
outerLoop@ for (meD in fromSourcesGoesFirst) {
for (otherD in result) {
val me = meD.resultingDescriptor
val other = otherD.resultingDescriptor
val me = meD.resultingDescriptor.originalIfTypeRefinementEnabled
val other = otherD.resultingDescriptor.originalIfTypeRefinementEnabled
val ignoreReturnType = isFromSources(me) != isFromSources(other)
if (DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent(
me,
@@ -143,6 +143,8 @@ open class OverloadingConflictResolver<C : Any>(
return result
}
private val CallableDescriptor.originalIfTypeRefinementEnabled get() = if (isTypeRefinementEnabled) original else this
private fun Collection<C>.setIfOneOrEmpty() = when (size) {
0 -> emptySet()
1 -> setOf(single())