@@ -40,7 +40,7 @@ ASTContext &DeclContext::getASTContext() const {
4040}
4141
4242GenericTypeDecl *
43- DeclContext::getAsGenericTypeOrGenericTypeExtensionContext () const {
43+ DeclContext::getAsTypeOrTypeExtensionContext () const {
4444 switch (getContextKind ()) {
4545 case DeclContextKind::Module:
4646 case DeclContextKind::FileUnit:
@@ -78,32 +78,28 @@ DeclContext::getAsGenericTypeOrGenericTypeExtensionContext() const {
7878// / extension thereof, return the NominalTypeDecl.
7979NominalTypeDecl *DeclContext::
8080getAsNominalTypeOrNominalTypeExtensionContext () const {
81- auto decl = getAsGenericTypeOrGenericTypeExtensionContext ();
81+ auto decl = getAsTypeOrTypeExtensionContext ();
8282 return dyn_cast_or_null<NominalTypeDecl>(decl);
8383}
8484
8585
8686ClassDecl *DeclContext::getAsClassOrClassExtensionContext () const {
87- return dyn_cast_or_null<ClassDecl>(
88- getAsGenericTypeOrGenericTypeExtensionContext ());
87+ return dyn_cast_or_null<ClassDecl>(getAsTypeOrTypeExtensionContext ());
8988}
9089
9190EnumDecl *DeclContext::getAsEnumOrEnumExtensionContext () const {
92- return dyn_cast_or_null<EnumDecl>(
93- getAsGenericTypeOrGenericTypeExtensionContext ());
91+ return dyn_cast_or_null<EnumDecl>(getAsTypeOrTypeExtensionContext ());
9492}
9593
9694ProtocolDecl *DeclContext::getAsProtocolOrProtocolExtensionContext () const {
97- return dyn_cast_or_null<ProtocolDecl>(
98- getAsGenericTypeOrGenericTypeExtensionContext ());
95+ return dyn_cast_or_null<ProtocolDecl>(getAsTypeOrTypeExtensionContext ());
9996}
10097
10198ProtocolDecl *DeclContext::getAsProtocolExtensionContext () const {
10299 if (getContextKind () != DeclContextKind::ExtensionDecl)
103100 return nullptr ;
104101
105- return dyn_cast_or_null<ProtocolDecl>(
106- getAsGenericTypeOrGenericTypeExtensionContext ());
102+ return dyn_cast_or_null<ProtocolDecl>(getAsTypeOrTypeExtensionContext ());
107103}
108104
109105GenericTypeParamType *DeclContext::getProtocolSelfType () const {
@@ -357,6 +353,11 @@ AbstractFunctionDecl *DeclContext::getInnermostMethodContext() {
357353 }
358354}
359355
356+ bool DeclContext::isTypeContext () const {
357+ return isa<NominalTypeDecl>(this ) ||
358+ getContextKind () == DeclContextKind::ExtensionDecl;
359+ }
360+
360361DeclContext *DeclContext::getInnermostTypeContext () {
361362 DeclContext *Result = this ;
362363 while (true ) {
@@ -374,8 +375,14 @@ DeclContext *DeclContext::getInnermostTypeContext() {
374375 case DeclContextKind::FileUnit:
375376 return nullptr ;
376377
377- case DeclContextKind::ExtensionDecl:
378378 case DeclContextKind::GenericTypeDecl:
379+ if (isa<TypeAliasDecl>(Result)) {
380+ Result = Result->getParent ();
381+ continue ;
382+ }
383+ return Result;
384+
385+ case DeclContextKind::ExtensionDecl:
379386 return Result;
380387 }
381388 }
0 commit comments