11140abcce
Changes the shared error code `FieldInitializerOutsideConstructor` so that it generates `CompileTimeErrorCode.fieldInitializerOutsideConstructor` rather than `ParserErrorCode.fieldInitializerOutsideConstructor`, replacing the old analyzer-only `CompileTimeErrorCode.fieldInitializerOutsideConstructor`. This eliminates unnecessary code duplication between `pkg/analyzer/messages.yaml` and `pkg/_fe_analyzer_shared/messages.yaml`. Removes logic from `pkg/analyzer/lib/src/fasta/ast_builder.dart` that previously reported `ParserErrorCode.fieldInitializerOutsideConstructor`. This logic was unreliable (it only triggered for method parameters and local function declarations) and unnecessary (because it duplicated logic in the `ErrorVerifier`). This improves the user experience by eliminating duplicate errors. Change-Id: I6a6a69648a9958db531bb0c84bc604358dd0af6f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455466 Reviewed-by: Johnni Winther <johnniwinther@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
18 lines
519 B
Dart
18 lines
519 B
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
/// Fails because this.x parameter is used in a static function.
|
|
|
|
class Foo {
|
|
var x;
|
|
static foo(this.x) {}
|
|
// ^^^^^^
|
|
// [analyzer] COMPILE_TIME_ERROR.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR
|
|
// [cfe] Field formal parameters can only be used in a constructor.
|
|
}
|
|
|
|
main() {
|
|
Foo.foo(1);
|
|
}
|