@@ -739,13 +739,6 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
739739 }
740740 }
741741
742- /// Visit the given [comment] if it is not `null` .
743- void safelyVisitComment (Comment ? comment) {
744- if (comment != null ) {
745- super .visitComment (comment);
746- }
747- }
748-
749742 void setReadElement (Expression node, Element ? element) {
750743 DartType readType = DynamicTypeImpl .instance;
751744 if (node is IndexExpression ) {
@@ -1096,52 +1089,6 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
10961089 // visitClassTypeAlias.
10971090 }
10981091
1099- @override
1100- void visitComment (Comment node) {
1101- var parent = node.parent;
1102- if (parent is FunctionDeclaration ||
1103- parent is FunctionTypeAlias ||
1104- parent is ConstructorDeclaration ) {
1105- return ;
1106- }
1107-
1108- // TODO(scheglov) Change corresponding visiting places to visit comments
1109- // with name scopes set for correct comments resolution.
1110- if (parent is GenericTypeAlias ) {
1111- var element = parent.declaredElement as TypeAliasElement ;
1112- var outerScope = nameScope;
1113- try {
1114- nameScope = TypeParameterScope (nameScope, element.typeParameters);
1115-
1116- var aliasedElement = element.aliasedElement;
1117- if (aliasedElement is GenericFunctionTypeElement ) {
1118- nameScope = FormalParameterScope (
1119- TypeParameterScope (nameScope, aliasedElement.typeParameters),
1120- aliasedElement.parameters,
1121- );
1122- }
1123-
1124- super .visitComment (node);
1125- return ;
1126- } finally {
1127- nameScope = outerScope;
1128- }
1129- } else if (parent is MethodDeclaration ) {
1130- var outerScope = nameScope;
1131- try {
1132- var element = parent.declaredElement! ;
1133- nameScope = FormalParameterScope (nameScope, element.parameters);
1134-
1135- super .visitComment (node);
1136- return ;
1137- } finally {
1138- nameScope = outerScope;
1139- }
1140- }
1141-
1142- super .visitComment (node);
1143- }
1144-
11451092 @override
11461093 void visitCommentReference (CommentReference node) {
11471094 //
@@ -1246,7 +1193,6 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
12461193 // element resolver and type analyzer to visit the constructor declaration.
12471194 node.accept (elementResolver);
12481195 node.accept (typeAnalyzer);
1249- safelyVisitComment (node.documentationComment);
12501196 }
12511197
12521198 @override
@@ -1479,12 +1425,6 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
14791425 // visitFunctionDeclaration
14801426 }
14811427
1482- @override
1483- void visitFunctionDeclarationInScope (FunctionDeclaration node) {
1484- super .visitFunctionDeclarationInScope (node);
1485- safelyVisitComment (node.documentationComment);
1486- }
1487-
14881428 @override
14891429 void visitFunctionExpression (covariant FunctionExpressionImpl node) {
14901430 // Note: we have to update _enclosingFunction because we don't make use of
@@ -1535,12 +1475,6 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
15351475 // visitFunctionTypeAlias.
15361476 }
15371477
1538- @override
1539- void visitFunctionTypeAliasInScope (FunctionTypeAlias node) {
1540- super .visitFunctionTypeAliasInScope (node);
1541- safelyVisitComment (node.documentationComment);
1542- }
1543-
15441478 @override
15451479 void visitFunctionTypedFormalParameter (FunctionTypedFormalParameter node) {
15461480 super .visitFunctionTypedFormalParameter (node);
@@ -1557,12 +1491,6 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
15571491 // visitGenericTypeAlias.
15581492 }
15591493
1560- @override
1561- void visitGenericTypeAliasInFunctionScope (GenericTypeAlias node) {
1562- super .visitGenericTypeAliasInFunctionScope (node);
1563- safelyVisitComment (node.documentationComment);
1564- }
1565-
15661494 @override
15671495 void visitHideCombinator (HideCombinator node) {}
15681496
@@ -2574,7 +2502,6 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
25742502 try {
25752503 ConstructorElement element = node.declaredElement! ;
25762504
2577- node.documentationComment? .accept (this );
25782505 node.metadata.accept (this );
25792506 node.returnType.accept (this );
25802507 node.name? .accept (this );
@@ -2604,6 +2531,7 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
26042531 }
26052532
26062533 void visitConstructorDeclarationInScope (ConstructorDeclaration node) {
2534+ node.documentationComment? .accept (this );
26072535 node.body.accept (this );
26082536 }
26092537
@@ -2801,17 +2729,18 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
28012729 void visitFunctionDeclarationInScope (FunctionDeclaration node) {
28022730 // Note: we don't visit metadata because it's not inside the function's type
28032731 // parameter scope. It was already visited in [visitFunctionDeclaration].
2804- node.documentationComment? .accept (this );
28052732 node.returnType? .accept (this );
28062733 node.name.accept (this );
28072734 node.functionExpression.accept (this );
28082735 }
28092736
28102737 @override
28112738 void visitFunctionExpression (FunctionExpression node) {
2812- if (node.parent is FunctionDeclaration ) {
2739+ var parent = node.parent;
2740+ if (parent is FunctionDeclaration ) {
28132741 // We have already created a function scope and don't need to do so again.
28142742 super .visitFunctionExpression (node);
2743+ parent.documentationComment? .accept (this );
28152744 return ;
28162745 }
28172746
@@ -2848,11 +2777,13 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
28482777 // Note: we don't visit metadata because it's not inside the function type
28492778 // alias's type parameter scope. It was already visited in
28502779 // [visitFunctionTypeAlias].
2851- node.documentationComment? .accept (this );
28522780 node.returnType? .accept (this );
28532781 node.name.accept (this );
28542782 node.typeParameters? .accept (this );
28552783 node.parameters.accept (this );
2784+ // Visiting the parameters added them to the scope as a side effect. So it
2785+ // is safe to visit the documentation comment now.
2786+ node.documentationComment? .accept (this );
28562787 }
28572788
28582789 @override
@@ -2917,21 +2848,20 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
29172848
29182849 var aliasedElement = element.aliasedElement;
29192850 if (aliasedElement is GenericFunctionTypeElement ) {
2920- nameScope = FormalParameterScope (nameScope, aliasedElement.parameters);
2921- visitGenericTypeAliasInFunctionScope (node);
2851+ nameScope = FormalParameterScope (
2852+ TypeParameterScope (nameScope, aliasedElement.typeParameters),
2853+ aliasedElement.parameters);
29222854 }
2855+ node.documentationComment? .accept (this );
29232856 } finally {
29242857 nameScope = outerScope;
29252858 }
29262859 }
29272860
2928- void visitGenericTypeAliasInFunctionScope (GenericTypeAlias node) {}
2929-
29302861 void visitGenericTypeAliasInScope (GenericTypeAlias node) {
29312862 // Note: we don't visit metadata because it's not inside the generic type
29322863 // alias's type parameter scope. It was already visited in
29332864 // [visitGenericTypeAlias].
2934- node.documentationComment? .accept (this );
29352865 node.name.accept (this );
29362866 node.typeParameters? .accept (this );
29372867 node.type.accept (this );
@@ -2978,11 +2908,13 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
29782908 void visitMethodDeclarationInScope (MethodDeclaration node) {
29792909 // Note: we don't visit metadata because it's not inside the method's type
29802910 // parameter scope. It was already visited in [visitMethodDeclaration].
2981- node.documentationComment? .accept (this );
29822911 node.returnType? .accept (this );
29832912 node.name.accept (this );
29842913 node.typeParameters? .accept (this );
29852914 node.parameters? .accept (this );
2915+ // Visiting the parameters added them to the scope as a side effect. So it
2916+ // is safe to visit the documentation comment now.
2917+ node.documentationComment? .accept (this );
29862918 node.body.accept (this );
29872919 }
29882920
0 commit comments