AST: Use availability to disambiguate multiple overlapping conformances

If a conformance is found in an imported module as well as the current module,
and one of the two conformances is conditionally unavailable on the current
deployment target, pick the one that is always available.

Fixes <rdar://problem/78633800>.
This commit is contained in:
Slava Pestov
2021-06-07 00:44:40 -04:00
parent c139bb4a1c
commit a250688a50
6 changed files with 92 additions and 1 deletions

View File

@@ -529,6 +529,18 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
ConformanceEntry *lhs,
ConformanceEntry *rhs,
bool &diagnoseSuperseded) {
// If only one of the conformances is unconditionally available on the
// current deployment target, pick that one.
//
// FIXME: Conformance lookup should really depend on source location for
// this to be 100% correct.
if (lhs->getDeclContext()->isAlwaysAvailableConformanceContext() !=
rhs->getDeclContext()->isAlwaysAvailableConformanceContext()) {
return (lhs->getDeclContext()->isAlwaysAvailableConformanceContext()
? Ordering::Before
: Ordering::After);
}
// If one entry is fixed and the other is not, we have our answer.
if (lhs->isFixed() != rhs->isFixed()) {
// If the non-fixed conformance is not replaceable, we have a failure to