@@ -565,9 +565,7 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
565565
566566 if (selfType->is <GenericTypeParamType>()) {
567567 if (typeDecl->getDeclContext ()->getSelfProtocolDecl ()) {
568- if (isa<AssociatedTypeDecl>(typeDecl) ||
569- (isa<TypeAliasDecl>(typeDecl) &&
570- !cast<TypeAliasDecl>(typeDecl)->isGeneric ())) {
568+ if (isa<AssociatedTypeDecl>(typeDecl)) {
571569 // FIXME: We should use this lookup method for the Interface
572570 // stage too, but right now that causes problems with
573571 // Sequence.SubSequence vs Collection.SubSequence; the former
@@ -1295,10 +1293,23 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution,
12951293 // Otherwise, check for an ambiguity.
12961294 if (!resolution.areSameType (current, type)) {
12971295 isAmbiguous = true ;
1298- break ;
1296+ // If a typealias collides with an associatedtype in generic requirement
1297+ // position, prefer the associated type.
1298+ if (options.getContext () == TypeResolverContext::GenericRequirement) {
1299+ if (isa<TypeAliasDecl>(currentDecl) && isa<AssociatedTypeDecl>(typeDecl)) {
1300+ current = type;
1301+ currentDecl = typeDecl;
1302+ currentDC = foundDC;
1303+ isAmbiguous = false ;
1304+ } else if (isa<AssociatedTypeDecl>(currentDecl) &&
1305+ isa<TypeAliasDecl>(typeDecl)) {
1306+ isAmbiguous = false ;
1307+ }
1308+ }
1309+ if (isAmbiguous) break ;
12991310 }
13001311
1301- // We have a found multiple type aliases that refer to the same thing.
1312+ // We have found multiple type aliases that refer to the same thing.
13021313 // Ignore the duplicate.
13031314 }
13041315
0 commit comments