Parametrize behavior of DescriptorEquivalenceForOverrides::areCallableDescriptorsEquivalent
The changes introduced471134d31eare only needed for the case of HMPP project while for other cases it might break the behavior a bit like in KT-34027 See org.jetbrains.kotlin.resolve.calls.results.OverloadingConflictResolver#filterOutEquivalentCalls Before471134dwe 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. After471134d, 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 straightforward fixing of this exact call-site (using original descriptors) doesn't help: behavior might change in a very subtle way (see org.jetbrains.kotlin.spec.checkers.DiagnosticsTestSpecGenerated.NotLinked.Dfa.Pos#test72) So, the main idea is changing the contract for areCallableDescriptorsEquivalent only when project is HMPP one. ^KT-34027 In Progress
This commit is contained in:
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.isOrOverridesSynthesized
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isTypeRefinementEnabled
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
|
||||
fun <Signature> generateBridgesForFunctionDescriptor(
|
||||
descriptor: FunctionDescriptor,
|
||||
@@ -128,6 +130,6 @@ fun firstSuperMethodFromKotlin(
|
||||
): CallableMemberDescriptor? {
|
||||
return descriptor.overriddenDescriptors.firstOrNull { overridden ->
|
||||
overridden.modality != Modality.ABSTRACT &&
|
||||
(overridden == implementation || OverridingUtil.overrides(overridden, implementation))
|
||||
(overridden == implementation || OverridingUtil.overrides(overridden, implementation, overridden.module.isTypeRefinementEnabled()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import org.jetbrains.kotlin.psi.KtDelegatedSuperTypeEntry
|
||||
import org.jetbrains.kotlin.psi.KtPureClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isTypeRefinementEnabled
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.DelegationFilter
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
@@ -172,7 +174,13 @@ class DelegationResolver<T : CallableMemberDescriptor> private constructor(
|
||||
// this is the actual member of delegateExpressionType that we are delegating to
|
||||
(scope.getContributedFunctions(name, NoLookupLocation.WHEN_CHECK_OVERRIDES) +
|
||||
scope.getContributedVariables(name, NoLookupLocation.WHEN_CHECK_OVERRIDES))
|
||||
.firstOrNull { it == overriddenDescriptor || OverridingUtil.overrides(it, overriddenDescriptor) }
|
||||
.firstOrNull {
|
||||
it == overriddenDescriptor || OverridingUtil.overrides(
|
||||
it,
|
||||
overriddenDescriptor,
|
||||
it.module.isTypeRefinementEnabled()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
actualDelegates.firstOrNull()
|
||||
|
||||
+4
-1
@@ -61,7 +61,10 @@ interface IdentifierInfo {
|
||||
get() = kind == STABLE_VALUE
|
||||
|
||||
override fun equals(other: Any?) =
|
||||
other is Variable && DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent(variable, other.variable)
|
||||
other is Variable &&
|
||||
DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent(
|
||||
variable, other.variable, allowCopiesFromTheSameDeclaration = true
|
||||
)
|
||||
|
||||
override fun hashCode() = variable.name.hashCode() * 31 + variable.containingDeclaration.original.hashCode()
|
||||
|
||||
|
||||
+14
-2
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorEquivalenceForOverrides
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isTypeRefinementEnabled
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.varargParameterPosition
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
@@ -44,6 +45,8 @@ open class OverloadingConflictResolver<C : Any>(
|
||||
private val hasSAMConversion: ((C) -> Boolean)?
|
||||
) {
|
||||
|
||||
private val isTypeRefinementEnabled by lazy { module.isTypeRefinementEnabled() }
|
||||
|
||||
private val resolvedCallHashingStrategy = object : TObjectHashingStrategy<C> {
|
||||
override fun equals(call1: C?, call2: C?): Boolean =
|
||||
if (call1 != null && call2 != null)
|
||||
@@ -72,7 +75,10 @@ open class OverloadingConflictResolver<C : Any>(
|
||||
}
|
||||
|
||||
val noEquivalentCalls = filterOutEquivalentCalls(fixedCandidates)
|
||||
val noOverrides = OverridingUtil.filterOverrides(noEquivalentCalls) { a, b ->
|
||||
val noOverrides = OverridingUtil.filterOverrides(
|
||||
noEquivalentCalls,
|
||||
isTypeRefinementEnabled
|
||||
) { a, b ->
|
||||
val aDescriptor = a.resultingDescriptor
|
||||
val bDescriptor = b.resultingDescriptor
|
||||
// Here we'd like to handle situation when we have two synthetic descriptors as in syntheticSAMExtensions.kt
|
||||
@@ -121,7 +127,13 @@ open class OverloadingConflictResolver<C : Any>(
|
||||
val me = meD.resultingDescriptor
|
||||
val other = otherD.resultingDescriptor
|
||||
val ignoreReturnType = isFromSources(me) != isFromSources(other)
|
||||
if (DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent(me, other, ignoreReturnType)) {
|
||||
if (DescriptorEquivalenceForOverrides.areCallableDescriptorsEquivalent(
|
||||
me,
|
||||
other,
|
||||
isTypeRefinementEnabled,
|
||||
ignoreReturnType
|
||||
)
|
||||
) {
|
||||
continue@outerLoop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ public abstract class ExpectedResolveData {
|
||||
}
|
||||
|
||||
private static void assertDescriptorsEqual(String message, DeclarationDescriptor expected, DeclarationDescriptor actual) {
|
||||
if (DescriptorEquivalenceForOverrides.INSTANCE.areEquivalent(expected, actual)) {
|
||||
if (DescriptorEquivalenceForOverrides.INSTANCE.areEquivalent(expected, actual, true)) {
|
||||
return;
|
||||
}
|
||||
String formatted = "";
|
||||
|
||||
Reference in New Issue
Block a user