Index: pkg/analyzer/lib/src/generated/error_verifier.dart |
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart |
index d1cbb72bff5931cf02461eee199ad3906df13236..0a54caa945d7caa6d04eff3b93240b1e30095c02 100644 |
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart |
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart |
@@ -3399,29 +3399,34 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> { |
*/ |
void _checkForFieldInitializingFormalRedirectingConstructor( |
FieldFormalParameter parameter) { |
- ConstructorDeclaration constructor = |
- parameter.getAncestor((node) => node is ConstructorDeclaration); |
- if (constructor == null) { |
- _errorReporter.reportErrorForNode( |
- CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, |
- parameter); |
- return; |
- } |
- // constructor cannot be a factory |
- if (constructor.factoryKeyword != null) { |
- _errorReporter.reportErrorForNode( |
- CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, |
- parameter); |
- return; |
- } |
- // constructor cannot have a redirection |
- for (ConstructorInitializer initializer in constructor.initializers) { |
- if (initializer is RedirectingConstructorInvocation) { |
+ // prepare the node that should be a ConstructorDeclaration |
+ AstNode formalParameterList = parameter.parent; |
+ if (formalParameterList is! FormalParameterList) { |
+ formalParameterList = formalParameterList?.parent; |
+ } |
+ AstNode constructor = formalParameterList?.parent; |
+ // now check whether the node is actually a ConstructorDeclaration |
+ if (constructor is ConstructorDeclaration) { |
+ // constructor cannot be a factory |
+ if (constructor.factoryKeyword != null) { |
_errorReporter.reportErrorForNode( |
- CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, |
+ CompileTimeErrorCode.FIELD_INITIALIZER_FACTORY_CONSTRUCTOR, |
parameter); |
return; |
} |
+ // constructor cannot have a redirection |
+ for (ConstructorInitializer initializer in constructor.initializers) { |
+ if (initializer is RedirectingConstructorInvocation) { |
+ _errorReporter.reportErrorForNode( |
+ CompileTimeErrorCode.FIELD_INITIALIZER_REDIRECTING_CONSTRUCTOR, |
+ parameter); |
+ return; |
+ } |
+ } |
+ } else { |
+ _errorReporter.reportErrorForNode( |
+ CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR, |
+ parameter); |
} |
} |