@@ -565,9 +565,7 @@ Type TypeChecker::resolveTypeInContext(TypeDecl *typeDecl, DeclContext *foundDC,
565
565
566
566
if (selfType->is <GenericTypeParamType>()) {
567
567
if (typeDecl->getDeclContext ()->getSelfProtocolDecl ()) {
568
- if (isa<AssociatedTypeDecl>(typeDecl) ||
569
- (isa<TypeAliasDecl>(typeDecl) &&
570
- !cast<TypeAliasDecl>(typeDecl)->isGeneric ())) {
568
+ if (isa<AssociatedTypeDecl>(typeDecl)) {
571
569
// FIXME: We should use this lookup method for the Interface
572
570
// stage too, but right now that causes problems with
573
571
// Sequence.SubSequence vs Collection.SubSequence; the former
@@ -1295,10 +1293,23 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution,
1295
1293
// Otherwise, check for an ambiguity.
1296
1294
if (!resolution.areSameType (current, type)) {
1297
1295
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 ;
1299
1310
}
1300
1311
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.
1302
1313
// Ignore the duplicate.
1303
1314
}
1304
1315
0 commit comments