Remove the `reportScannerErrors` option from `Scanner.tokenize`. The
parser handles scanner error tokens directly, so the scanner no longer
needs a mode that translates and reports them before parsing.
Update all callers to use the simplified `tokenize()` API. Adjust parser
recovery expectations where diagnostics are now reported at the
synthetic token location chosen by parser.
Change-Id: Ia2d479ba57b3156f1a4bab47c32444892c9d0aa4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500361
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Permit `abstract` on top-level variable declarations when the
augmentations feature is enabled. Previously the parser always reported
`abstract` as extraneous at the top level, which rejected valid syntax
and dropped the modifier before later stages could see it.
Thread the abstract token through top-level field parsing, record it on
`TopLevelVariableDeclaration`, and pass it through the front-end
builders. Reorder the field callback arguments so `augment` precedes
`abstract`, matching the augmentation grammar for incomplete top-level
variables and keeping the parser, listener, and outline plumbing
consistent.
Change-Id: I680414a746b707d483e485702685c95f28a9c9ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494564
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Replace ErrorParserTest's custom Fasta parser setup with the shared
parser diagnostics harness based on parseStringWithErrors().
This updates the test class to extend ParserDiagnosticsTest, rewrites
cases to parse complete source snippets, and switches expectations from
listener-based checks to parse result assertions. Parsing full units or
function bodies makes each case exercise the same entry points used by
the newer diagnostics tests.
The migration also adjusts expected offsets and diagnostics in places
where the surrounding context changes recovery, and adds parsed-node
assertions for selected cases to verify that recovery still produces the
intended AST shape.
Switch to using `ParserDiagnosticsTest` infrastructure, with
`latestWithExperiments` features caused the tests to begin testing with
the "primary constructors" and "enhanced parts" features enabled, and so
test expectations were changed in `test_functionTypedParameter_var`,
`test_invalidTopLevelVar`, `test_invalidTypedef`, and
`test_multiplePartOfDirectives`.
Change-Id: Ibce6274d92ce484cd9b7eb4c5393b312f1b4e6a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485680
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Centralize diagnostics for illegal constructor/method bodies in
ErrorVerifier instead of reporting them from the AST builder and Fasta
error conversion.
This consolidates several overlapping checks and fixes inconsistent
error locations (for example, reporting at `external`/`const` instead of
at `{`/`=>`).
Key changes:
- Remove constructor-body validation from AstBuilder (const bodies, const
factories) and stop converting the corresponding Fasta codes to analyzer
diagnostics to avoid duplicate reporting.
- Add a single verifier entry point that validates whether a body is allowed
based on:
- factory vs generative
- const vs non-const
- external vs non-external
- redirecting vs non-redirecting
- Reuse the same validation for both regular constructors and primary
constructors, and report at the body token for stable source ranges.
- Add a shared check for `external` functions/methods with block or expression
bodies, and apply it consistently to top-level functions and class members.
- Align expectation files to the new, body-based error ranges and remove
formatter-crash classification where the new reporting no longer triggers it.
Change-Id: Ie91ea08a7b5505d3e6443b12317c45359bac1c2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477780
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Constructor-body related expectations were split across generated parser
tests and a dedicated diagnostic test, with uneven coverage for primary
constructors and newer declaration forms (enums, extension types). This
made it easy for behavior to drift and hard to add new cases
consistently.
Refactor and expand the test coverage:
- Replace the standalone const-constructor-with-body suite with a unified
constructor_body_test.dart that exercises primary and secondary constructors
across classes, enums, and extension types, covering:
- const vs non-const generative constructors
- factory vs redirecting constructors
- external modifiers and the interaction with bodies
- block, empty, and (where applicable) expression-body forms
- Add a focused external_method_with_body_test.dart to cover external methods,
getters/setters, operators, and top-level functions with bodies.
- Remove redundant constructor-body cases from generated error/parser tests and
update a few remaining assertions to check the exact diagnostics now that
highlighting spans are stable.
- Wire the new suites into diagnostics/test_all.dart.
This reduces duplication, centralizes the behavior matrix in one place,
and makes future language-feature coverage extensions straightforward.
Change-Id: Iafa6458531bfa19862390567f193a36a88558c03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477781
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Stop converting front end `constNotInitialized` and
`finalNotInitialized` reports, and instead centralize these diagnostics
in `ErrorVerifier`. This avoids duplicate reporting and keeps
initialization rules consistent with analyzer resolution.
Unify variable/field initialization checks by:
- Verifying `const` declarations without initializers in the verifier for fields, top-level variables, and local declarations.
- Reporting `finalNotInitialized` for non-late, non-external, non-abstract
declarations that cannot be initialized elsewhere.
- Reporting non-nullable uninitialized diagnostics based on the resolved
element type, distinguishing instance fields from static/top-level
variables.
- Treating a primary-constructor body as intent to have a generative
constructor, deferring instance-field initialization validation to the
constructor-field verifier.
Improve error positioning for `primaryConstructorBodyWithoutDeclaration`
by anchoring the diagnostic on the `this` token, producing a tighter and
more actionable source range.
Change-Id: Id01b5a36b9fcc00e8ed282466db2d845c06e3b40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/477360
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
No more flag, always parse into the new AST, always visit new AST nodes,
always return them as child entities, parent-child structure reflects
the new AST.
So, use `namePart` and `body` where possible. Deprecate previous
properties.
This is still de jure a breaking change, because `parent` of deprecated
properties changes. De facto this required very few changes in google3.
Once this CL lands, I will publish `analyzer 10.0.0`, migrate everything
to new properties, delete deprecated properties, and publish `analyzer
11.0.0`.
Maybe deprecate `NamedCompilationUnitMember.name` and migrate to
subclass specific `name` or `namePart` properties before publishing
`analyzer 10.0.0`. This part is not breaking per se.
* Deprecations in `ClassDeclaration`:
* Properties `leftBracket`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `name`, `typeParameters` are deprecated, use `namePart` instead.
* Deprecations in `EnumDeclaration`:
* Properties `leftBracket`, `constants`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `name`, `typeParameters` are deprecated, use `namePart` instead.
* Deprecations in `ExtensionDeclaration`:
* Properties `leftBracket`, `members`, `rightBracket` are deprecated, use `body` instead.
* Deprecations in `ExtensionTypeDeclaration`:
* Properties `leftBracket`, `constants`, `members`, `rightBracket` are deprecated, use `body` instead.
* Properties `constKeyword`, `name`, `representation`, `typeParameters` are deprecated,
use `primaryConstructor` instead.
* **Breaking Change:** While the deprecated members mentioned above still exist in the AST,
their parent nodes have changed. This means that code relying on specific parent-child
relationships for these nodes might break.
Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: Ic48104da8b029c9b454bbd2336574b7823025565
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461841
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Changes the analyzer and related packages so that when they refer to
diagnostic constants, they do so via the import prefix `diag`, which
refers to the appropriate `diagnostic.dart` file containing the top
level diagnostic constant declarations, rather than the static
declarations inside `DiagnosticCode`-derived classes (which will soon
be removed).
This CL was created by the following steps:
- Run the script
`pkg/analyzer_utilities/tool/messages/switch_to_toplevel_diagnostics.dart`.
- Execute `dart fix --apply --code=unused_import,unnecessary_import`
on the following directories (this removes imports that are no
longer necessary due to the change):
- `pkg/analysis_server`
- `pkg/analyzer`
- `pkg/linter`
- `pkg/analysis_server_plugin`
- `pkg/analyzer_plugin`
- `pkg/analyzer_testing`
- `pkg/front_end`
- `pkg/analyzer_cli`
- Execute `dart format` on the following files and directories:
- `pkg/analysis_server`
- `pkg/analyzer`
- `pkg/linter`
- `pkg/analysis_server_plugin`
- `pkg/analyzer_plugin`
- `pkg/analyzer_testing`
- `pkg/front_end/test/scanner_test.dart`
(Note that `pkg/front_end` and `pkg/analyzer_cli` are not
re-formatted as whole directories because they contain `.dart` files
that are test cases rather than source code, and reformatting those
files might change test expectations.)
- Manually add `diag` to
pkg/front_end/test/spell_checking_list_tests.txt.
- Manually fix the ignore comment in
`pkg/analyzer_testing/lib/src/analysis_rule/pub_package_resolution.dart`. (The
script `switch_to_toplevel_diagnostics.dart` automatically adds it
after `import 'package:analyzer/src/diagnostic/diagnostic.dart' as
diag;`, but then executing `dart format` bumps the ignore comment to
the following line, where it has no effect.)
Change-Id: I6a6a69643022aab2b5a6224fb4124eead243260d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461521
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This also includes some small refactorings for parameter names to start using the diagnostic wording instead of error. As well as a small change to `contextMessage` and related to use a list of `Pattern`s instead of a single `String` for better matching.
In future CLs, the TODOs added in this one will be addressed so we can fully migrate this. Added them because of the size of the CL.
Bug: https://github.com/dart-lang/sdk/issues/61557
Change-Id: I5557668a1baed98faff977255c9f22e0d9d96008
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452180
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Felipe Morschel <git@fmorschel.dev>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Removes the analyzer error code `ScannerErrorCode.expectedToken` and
replaces usages of it with `ParserErrorCode.expectedToken`. This
avoids an ambiguity between the two messages.
Avoiding ambiguities like these is important, because in many cases
the user only sees the diagnostic name; they don't see the class it's
in. For example, `ignore:` comments just give the diagnostic name, and
the web page https://dart.dev/tools/diagnostics only shows diagnostic
names.
In the future I intend to add an error check to the analyzer
diagnostic code generator, to ensure that there are no ambiguities
like these. This CL is a prerequisite for adding the error check.
Change-Id: I6a6a696491a41a9d220a4502bfa9b96410580a19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455561
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Removes the analyzer error code `ScannerErrorCode.missingIdentifier`
and replaces usages of it with
`ParserErrorCode.missingIdentifier`. This avoids an ambiguity between
the two messages.
Avoiding ambiguities like these is important, because in many cases
the user only sees the diagnostic name; they don't see the class it's
in. For example, `ignore:` comments just give the diagnostic name, and
the web page https://dart.dev/tools/diagnostics only shows diagnostic
names.
In the future I intend to add an error check to the analyzer
diagnostic code generator, to ensure that there are no ambiguities
like these. This CL is a prerequisite for adding the error check.
Change-Id: I6a6a696467b91740c152278f538b9fed763e258f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455540
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
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>
This change was generated by the following process:
- The script `pkg/analyzer/tool/messages/rename_error_constants.dart`
was run. This generated the vast majority of the diffs.
- Then all modified files were reformatted using
`tools/sdk/dart-sdk/bin/dart/format`.
- Finally, the script `pkg/analyzer/tool/messages/generate.dart` was
run, to rebuild generated code.
Change-Id: I6a6a69644ed8740ad6269d98cb169076151824ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444921
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The error codes are not being generated and the mapping to `EXTRANEOUS_MODIFIER` in tests is unnecessary.
This logic is likely a hold over from when the analyzer had it’s own parser with temporary conversion logic to align it with fasta. With only one parser, these bits are stale and should be safe to remove.
Change-Id: I5b29f0081953c61771b313025595910eef055c2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367540
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This turns on the flags for these two language features and makes
them generally accessible.
Doing so causes a number of tests to fail, but the failures are
approved and there are filed issues for them. Most of the
failures are minor or only affect code using the new language
features.
This CL:
- Enables the features in experimental_features.yaml.
- Re-generates all of the various files generated from that.
- Makes some analyzer and front end changes that this CL
inherited from Paul's original CL flipping all of the 3.0
feature flags. I don't know what these changes are about, but
I assume they are necessary.
- Pins a couple of tests to 2.19 since they deliberately test
behavior that is specific to 2.19. (For most test changes, I've
landed them separately, but there are a couple of stragglers
in this CL.)
This doesn't enable "class-modifiers" or "sealed-types" and doesn't
include the core lib changes related to those.
TEST=On bots
Change-Id: Id387753772286a958e20a3589a6e983995f2e4a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286344
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
E.g. if reporting a missing ";" after a SyntheticStringToken (e.g. a
inserted identifier) before this CL it would go to the next token and
say we expected the ";" after that, when really we expected it *before*
that token.
Change-Id: I2c358e017edb2f661e307eba03dddaee889086d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205799
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>