Move another batch of analyzer tests away from offset-based
assertErrorsInCode() expectations. Put expected diagnostics and context
messages directly in the source snippets instead, including multi-file
cases that need context markers in supporting files.
This keeps each diagnostic expectation next to the code that produces
it, making the tests easier to read and less fragile when surrounding
code changes. It also removes now-unused diagnostic imports and helper
parameters that were only needed for explicit ExpectedDiagnostic lists.
Update the diagnostic expectation utilities so stripping generated
marker lines preserves the retained source lines correctly.
Change-Id: Ibe3890b9ff5e2b2e102e13e5ecc243bdf80c5f4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509682
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Add helpers that resolve non-test files using the same inline diagnostic
expectation format as resolveTestCodeWithDiagnostics.
resolveFileWithDiagnostics handles a single file, while
resolveFilesWithDiagnostics writes all related files before resolving
any of them.
Add multi-file diagnostic expectation generation so context messages in
one file can be referenced from diagnostics reported in another. Teach
expectation updating how to target values in a files-to-code map using
per-entry intra-invocation ids.
Remove assertErrorsInFile2 and migrate diagnostics tests from
hand-written ExpectedError offsets to inline markers. This keeps the
diagnostic range, code, message, and cross-file context next to the code
under test, and makes expectation updates reusable for library and part
tests.
Initialize strong-mode type assertions from resolveFile so callers that
resolve files other than testFile get the same setup.
Change-Id: Ie492155b046c28a535faf21fa9a2e47797caffb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506180
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Stop storing the most recently resolved unit in ResolutionTest. Make
test helpers operate on explicit result objects instead, so each
assertion uses the diagnostics, type provider, type system, and
inheritance manager from the result it is checking.
This makes the tests less order-dependent and easier to reason about. A
test can now resolve more than one file or unit without later assertions
implicitly depending on whichever result happened to be stored last. It
also makes helper APIs more local: the data needed by an assertion is
passed directly, rather than recovered from mutable test state.
Update tests to keep the returned result when they need access to the
resolved AST or result-derived utilities. Add convenience accessors on
the result wrappers to preserve common lookup patterns without
reintroducing shared mutable state.
Change-Id: Ib45c52f8fd104b668f9fdd1ec6b1442927cd7e61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505920
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Stop exposing common type and element shortcuts from ResolutionTest so
tests use the resolved unit's TypeProvider and library state directly.
This keeps the shared resolution test mixin focused on resolution
utilities instead of duplicating accessors for analyzer internals.
Move the affected flatten coverage out of StaticTypeAnalyzerTest and
into the dedicated built-type tests. This keeps flatten, futureType, and
unionFreeType behavior together in FlattenTypeTest and related test
classes, including coverage for recursive hierarchies and conflicting
Future interfaces.
Update remaining callers to read the library feature set from the
resolved result, and remove assertions that depended on the deleted
ResolutionTest element shortcuts.
Change-Id: I714aec736636500b293b547972a64dc0541172a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505500
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
We still have `late ResolvedUnitResultImpl result` for now, but many
tests migrated to explicit `TestResolvedUnitResult` and its getters.
Start migrating analyzer resolution tests away from the implicit
ResolutionTest state. Store the TestResolvedUnitResult returned by
resolve helpers in local variables, then read nodes and elements through
that result.
Update helper methods to take the resolved result explicitly when they
need access to findNode or findElement. Also return resolved results
from small wrapper helpers so their callers do not have to depend on
shared state.
This keeps each test tied to the unit it resolved and prepares the test
harness for removing the remaining stored resolution result.
Change-Id: I5e9331fb574d962473e5d36922107f674d7340cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505621
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Update generated AST node metadata and token ordering so child entities,
begin tokens, and reconstructed source follow the grammar order for
modifier tokens.
Place `augment` before declaration modifiers on class type aliases and
the affected top-level and class-level declarations. Order field
modifiers as `augment external static abstract covariant`, and order
named formal parameter modifiers as `required covariant`.
Also emit the missing modifier tokens in `ToSourceVisitor` so source
reconstruction preserves augmentation syntax and the canonical modifier
order.
Change-Id: I57b4aa05f856779526bc3c8d5e3319d8c260bc49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504682
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Add support for keeping parser diagnostic expectations in the source
snippets they describe. Expectations are written as caret markers and
diagnostic comments, and regenerated from the parser's actual
diagnostics before comparison.
This keeps parser recovery expectations close to the code under test and
removes the need to maintain offset-based `assertErrors` lists by hand.
The updater also removes existing expectation markers before writing the
canonical form, so marked snippets can be refreshed in place.
Migrate recovery parser and class parser tests to the new
`assertExpectedDiagnostics` helper, including no-error cases where an
unmarked snippet is the expected canonical form.
Update `test_runner` to exclude `/pkg/analyzer/` from searching static
error expectations.
Bug: https://github.com/dart-lang/sdk/issues/63335
Change-Id: Ic9866da8cc601c6b360552ba576e8aa1646f89a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501340
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
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>
Replace the positional Scanner constructors with a single constructor
that takes the input text and error reporting callback as named required
arguments.
Remove the unused fasta forwarding constructor, reader offset handling,
and stored first token. The scanner now keeps only the input text and
returns the token stream directly from tokenize.
Update analyzer, analysis server, plugin, CLI, scrape, and scanner test
call sites to use the named constructor arguments.
Change-Id: Ieabb7b28570d4a963563fb2d1c5ef5ac0c89032a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500340
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Use FileSource backed by analyzer_testing resources instead of the
test-only Source implementations in analyzer tests.
Update the lightweight TestAnalysisContext to receive a
ResourceProviderMixin and install a URI resolver that produces real
FileSource instances for the dart: and package: URIs used by mock SDK
elements. Convert scanner, diagnostic, options, constant, type system,
and workspace tests to create sources from in-memory files.
Remove the remaining Source mock helpers, including TestSource,
TestSourceWithUri, local Source mocks, and the unused TestTypeProvider.
This keeps test sources closer to production Source behavior and avoids
partial mock implementations that rely on noSuchMethod stubs.
Change-Id: Iad600fb7f5ea00d2c015191df548e0d66a424940
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499422
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Replace the generic mutable reference tree with typed reference classes
for roots, libraries, top-level declarations, member containers,
members, and built-in elements.
The previous API was shallow. It offered a small primitive,
`getChild(String)`, but pushed too much knowledge to every caller: which
sentinel names exist, which paths are valid for each declaration kind,
which references may contain members, and which references are not real
declarations at all. That kept the reference implementation simple by
spreading its complexity across the analyzer.
Make the reference model deeper instead. Callers now ask for the
semantic role they need, such as a library, constructor, method, field,
or top-level declaration. The reference layer owns the representation,
lookup, creation, and serialization details. This concentrates the
complexity behind a narrower interface, makes the common cases clearer,
and makes invalid reference shapes harder to construct.
This is a strategic cleanup rather than a local simplification. The
reference graph is used by element construction, summary reading and
writing, scopes, exports, and fine-grained dependency manifests. Giving
it explicit concepts reduces the amount of convention each subsystem
must remember and preserves a simpler mental model at the call sites.
Update summary serialization to write semantic reference rows with a
tag, enclosing reference, kind, key, and URI payload. Bump the analyzer
data version because this changes the linked summary format.
Represent exported declarations as export entries that carry the
exported name, reference, and export locations. Use those entries when
building scopes, filtering deprecated exports, and updating fine-grained
library manifests.
Keep import prefixes out of the declaration reference tree. Bind prefix
fragments through fragment-local ids so prefixes can be restored and
merged without fabricating declaration references.
Bug: https://github.com/dart-lang/sdk/issues/63227
Change-Id: If28f8b779faa78bdf023bc69b714555fae57ccb3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497621
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Replace manual type construction utilities in type system tests with a
unified string-based type parser. This simplifies test code, improves
readability, and enables more expressive type scenarios.
Key changes:
- Introduce TypeSpecParser and TypeParsingScope to parse types,
function types, records, and type parameters from strings.
- Add parseType() and related helpers to AbstractTypeSystemTest,
replacing ElementsTypesMixin usage.
- Remove ElementsTypesMixin and migrate all tests to use parsed
types instead of manually constructed TypeImpl instances.
- Extend _SpecParser to support:
- Promoted type parameter bounds (`T & int`)
- Parenthesized vs record types disambiguation
- Additional built-in types (InvalidType, UnknownInferredType)
- Variance in generic function types
- Covariant parameters
- Refactor scope construction to use _Scope.forLibraries, reducing
duplicated interface/type alias collection logic.
- Add standalone materialization flow for type parameters to support
parsing in isolation.
Impact:
- Tests become more declarative and closer to Dart syntax.
- Eliminates boilerplate and reduces risk of inconsistencies in
manual type construction.
- Enables testing of newer type system features (promotion,
variance, complex function types) via concise string specs.
Change-Id: I85dd0aa88a37142356f14419d0d35350e38b9c8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497680
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Move buildLibrariesFromSpec to a parsed header model instead of
assembling mock declarations from many separate fields.
This rewrites the test library builder around declaration objects that
first create fragments and elements and then resolve their types in a
second pass. Specs now describe classes, constructors, methods, mixins,
extension types, typedefs, and top-level functions using compact
Dart-like headers, and the builder parses those headers in one place.
This makes mock libraries easier to read and update, keeps test data
closer to real source syntax, and removes a lot of repetitive client
code. It also simplifies the surrounding helpers by using named
arguments, adding missing library support for type aliases, and
providing small convenience APIs for looking up declarations in tests.
Change-Id: I6a3b174b3899b4350b571906dc9784a59affe216
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497181
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Expand the test library builder so more unit-style type system tests can
construct declarations through LibrarySpec instead of assembling
elements and fragments by hand.
Add support for imports and external libraries, enums, mixins, extension
types, type aliases, class mixins, type parameter bounds and variances,
and additional parsed type forms needed by these tests. Also add shared
helpers in type_system_base to build test libraries with the mock SDK
libraries and wire in the type provider and type system.
Migrate the affected tests to describe their libraries declaratively and
look up the resulting elements from the built library. This removes a
large amount of bespoke test-only element construction, drops helper
APIs that were only needed for hand-built declarations, and makes these
tests exercise element shapes that are closer to normal analyzer code.
Change-Id: Ic4180a64a5309b87b942f95ff45f682fbb8399df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496664
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@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>
The function mostly returned null/nonsense if given a null argument,
and the few call sites with nullable arguments (in tests and tools)
are easily tweaked.
Change-Id: I7f9993696c4bd822b648a5a89114e6af25eac552
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490020
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
I initially thought it had a bug, because I didn't
recognize that it would scan the same characters more than once.
So changed to never scanning the same character more than once,
for a completely linear pass, and some small tweaks.
Change-Id: If24955cf3b3d22cc2818a0751d14a68661b4219b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486982
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
The RegEx engine in the VM was updated in
e443b89f23 which caused the analyzer
analyzing the CFE to use ~150 mio instructions more.
Part of this was an increased cost in formatList which before cost ~40
mio and after cost 114 mio (analyzing the cfe).
This CL removes the regex from the method reducing the cost to ~19 mio,
saving ~95 mio instructions.
Numbers from `valgrind --tool=callgrind`.
Change-Id: I7c72d9e4ed3a21e627a3c846428c2e62965d4602
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486782
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@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>
Rewrite ComplexParserTest to parse full snippets with
parseStringWithErrors and verify AST shape with assertParsedNodeText.
This moves the suite from fragment-oriented parsing and ad hoc property
checks to the parser diagnostics harness, so each case now asserts the
parsed structure and the recovered diagnostics together. That makes the
tests more explicit about precedence, recovery, and how complex
constructs are embedded in real code.
Update the migrated cases to select nodes from wrapped function or class
bodies, and add FindNode.firstBinaryExpression to make that navigation
easier.
Adjust expectations where full-snippet parsing recovers differently from
expression-only parsing, including written-out operator cases that now
validate the parser's actual recovered AST.
Change-Id: I06ff024afac03a2814943aa3228de99e767cdc84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/485584
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Changes the test logic in `analysis_server` and `analyzer_testing` so
that after printing `To accept the current state, expect:`, it prints
diagnostic codes in their proper camelCase format.
Also removes some bogus code from
`pkg/analyzer_testing/lib/analysis_rule/analysis_rule.dart` that
erroneously suggested passing a `name:` parameter to the top level
`error` function. This function does not accept any parameter called
`name`.
Previously, only tests in `pkg/analyzer/test` printed the diagnostic
codes correctly.
Fixes https://github.com/dart-lang/sdk/issues/62651.
Change-Id: I6a6a6964b17cf798c1355e09f9a4633e1fbe388c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480041
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>