@@ -900,7 +900,7 @@ matchWitness(TypeChecker &tc,
900
900
static RequirementMatch
901
901
matchWitness (TypeChecker &tc,
902
902
ProtocolDecl *proto,
903
- NormalProtocolConformance *conformance,
903
+ ProtocolConformance *conformance,
904
904
DeclContext *dc, ValueDecl *req, ValueDecl *witness) {
905
905
using namespace constraints ;
906
906
@@ -4945,6 +4945,26 @@ TypeChecker::findWitnessedObjCRequirements(const ValueDecl *witness,
4945
4945
if ((*conformance)->getWitness (req, this ).getDecl () == witness) {
4946
4946
result.push_back (req);
4947
4947
if (anySingleRequirement) return result;
4948
+ continue ;
4949
+ }
4950
+
4951
+ // If we have an inherited conformance, check whether the potential
4952
+ // witness matches the requirement.
4953
+ // FIXME: for now, don't even try this with generics involved. We
4954
+ // should be tracking how subclasses implement optional requirements,
4955
+ // in which case the getWitness() check above would suffice.
4956
+ if (req->getAttrs ().hasAttribute <OptionalAttr>() &&
4957
+ isa<InheritedProtocolConformance>(*conformance)) {
4958
+ auto normal = (*conformance)->getRootNormalConformance ();
4959
+ if (!(*conformance)->getDeclContext ()->getGenericSignatureOfContext () &&
4960
+ !normal->getDeclContext ()->getGenericSignatureOfContext () &&
4961
+ matchWitness (*this , proto, *conformance, witness->getDeclContext (),
4962
+ req, const_cast <ValueDecl *>(witness)).Kind
4963
+ == MatchKind::ExactMatch) {
4964
+ result.push_back (req);
4965
+ if (anySingleRequirement) return result;
4966
+ continue ;
4967
+ }
4948
4968
}
4949
4969
}
4950
4970
}
0 commit comments