@@ -849,6 +849,20 @@ TopLevelCodeScope::expandAScopeThatCreatesANewInsertionPoint(ScopeCreator &
849
849
850
850
// Create child scopes for every declaration in a body.
851
851
852
+ namespace {
853
+ // / Retrieve the opaque generic parameter list if present, otherwise the normal generic parameter list.
854
+ template <typename T>
855
+ GenericParamList *getPotentiallyOpaqueGenericParams (T *decl) {
856
+ if (auto opaqueRepr = decl->getOpaqueResultTypeRepr ()) {
857
+ if (auto namedOpaque = dyn_cast<NamedOpaqueReturnTypeRepr>(opaqueRepr)) {
858
+ return namedOpaque->getGenericParams ();
859
+ }
860
+ }
861
+
862
+ return decl->getGenericParams ();
863
+ }
864
+ }
865
+
852
866
void AbstractFunctionDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint (
853
867
ScopeCreator &scopeCreator) {
854
868
scopeCreator.addChildrenForKnownAttributes (decl, this );
@@ -859,15 +873,8 @@ void AbstractFunctionDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
859
873
ASTScopeImpl *leaf = this ;
860
874
861
875
if (!isa<AccessorDecl>(decl)) {
862
- if (auto opaqueRepr = decl->getOpaqueResultTypeRepr ()) {
863
- if (auto namedOpaque = dyn_cast<NamedOpaqueReturnTypeRepr>(opaqueRepr)) {
864
- leaf = scopeCreator.addNestedGenericParamScopesToTree (
865
- decl, namedOpaque->getGenericParams (), leaf);
866
- }
867
- }
868
-
869
876
leaf = scopeCreator.addNestedGenericParamScopesToTree (
870
- decl, decl-> getGenericParams ( ), leaf);
877
+ decl, getPotentiallyOpaqueGenericParams (decl ), leaf);
871
878
872
879
auto *params = decl->getParameters ();
873
880
if (params->size () > 0 ) {
@@ -1015,7 +1022,7 @@ void SubscriptDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
1015
1022
ScopeCreator &scopeCreator) {
1016
1023
scopeCreator.addChildrenForKnownAttributes (decl, this );
1017
1024
auto *leaf = scopeCreator.addNestedGenericParamScopesToTree (
1018
- decl, decl-> getGenericParams ( ), this );
1025
+ decl, getPotentiallyOpaqueGenericParams (decl ), this );
1019
1026
scopeCreator.constructExpandAndInsert <ParameterListScope>(
1020
1027
leaf, decl->getIndices (), decl->getAccessor (AccessorKind::Get));
1021
1028
scopeCreator.addChildrenForParsedAccessors (decl, leaf);
0 commit comments