@@ -4507,23 +4507,16 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
45074507 TypeParameterScope (nameScope, element.typeParameters),
45084508 element,
45094509 );
4510- visitClassTypeAliasInScope (node);
4510+ _visitDocumentationComment (node.documentationComment);
4511+ node.typeParameters? .accept (this );
4512+ node.superclass.accept (this );
4513+ node.withClause.accept (this );
4514+ node.implementsClause? .accept (this );
45114515 } finally {
45124516 nameScope = outerScope;
45134517 }
45144518 }
45154519
4516- void visitClassTypeAliasInScope (ClassTypeAliasImpl node) {
4517- // Note: we don't visit metadata because it's not inside the class type
4518- // alias's type parameter scope. It was already visited in
4519- // [visitClassTypeAlias].
4520- _visitDocumentationComment (node.documentationComment);
4521- node.typeParameters? .accept (this );
4522- node.superclass.accept (this );
4523- node.withClause.accept (this );
4524- node.implementsClause? .accept (this );
4525- }
4526-
45274520 @override
45284521 void visitCompilationUnit (covariant CompilationUnitImpl node) {
45294522 node.nameScope = nameScope;
@@ -4580,17 +4573,13 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
45804573 ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
45814574 try {
45824575 _implicitLabelScope = _implicitLabelScope.nest (node);
4583- visitDoStatementInScope (node);
4576+ _visitStatementInScope (node.body);
4577+ node.condition.accept (this );
45844578 } finally {
45854579 _implicitLabelScope = outerImplicitScope;
45864580 }
45874581 }
45884582
4589- void visitDoStatementInScope (DoStatement node) {
4590- visitStatementInScope (node.body);
4591- node.condition.accept (this );
4592- }
4593-
45944583 @override
45954584 void visitEnumDeclaration (covariant EnumDeclarationImpl node) {
45964585 Scope outerScope = nameScope;
@@ -4624,35 +4613,27 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
46244613
46254614 @override
46264615 void visitExtensionDeclaration (covariant ExtensionDeclarationImpl node) {
4627- Scope outerScope = nameScope;
4616+ var outerScope = nameScope;
46284617 try {
4629- ExtensionElement element = node.declaredElement! ;
4618+ var element = node.declaredElement! ;
46304619 node.metadata.accept (this );
46314620
46324621 nameScope = TypeParameterScope (
46334622 nameScope,
46344623 element.typeParameters,
46354624 );
46364625 node.nameScope = nameScope;
4637- visitExtensionDeclarationInScope (node);
4626+ node.typeParameters? .accept (this );
4627+ node.onClause? .accept (this );
46384628
46394629 nameScope = ExtensionScope (nameScope, element);
4640- visitExtensionMembersInScope (node);
4630+ _visitDocumentationComment (node.documentationComment);
4631+ node.members.accept (this );
46414632 } finally {
46424633 nameScope = outerScope;
46434634 }
46444635 }
46454636
4646- void visitExtensionDeclarationInScope (ExtensionDeclaration node) {
4647- node.typeParameters? .accept (this );
4648- node.onClause? .accept (this );
4649- }
4650-
4651- void visitExtensionMembersInScope (ExtensionDeclarationImpl node) {
4652- _visitDocumentationComment (node.documentationComment);
4653- node.members.accept (this );
4654- }
4655-
46564637 @override
46574638 void visitExtensionTypeDeclaration (
46584639 covariant ExtensionTypeDeclarationImpl node,
@@ -4688,10 +4669,8 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
46884669
46894670 @override
46904671 void visitForEachPartsWithDeclaration (ForEachPartsWithDeclaration node) {
4691- //
46924672 // We visit the iterator before the loop variable because the loop variable
46934673 // cannot be in scope while visiting the iterator.
4694- //
46954674 node.iterable.accept (this );
46964675 node.loopVariable.accept (this );
46974676 }
@@ -4700,10 +4679,8 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
47004679 void visitForEachPartsWithPattern (
47014680 covariant ForEachPartsWithPatternImpl node,
47024681 ) {
4703- //
47044682 // We visit the iterator before the pattern because the pattern variables
47054683 // cannot be in scope while visiting the iterator.
4706- //
47074684 node.iterable.accept (this );
47084685
47094686 for (var variable in node.variables) {
@@ -4719,22 +4696,13 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
47194696 try {
47204697 nameScope = LocalScope (nameScope);
47214698 node.nameScope = nameScope;
4722- visitForElementInScope (node);
4699+ node.forLoopParts.accept (this );
4700+ node.body.accept (this );
47234701 } finally {
47244702 nameScope = outerNameScope;
47254703 }
47264704 }
47274705
4728- /// Visit the given [node] after it's scope has been created. This replaces
4729- /// the normal call to the inherited visit method so that ResolverVisitor can
4730- /// intervene when type propagation is enabled.
4731- void visitForElementInScope (ForElement node) {
4732- // TODO(brianwilkerson): Investigate the possibility of removing the
4733- // visit...InScope methods now that type propagation is no longer done.
4734- node.forLoopParts.accept (this );
4735- node.body.accept (this );
4736- }
4737-
47384706 @override
47394707 void visitFormalParameterList (FormalParameterList node) {
47404708 super .visitFormalParameterList (node);
@@ -4771,23 +4739,14 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
47714739 nameScope = LocalScope (nameScope);
47724740 _implicitLabelScope = _implicitLabelScope.nest (node);
47734741 node.nameScope = nameScope;
4774- visitForStatementInScope (node);
4742+ node.forLoopParts.accept (this );
4743+ _visitStatementInScope (node.body);
47754744 } finally {
47764745 nameScope = outerNameScope;
47774746 _implicitLabelScope = outerImplicitScope;
47784747 }
47794748 }
47804749
4781- /// Visit the given [node] after it's scope has been created. This replaces
4782- /// the normal call to the inherited visit method so that ResolverVisitor can
4783- /// intervene when type propagation is enabled.
4784- void visitForStatementInScope (ForStatement node) {
4785- // TODO(brianwilkerson): Investigate the possibility of removing the
4786- // visit...InScope methods now that type propagation is no longer done.
4787- node.forLoopParts.accept (this );
4788- visitStatementInScope (node.body);
4789- }
4790-
47914750 @override
47924751 void visitFunctionDeclaration (covariant FunctionDeclarationImpl node) {
47934752 node.functionExpression.body.localVariableInfo = _localVariableInfo;
@@ -4804,20 +4763,14 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
48044763 element.typeParameters,
48054764 );
48064765 node.nameScope = nameScope;
4807- visitFunctionDeclarationInScope (node);
4766+ node.returnType? .accept (this );
4767+ node.functionExpression.accept (this );
48084768 } finally {
48094769 nameScope = outerScope;
48104770 _enclosingClosure = outerClosure;
48114771 }
48124772 }
48134773
4814- void visitFunctionDeclarationInScope (FunctionDeclaration node) {
4815- // Note: we don't visit metadata because it's not inside the function's type
4816- // parameter scope. It was already visited in [visitFunctionDeclaration].
4817- node.returnType? .accept (this );
4818- node.functionExpression.accept (this );
4819- }
4820-
48214774 @override
48224775 void visitFunctionExpression (FunctionExpression node) {
48234776 var outerClosure = _enclosingClosure;
@@ -4854,24 +4807,17 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
48544807 try {
48554808 var element = node.declaredElement! ;
48564809 nameScope = TypeParameterScope (nameScope, element.typeParameters);
4857- visitFunctionTypeAliasInScope (node);
4810+ node.returnType? .accept (this );
4811+ node.typeParameters? .accept (this );
4812+ node.parameters.accept (this );
4813+ // Visiting the parameters added them to the scope as a side effect. So it
4814+ // is safe to visit the documentation comment now.
4815+ _visitDocumentationComment (node.documentationComment);
48584816 } finally {
48594817 nameScope = outerScope;
48604818 }
48614819 }
48624820
4863- void visitFunctionTypeAliasInScope (covariant FunctionTypeAliasImpl node) {
4864- // Note: we don't visit metadata because it's not inside the function type
4865- // alias's type parameter scope. It was already visited in
4866- // [visitFunctionTypeAlias].
4867- node.returnType? .accept (this );
4868- node.typeParameters? .accept (this );
4869- node.parameters.accept (this );
4870- // Visiting the parameters added them to the scope as a side effect. So it
4871- // is safe to visit the documentation comment now.
4872- _visitDocumentationComment (node.documentationComment);
4873- }
4874-
48754821 @override
48764822 void visitFunctionTypedFormalParameter (
48774823 covariant FunctionTypedFormalParameterImpl node) {
@@ -4883,23 +4829,15 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
48834829 nameScope,
48844830 element.typeParameters,
48854831 );
4886- visitFunctionTypedFormalParameterInScope (node);
4832+ _visitDocumentationComment (node.documentationComment);
4833+ node.returnType? .accept (this );
4834+ node.typeParameters? .accept (this );
4835+ node.parameters.accept (this );
48874836 } finally {
48884837 nameScope = outerScope;
48894838 }
48904839 }
48914840
4892- void visitFunctionTypedFormalParameterInScope (
4893- FunctionTypedFormalParameterImpl node) {
4894- // Note: we don't visit metadata because it's not inside the function typed
4895- // formal parameter's type parameter scope. It was already visited in
4896- // [visitFunctionTypedFormalParameter].
4897- _visitDocumentationComment (node.documentationComment);
4898- node.returnType? .accept (this );
4899- node.typeParameters? .accept (this );
4900- node.parameters.accept (this );
4901- }
4902-
49034841 @override
49044842 void visitGenericFunctionType (covariant GenericFunctionTypeImpl node) {
49054843 var type = node.type;
@@ -4929,7 +4867,8 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
49294867 var element = node.declaredElement as TypeAliasElement ;
49304868 nameScope = TypeParameterScope (nameScope, element.typeParameters);
49314869 node.nameScope = nameScope;
4932- visitGenericTypeAliasInScope (node);
4870+ node.typeParameters? .accept (this );
4871+ node.type.accept (this );
49334872
49344873 var aliasedElement = element.aliasedElement;
49354874 if (aliasedElement is GenericFunctionTypeElement ) {
@@ -4943,14 +4882,6 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
49434882 }
49444883 }
49454884
4946- void visitGenericTypeAliasInScope (GenericTypeAlias node) {
4947- // Note: we don't visit metadata because it's not inside the generic type
4948- // alias's type parameter scope. It was already visited in
4949- // [visitGenericTypeAlias].
4950- node.typeParameters? .accept (this );
4951- node.type.accept (this );
4952- }
4953-
49544885 @override
49554886 void visitGuardedPattern (covariant GuardedPatternImpl node) {
49564887 var patternVariables = node.variables.values.toList ();
@@ -5044,26 +4975,18 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
50444975
50454976 nameScope = TypeParameterScope (nameScope, element.typeParameters);
50464977 node.nameScope = nameScope;
5047- visitMixinDeclarationInScope (node);
4978+ node.typeParameters? .accept (this );
4979+ node.onClause? .accept (this );
4980+ node.implementsClause? .accept (this );
50484981
50494982 nameScope = InstanceScope (nameScope, element);
5050- visitMixinMembersInScope (node);
4983+ _visitDocumentationComment (node.documentationComment);
4984+ node.members.accept (this );
50514985 } finally {
50524986 nameScope = outerScope;
50534987 }
50544988 }
50554989
5056- void visitMixinDeclarationInScope (MixinDeclaration node) {
5057- node.typeParameters? .accept (this );
5058- node.onClause? .accept (this );
5059- node.implementsClause? .accept (this );
5060- }
5061-
5062- void visitMixinMembersInScope (MixinDeclarationImpl node) {
5063- _visitDocumentationComment (node.documentationComment);
5064- node.members.accept (this );
5065- }
5066-
50674990 @override
50684991 void visitNamedType (NamedType node) {
50694992 // All TypeName(s) are already resolved, so we don't resolve it here.
@@ -5147,27 +5070,6 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
51475070 }
51485071 }
51495072
5150- /// Visit the given statement after it's scope has been created. This is used
5151- /// by ResolverVisitor to correctly visit the 'then' and 'else' statements of
5152- /// an 'if' statement.
5153- ///
5154- /// @param node the statement to be visited
5155- void visitStatementInScope (Statement ? node) {
5156- if (node is BlockImpl ) {
5157- // Don't create a scope around a block because the block will create it's
5158- // own scope.
5159- visitBlock (node);
5160- } else if (node != null ) {
5161- Scope outerNameScope = nameScope;
5162- try {
5163- nameScope = LocalScope (nameScope);
5164- node.accept (this );
5165- } finally {
5166- nameScope = outerNameScope;
5167- }
5168- }
5169- }
5170-
51715073 @override
51725074 void visitSwitchExpression (covariant SwitchExpressionImpl node) {
51735075 node.expression.accept (this );
@@ -5250,16 +5152,15 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
52505152 ImplicitLabelScope outerImplicitScope = _implicitLabelScope;
52515153 try {
52525154 _implicitLabelScope = _implicitLabelScope.nest (node);
5253- visitStatementInScope (node.body);
5155+ _visitStatementInScope (node.body);
52545156 } finally {
52555157 _implicitLabelScope = outerImplicitScope;
52565158 }
52575159 }
52585160
5259- /// Add scopes for each of the given labels.
5161+ /// Adds scopes for each of the given [ labels] .
52605162 ///
5261- /// @param labels the labels for which new scopes are to be added
5262- /// @return the scope that was in effect before the new scopes were added
5163+ /// Returns the scope that was in effect before the new scopes were added.
52635164 LabelScope ? _addScopesFor (NodeList <Label > labels, AstNode node) {
52645165 var outerScope = labelScope;
52655166 for (Label label in labels) {
@@ -5370,6 +5271,26 @@ class ScopeResolverVisitor extends UnifyingAstVisitor<void> {
53705271 }
53715272 }
53725273
5274+ /// Visits the given statement.
5275+ ///
5276+ /// This is used by [ResolverVisitor] to correctly visit the 'then' and 'else'
5277+ /// statements of an 'if' statement.
5278+ void _visitStatementInScope (Statement ? node) {
5279+ if (node is BlockImpl ) {
5280+ // Don't create a scope around a block because the block will create it's
5281+ // own scope.
5282+ visitBlock (node);
5283+ } else if (node != null ) {
5284+ var outerNameScope = nameScope;
5285+ try {
5286+ nameScope = LocalScope (nameScope);
5287+ node.accept (this );
5288+ } finally {
5289+ nameScope = outerNameScope;
5290+ }
5291+ }
5292+ }
5293+
53735294 void _withDeclaredLocals (
53745295 AstNodeWithNameScopeMixin node,
53755296 List <Statement > statements,
0 commit comments