@@ -297,7 +297,7 @@ Type TypeChecker::applyGenericArguments(Type type,
297
297
SourceLoc loc,
298
298
DeclContext *dc,
299
299
MutableArrayRef<TypeLoc> genericArgs,
300
- bool isNominalInheritanceClause ,
300
+ bool isGenericSignature ,
301
301
GenericTypeResolver *resolver) {
302
302
// Make sure we always have a resolver to use.
303
303
PartialGenericTypeToArchetypeResolver defaultResolver (*this );
@@ -330,8 +330,8 @@ Type TypeChecker::applyGenericArguments(Type type,
330
330
}
331
331
332
332
TypeResolutionOptions options;
333
- if (isNominalInheritanceClause )
334
- options |= TR_NominalInheritanceClause ;
333
+ if (isGenericSignature )
334
+ options |= TR_GenericSignature ;
335
335
336
336
// Validate the generic arguments and capture just the types.
337
337
SmallVector<Type, 4 > genericArgTypes;
@@ -370,13 +370,13 @@ Type TypeChecker::applyGenericArguments(Type type,
370
370
static Type applyGenericTypeReprArgs (TypeChecker &TC, Type type, SourceLoc loc,
371
371
DeclContext *dc,
372
372
ArrayRef<TypeRepr *> genericArgs,
373
- bool isNominalInheritanceClause ,
373
+ bool isGenericSignature ,
374
374
GenericTypeResolver *resolver) {
375
375
SmallVector<TypeLoc, 8 > args;
376
376
for (auto tyR : genericArgs)
377
377
args.push_back (tyR);
378
378
Type ty = TC.applyGenericArguments (type, loc, dc, args,
379
- isNominalInheritanceClause , resolver);
379
+ isGenericSignature , resolver);
380
380
if (!ty)
381
381
return ErrorType::get (TC.Context );
382
382
return ty;
@@ -396,7 +396,7 @@ static Type resolveTypeDecl(TypeChecker &TC, TypeDecl *typeDecl, SourceLoc loc,
396
396
DeclContext *dc,
397
397
ArrayRef<TypeRepr *> genericArgs,
398
398
bool allowUnboundGenerics,
399
- bool isNominalInheritanceClause ,
399
+ bool isGenericSignature ,
400
400
GenericTypeResolver *resolver) {
401
401
TC.validateDecl (typeDecl);
402
402
@@ -432,7 +432,7 @@ static Type resolveTypeDecl(TypeChecker &TC, TypeDecl *typeDecl, SourceLoc loc,
432
432
if (!genericArgs.empty ()) {
433
433
// Apply the generic arguments to the type.
434
434
type = applyGenericTypeReprArgs (TC, type, loc, dc, genericArgs,
435
- isNominalInheritanceClause , resolver);
435
+ isGenericSignature , resolver);
436
436
}
437
437
438
438
assert (type);
@@ -459,15 +459,15 @@ static NominalTypeDecl *getEnclosingNominalContext(DeclContext *dc) {
459
459
// / \param dc The context in which name lookup occurred.
460
460
// / \param components The components that refer to the type, where the last
461
461
// / component refers to the type that could not be found.
462
- // / \param isNominalInheritanceClause True if this type is in a nominal's
463
- // / inheritance clause .
462
+ // / \param isGenericSignature True if we're only looking into the generic
463
+ // / signature of the given context .
464
464
// /
465
465
// / \returns true if we could not fix the type reference, false if
466
466
// / typo correction (or some other mechanism) was able to fix the
467
467
// / reference.
468
468
static bool diagnoseUnknownType (TypeChecker &tc, DeclContext *dc,
469
469
ArrayRef<ComponentIdentTypeRepr *> components,
470
- bool isNominalInheritanceClause ,
470
+ bool isGenericSignature ,
471
471
GenericTypeResolver *resolver) {
472
472
auto comp = components.back ();
473
473
@@ -483,7 +483,7 @@ static bool diagnoseUnknownType(TypeChecker &tc, DeclContext *dc,
483
483
assert (!isa<ProtocolDecl>(nominal) && " Cannot be a protocol" );
484
484
auto type = resolveTypeDecl (tc, nominal, comp->getIdLoc (), dc, { },
485
485
/* allowUnboundGenerics=*/ false ,
486
- isNominalInheritanceClause , resolver);
486
+ isGenericSignature , resolver);
487
487
if (type->is <ErrorType>())
488
488
return true ;
489
489
@@ -561,7 +561,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
561
561
// Resolve the first component, which is the only one that requires
562
562
// unqualified name lookup.
563
563
DeclContext *lookupDC = DC;
564
- if (options.contains (TR_NominalInheritanceClause ))
564
+ if (options.contains (TR_GenericSignature ))
565
565
lookupDC = DC->getParent ();
566
566
UnqualifiedLookup Globals (comp->getIdentifier (), lookupDC, &TC,
567
567
options.contains (TR_KnownNonCascadingDependency),
@@ -601,7 +601,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
601
601
Type type = resolveTypeDecl (TC, typeDecl, comp->getIdLoc (),
602
602
DC, genericArgs,
603
603
options.contains (TR_AllowUnboundGenerics),
604
- options.contains (TR_NominalInheritanceClause ),
604
+ options.contains (TR_GenericSignature ),
605
605
resolver);
606
606
if (type->is <ErrorType>()) {
607
607
comp->setValue (type);
@@ -650,7 +650,7 @@ resolveTopLevelIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
650
650
// source, bail out.
651
651
if (!diagnoseErrors ||
652
652
diagnoseUnknownType (TC, DC, comp,
653
- options.contains (TR_NominalInheritanceClause ),
653
+ options.contains (TR_GenericSignature ),
654
654
resolver)) {
655
655
Type ty = ErrorType::get (TC.Context );
656
656
comp->setValue (ty);
@@ -671,15 +671,17 @@ resolveIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
671
671
if (parentComps.empty ()) {
672
672
TypeResolutionOptions lookupOptions = options;
673
673
674
- // For inheritance clause lookups, don't actually look into the type.
675
- // Just look at the generic parameters, and then move up to the enclosing
676
- // context.
677
- if (options.contains (TR_NominalInheritanceClause)) {
674
+ // For lookups within the generic signature, look at the generic
675
+ // parameters (only), then move up to the enclosing context.
676
+ if (options.contains (TR_GenericSignature)) {
678
677
GenericParamList *genericParams;
679
- if (auto *nominal = dyn_cast<NominalTypeDecl>(DC))
678
+ if (auto *nominal = dyn_cast<NominalTypeDecl>(DC)) {
680
679
genericParams = nominal->getGenericParams ();
681
- else
682
- genericParams = cast<ExtensionDecl>(DC)->getGenericParams ();
680
+ } else if (auto *ext = dyn_cast<ExtensionDecl>(DC)) {
681
+ genericParams = ext->getGenericParams ();
682
+ } else {
683
+ genericParams = cast<AbstractFunctionDecl>(DC)->getGenericParams ();
684
+ }
683
685
684
686
if (!isa<GenericIdentTypeRepr>(comp)) {
685
687
if (genericParams) {
@@ -773,13 +775,14 @@ resolveIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
773
775
}
774
776
775
777
// If we didn't find anything, complain.
776
- bool isNominal = options.contains (TR_NominalInheritanceClause );
778
+ bool isGenericSignature = options.contains (TR_GenericSignature );
777
779
bool recovered = false ;
778
780
if (!memberTypes) {
779
781
// If we're not allowed to complain or we couldn't fix the
780
782
// source, bail out.
781
783
if (!diagnoseErrors ||
782
- diagnoseUnknownType (TC, DC, components, isNominal, resolver)) {
784
+ diagnoseUnknownType (TC, DC, components, isGenericSignature,
785
+ resolver)) {
783
786
Type ty = ErrorType::get (TC.Context );
784
787
comp->setValue (ty);
785
788
return ty;
@@ -804,7 +807,7 @@ resolveIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
804
807
memberType = applyGenericTypeReprArgs (TC, memberType,
805
808
genComp->getIdLoc (),
806
809
DC, genComp->getGenericArgs (),
807
- isNominal , resolver);
810
+ isGenericSignature , resolver);
808
811
809
812
comp->setValue (memberType);
810
813
return memberType;
@@ -836,11 +839,12 @@ resolveIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
836
839
}
837
840
838
841
// If we didn't find a type, complain.
839
- bool isNominal = options.contains (TR_NominalInheritanceClause );
842
+ bool isGenericSignature = options.contains (TR_GenericSignature );
840
843
bool recovered = false ;
841
844
if (!foundModuleTypes) {
842
845
if (!diagnoseErrors ||
843
- diagnoseUnknownType (TC, DC, components, isNominal, resolver)) {
846
+ diagnoseUnknownType (TC, DC, components, isGenericSignature,
847
+ resolver)) {
844
848
Type ty = ErrorType::get (TC.Context );
845
849
comp->setValue (ty);
846
850
return ty;
@@ -856,7 +860,7 @@ resolveIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
856
860
if (auto genComp = dyn_cast<GenericIdentTypeRepr>(comp)) {
857
861
foundType = applyGenericTypeReprArgs (TC, foundType, genComp->getIdLoc (),
858
862
DC, genComp->getGenericArgs (),
859
- isNominal , resolver);
863
+ isGenericSignature , resolver);
860
864
}
861
865
862
866
comp->setValue (foundType);
@@ -888,7 +892,7 @@ resolveIdentTypeComponent(TypeChecker &TC, DeclContext *DC,
888
892
Type type = resolveTypeDecl (TC, typeDecl, comp->getIdLoc (), DC,
889
893
genericArgs,
890
894
options.contains (TR_AllowUnboundGenerics),
891
- options.contains (TR_NominalInheritanceClause ),
895
+ options.contains (TR_GenericSignature ),
892
896
resolver);
893
897
comp->setValue (type);
894
898
return type;
@@ -1739,7 +1743,7 @@ Type TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
1739
1743
TypeLoc args[2 ] = { TypeLoc (repr->getKey ()), TypeLoc (repr->getValue ()) };
1740
1744
1741
1745
if (!TC.applyGenericArguments (unboundTy, repr->getStartLoc (), DC, args,
1742
- options.contains (TR_NominalInheritanceClause ),
1746
+ options.contains (TR_GenericSignature ),
1743
1747
Resolver)) {
1744
1748
return ErrorType::get (TC.Context );
1745
1749
}
0 commit comments