@@ -3286,15 +3286,21 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDefault(
3286
3286
// /
3287
3287
// / \returns an empty result on success, or a description of the error.
3288
3288
static CheckTypeWitnessResult checkTypeWitness (TypeChecker &tc, DeclContext *dc,
3289
+ ProtocolDecl *proto,
3289
3290
AssociatedTypeDecl *assocType,
3290
3291
Type type) {
3291
- if (auto superclass = assocType->getSuperclass ()) {
3292
+ auto *moduleDecl = dc->getParentModule ();
3293
+ auto *reqtSig = assocType->getProtocol ()->getRequirementSignature ();
3294
+ auto *depTy = DependentMemberType::get (proto->getSelfInterfaceType (),
3295
+ assocType);
3296
+
3297
+ if (auto superclass = reqtSig->getSuperclassBound (depTy, *moduleDecl)) {
3292
3298
if (!superclass->isExactSuperclassOf (type))
3293
3299
return superclass->getAnyNominal ();
3294
3300
}
3295
3301
3296
3302
// Check protocol conformances.
3297
- for (auto reqProto : assocType-> getConformingProtocols ( )) {
3303
+ for (auto reqProto : reqtSig-> getConformsTo (depTy, *moduleDecl )) {
3298
3304
if (!tc.conformsToProtocol (type, reqProto, dc, None))
3299
3305
return reqProto;
3300
3306
@@ -3323,6 +3329,11 @@ static CheckTypeWitnessResult checkTypeWitness(TypeChecker &tc, DeclContext *dc,
3323
3329
// / Attempt to resolve a type witness via member name lookup.
3324
3330
ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup (
3325
3331
AssociatedTypeDecl *assocType) {
3332
+ if (!Proto->isRequirementSignatureComputed ()) {
3333
+ Conformance->setInvalid ();
3334
+ return ResolveWitnessResult::Missing;
3335
+ }
3336
+
3326
3337
// Look for a member type with the same name as the associated type.
3327
3338
auto candidates = TC.lookupMemberType (DC, Adoptee, assocType->getName (),
3328
3339
NameLookupFlags::ProtocolMembers);
@@ -3342,7 +3353,7 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
3342
3353
continue ;
3343
3354
3344
3355
// Check this type against the protocol requirements.
3345
- if (auto checkResult = checkTypeWitness (TC, DC, assocType,
3356
+ if (auto checkResult = checkTypeWitness (TC, DC, Proto, assocType,
3346
3357
candidate.second )) {
3347
3358
auto reqProto = checkResult.getProtocolOrClass ();
3348
3359
nonViable.push_back ({candidate.first , reqProto});
@@ -3603,7 +3614,7 @@ ConformanceChecker::inferTypeWitnessesViaValueWitnesses(
3603
3614
if (!canInferFromOtherAssociatedType) {
3604
3615
// Check that the type witness meets the
3605
3616
// requirements on the associated type.
3606
- if (auto failed = checkTypeWitness (TC, DC, result.first ,
3617
+ if (auto failed = checkTypeWitness (TC, DC, Proto, result.first ,
3607
3618
result.second )) {
3608
3619
witnessResult.NonViable .push_back (
3609
3620
std::make_tuple (result.first ,result.second ,failed));
@@ -4196,7 +4207,7 @@ void ConformanceChecker::resolveTypeWitnesses() {
4196
4207
if (!defaultType)
4197
4208
return Type ();
4198
4209
4199
- if (auto failed = checkTypeWitness (TC, DC, assocType, defaultType)) {
4210
+ if (auto failed = checkTypeWitness (TC, DC, Proto, assocType, defaultType)) {
4200
4211
// Record the failure, if we haven't seen one already.
4201
4212
if (!failedDefaultedAssocType) {
4202
4213
failedDefaultedAssocType = assocType;
@@ -4231,7 +4242,7 @@ void ConformanceChecker::resolveTypeWitnesses() {
4231
4242
return Type ();
4232
4243
4233
4244
// Make sure that the derived type is sane.
4234
- if (checkTypeWitness (TC, DC, assocType, derivedType)) {
4245
+ if (checkTypeWitness (TC, DC, Proto, assocType, derivedType)) {
4235
4246
diagnoseOrDefer (assocType, true ,
4236
4247
[derivedType](NormalProtocolConformance *conformance) {
4237
4248
// FIXME: give more detail here?
0 commit comments