[Invariant Fix] Fix callable equivalence definition in case of refined scopes

Before types refinement has been introduced it was reasonable to assume
that whenever we have two callables in the same declaration
they are actually different

But it become false once types refinement were introduced
and the same declarations may appear as different descriptors' instances
when viewing from different modules

The change does look very fragile because in many cases
source element is NO_SOURCE

At the same time, declaring actually different members
with the same signature is prohibited and may make sense only
in case of source-based members
This commit is contained in:
Denis Zharkov
2019-04-01 15:34:02 +03:00
committed by Dmitry Savvinov
parent 5c2c7e7776
commit 471134d31e
@@ -57,6 +57,12 @@ object DescriptorEquivalenceForOverrides {
return a.index == b.index // We ignore type parameter names
}
private tailrec fun CallableDescriptor.singleSource(): SourceElement? {
if (this !is CallableMemberDescriptor || kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) return source
return overriddenDescriptors.singleOrNull()?.singleSource()
}
fun areCallableDescriptorsEquivalent(
a: CallableDescriptor,
b: CallableDescriptor,
@@ -64,7 +70,10 @@ object DescriptorEquivalenceForOverrides {
): Boolean {
if (a == b) return true
if (a.name != b.name) return false
if (a.containingDeclaration == b.containingDeclaration) return false
if (a.containingDeclaration == b.containingDeclaration) {
if (a.singleSource() != b.singleSource()) return false
if (a is MemberDescriptor && b is MemberDescriptor && a.isExpect != b.isExpect) return false
}
// Distinct locals are not equivalent
if (DescriptorUtils.isLocal(a) || DescriptorUtils.isLocal(b)) return false