Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Unified Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2178123003: Issue 26860. Report CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR for parameters of fu… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698