Commit Graph

8475 Commits

Author SHA1 Message Date
Robert Nystrom 2cd3ec552c Fix "Convert to a primary constructor" on generic classes.
It would incorrectly put the primary constructor parameter list before
the type's type parameter list, like:

```dart
// Before:
class C<T> {
  C();
}

// After:
class C()<T> {
}
```

This fixes it to follow the type parameter list if there is one.

Change-Id: Ib49c7df7923e9feed11f87579fefc8300c56c4a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506760
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2026-05-27 13:59:34 -07:00
Sam Rawlins d0f27293ce DAS plugins: Respect the analysis roots set by "dart analyze"
Work towards https://github.com/dart-lang/sdk/issues/62686

`dart analyze` uses an 'analysis.setAnalysisRoots' "command" to let
the analysis server know that the user requested, for example,
`dart analyze foo` or `dart analyze foo/bar.dart`. This was not conveyed
to analyzer plugins, so analyzer plugins will always analyze the entire
context collection.

(For some reason, only files in the "analysis roots" were reported in
stdout; maybe DAS or dartdev does its own filtering on diagnostics.)

This change forwards the `setAnalysisRoots` request to DAS plugins using
a new protocol message that mirrors the one for the server.

We should not change the behavior of `analysis.setContextRoots` for
legacy plugins, so we keep sending that request as per usual. Then
we send `analysis.setAnalysisRoots` at the same time.

If we receive an `analysis.setAnalysisRoots` message, dispose and
delete references to the existing context collection, and instantiate
a new one, with the specified `included` and `excluded` paths.

Change-Id: I53627da1c30351a22b5e5410a557bf486620a7aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505041
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-27 13:47:02 -07:00
Konstantin Shcheglov ba760c36a4 Augment. Report augmentationInducedGetterAlreadyComplete and augmentationInducedSetterAlreadyComplete.
Change-Id: I87ba9c5b6c489417173a387bded700f52b52e7ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506501
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-27 11:17:44 -07:00
Sam Rawlins 0fa39c9649 linter: Switch cascade_invocations to report once for a set of cascadable statements
Fixes https://github.com/dart-lang/sdk/issues/58688

Change-Id: I022b58109deedfbd6e57e6aa5159942081e6d8fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503941
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-27 08:58:12 -07:00
Sam Rawlins c4d1c3a3e8 DAS plugins: Fix entrypoint deletion bug
I recently introduced this deletion logic but was deleting the wrong
file; this was deleting the `plugin.dart` file that `plugin.aot` is
compiled from. Over the weekend I found this issue with manual testing.
I've also verified this fix with manual testing.

Change-Id: I3f570368068117e6bb952ada0707a09ee97b765c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506320
Auto-Submit: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-26 10:13:34 -07:00
Konstantin Shcheglov 8c6366e66e Augment. Deprecate ExtensionTypeDeclaration.primaryConstructor, use namePart instead.
Extension type augmentations do not have representation declarations, so
an `ExtensionTypeDeclaration` can no longer always expose its name
through a primary constructor. Add `ExtensionTypeDeclaration.namePart`
as the canonical API for the declared name and type parameters, and keep
`primaryConstructor` as a deprecated compatibility API for introductory
declarations.

Report `extensionTypeAugmentationHasRepresentation` when an augmentation
writes representation syntax. This keeps the parser recovery explicit:
the augmentation still gets a plain `namePart`, while the invalid
representation is diagnosed instead of being modeled as the
declaration's primary constructor.

Synthesize recovery representation and primary constructor fragments
only for the element model when an extension type has no introductory
declaration.

Migrate analyzer, analysis server, analyzer plugin, and linter clients
to read extension type names and type parameters from `namePart`.

Change-Id: I59dd957ac38f087c861b993caf246986dcdac713
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505067
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-26 10:05:28 -07:00
Konstantin Shcheglov 4629bff7e9 Augment. Report extensionTypeAugmentationSpecifiesRepresentationField.
Add a syntactic diagnostic for extension type augmentations that declare
representation fields. Extension type augmentations may augment the
declaration, but they must not redeclare the representation.

Thread an explicit parser option through primary constructor parsing so
extension type augmentations can omit a representation without producing
the usual missing-primary-constructor diagnostics, while still reporting
an error when a representation is present.

Register the new diagnostic in the shared and analyzer generated
diagnostic tables and add it to fix status tracking.

Change-Id: I84815bb0669a76126564e590760e93096a3af046
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505860
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-22 17:36:54 -07:00
Brian Wilkerson ec40ebcd23 Fix a bug in textDocument/definition for primary constructors
Change-Id: Id24cdfda1c84322b5fa77cca0c87df0784482ec6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506080
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-22 17:05:29 -07:00
Brian Wilkerson 03a05b52d8 Fix a primary-constructors bug in ElementMatcher
The element matcher threw a null check exception when getting a matcher
in the argument list of a constructor redirect in a secondary
constructor declaration with no explicit type name. This fixes it so
that no exception will be thrown.

That said, it isn't clear to me that this code could ever be reached
outside of the tests. There might be a lot of unreachable code in
ElementMatcher. I just can't prove that this particular bug would never
have occurred.

Change-Id: I5adf9ab5d4f79686110099054902a28535483f4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505921
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-22 13:23:38 -07:00
Brian Wilkerson 739826d041 Update ImportedElementsComputer for primary constructors
This CL is to resolve a TODO. I couldn't find a way to trigger any bugs
in the code, but I did add a test. I believe that the reason I couldn't
trigger a bug is because any constructor that has a null `typeName`
will not have a simple identifier in a place that would allow
`_isConstructorDeclarationReturnType` to be invoked.

I realized, while looking at the code, that the type check is
unnecessary. If the type name is null, then the test will somply return
`false`, which is what we'd expect it to do. Given that it isn't needed,
I decided to remove it.

Change-Id: Ib36aaf16475db0db5817e65a8b8bfbb8aa834dbd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505501
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-22 12:53:51 -07:00
Danny Tuppeny c8a74e71ef [analysis_server] Add classes for processing interactive forms
This adds some classes for processing interactive forms (I'm splitting this from the CL that updates refactorings to simplify reviewing).

The `InteractiveForm` class managers a whole form (all fields), and processes a set of fields/answers that come back from the client (which may be the full set, or a subset). It produces a list of the outstanding fields (which need to be go back to the client) as well as maintaining the full set of answers for the master field list (to use as arguments for a command, for example).

I've also commented out enums/lists from the protocol code for now, because I made the field kinds `sealed` so we get exhaustiveness checking in the validation, but want to delay fully implementing those for now.

See https://github.com/dart-lang/sdk/issues/63371

Change-Id: Icc4dcea8c9eab20ffbdd19ebbc69e1285464f7ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505683
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-22 12:44:58 -07:00
Paul Berry 643733b42e [analyzer etc] Add ignores for codegen to prepare for new syntax.
(Part of https://github.com/dart-lang/sdk/issues/63288)

Updates the `CodeGenerator` mixin so that it outputs `ignore_for_file`
comments to ignore the following lints:
- unnecessary_type_name_in_constructor
- unnecessary_ignore
- duplicate_ignore

This mixin is used by the code generators that produce the Dart
wrappers for the analysis server and analyzer plugin wire protocols.

This is a first step towards migrating the packages `analysis_server`,
`analysis_server_client`, and `analyzer_plugin` packages to use the
new constructor declaration syntax, since it will allow the
`unnecessary_type_name_in_constructor` lint to be enabled without
breaking generated code.

Once all the packages have had their SDK constraints bumped to a
language version that supports the new syntax, I'll update the code
generator to use the new syntax, and remove the ignores.

For more information about the new constructor declaration syntax, see
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

Change-Id: Ied17e3ea772546675aad48efc324f6f16a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505521
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-22 10:30:17 -07:00
Brian Wilkerson 1e1ecd8b41 Fix code completion before keyword in constructor
This fixes an exeception when code completing before the `new` or
`factory` keyword in a constructor and the type name is not explicitly
used. The exception prevents any suggestions from being returned, so
it's fairly serious.

Change-Id: I2f5028812ee1945ac9635f55953fb800b19a48c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505620
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-22 10:25:06 -07:00
Danny Tuppeny 5a40aaaecc [analysis_server] Fix isAvailable check for "Remove constructor name" on unnamed constructor invocations
This code was checking the name of the type instead of the name of the constructor.

Fixes https://github.com/Dart-Code/Dart-Code/issues/6061

Change-Id: I180940162aa7ff12e4ec19aa002a188961d7aad5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505684
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-22 08:26:51 -07:00
Brian Wilkerson 349e81f62f Resolve TODO for occurrences
I couldn't find a way to trigger an exception, so there's no test.

I think this is ok because this code isn't actually used. IntelliJ
doesn't register for the notifications built by this code. And if
there's another client somewhere that does, the effect of the change
is to not generate an occurrence in a place where it would be
invalid because the legacy protocol doesn't support occurrences where
the name length is different.

Change-Id: I328d7f605b97e7570a9e6a5385dca4b0c4aa64af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505502
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-21 14:54:46 -07:00
Brian Wilkerson f2319d4ed4 Support fixing codes not enabled in the options file
Codes specified on the command-line are force-enabled in all of the
analysis options for all of the files. This is done in a brute force
way, but it should be safe because the code is creating an analysis
context collection just for this one run, so the options objects
should be short lived.

Closes https://github.com/dart-lang/sdk/issues/63345

Change-Id: I8925da426d6cb5b9ce686725e3b95696b552cae0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505045
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-21 12:57:18 -07:00
Keerti Parthasarathy ea3fb4d69a [analytics] Fix issue where fields from env variables were not populated
Bug: https://github.com/dart-lang/sdk/issues/63246

Change-Id: I9956cbfc7e4718727558727990e61baa59436ad5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505051
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-20 21:02:10 -07:00
Sam Rawlins bcb511529a DAS plugins: Remove AOT snapshot before compiling a new one
Fixes https://github.com/dart-lang/sdk/issues/63385

Change-Id: I76cecc3486f3fc03093efac8c7cc2d65c8977eb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505062
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-20 16:25:29 -07:00
Danny Tuppeny 4b609fd598 [analysis_server] Refactor some refactoring classes to simplify a future change
These are just some minor changes (logically, but a bit noisy mixed in with upcoming functional changes) from a future change I'm working on to handle command resolution for the new refactorings. In particular:

- Make it a bit clearer which classes refer to which refactoring system
- Rename `RefactorCommandHandler` -> `RefactorCommandExecutor` since there will also be a Resolver soon
- Extract some code from `RefactorCommandExecutor` into `RefactorCommandHandlerMixin` so it can be reused by the upcoming resolve handler
- Fix some type args that used `Object` when some implementations are `void` but we don't care about the type anyway
- Create a `ParameterizedRefactoringProducer` abstract class so that all refactors with no parameters don't have to implement stubs for `parameters` (and soon `resolve()`)

Change-Id: I865da1c5dac9dc5834564b5a4a47199c20b64979
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504601
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2026-05-20 15:00:15 -07:00
Konstantin Shcheglov fb2962c045 Issue 63382. Use WorkspacePackage.isInTestDirectory() instead of CompilationUnitExtension.
Bug: https://github.com/dart-lang/sdk/issues/63382
Change-Id: I3c1d2495f9cb6804c73d1f36314556186f825a67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505064
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-20 14:39:04 -07:00
Keerti Parthasarathy d3f4debece [dart fix]Fix adding package to both dependencies and dev_dependencies in pubspec.
Closes https://github.com/dart-lang/sdk/issues/63409

Change-Id: I51258cf986b9b60a8d7add58f7737d6c8bf9f1ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505040
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-20 12:56:57 -07:00
Sam Rawlins 73b76b93b3 DAS: Make more fields final or visibleForTesting
Change-Id: I43812c53605ed722dec7f45377b5d5cfbe6ef443
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504762
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-20 10:09:44 -07:00
Sam Rawlins 5f2c7f7ef0 DAS: Replace RequestConverter with extensions
Preliminary work before introducing a 'setAnalysisRoots' request

Also remove inferred types, in the tests. Very old style.

Change-Id: Id4495702419f1e219f758c509fdc617f6d411d54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504761
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-20 07:36:29 -07:00
Kallen Tu efd30a2de0 [migrate] Initial implementation of SDK constraint bumping.
Uses the pubspec util `computeVersionBumpEdit` that bumps the pubspec
file's `sdk:` one minor version up.

Very basic iteration through the given pubspec files to bump all of
them. We'll very likely have to refactor this as we get the pre/post
migrations involved, but I wanted to get there in small (reviewable)
steps.

Bug: https://github.com/dart-lang/sdk/issues/63268
Change-Id: I2a7abeacdc76b114dfef7888cd6db6bc8973d01a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504381
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-19 14:11:50 -07:00
Konstantin Shcheglov eba2982bc8 Augment. Report augmentationInducedGetterReturnTypeMismatch.
Report a dedicated diagnostic when an augmenting field or top-level
variable induces a getter whose return type differs from the getter
being augmented.

Previously, augmentation return type checking only covered executable
declarations with explicit return type annotations. Variable
augmentations that induced getters could therefore miss this mismatch,
or would not describe the induced getter case directly.

Add the new diagnostic code and use it for getter fragments induced by
variables. Keep the existing augmentation return type mismatch
diagnostic for methods and explicitly declared getters, and report the
induced getter diagnostic on the variable name so that mismatches in
multi-variable declarations are attributed to the specific variable.

Change-Id: Ifb421112d659815070110834702f68616e360a10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504181
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-19 09:48:27 -07:00
Konstantin Shcheglov 76011f9fe0 Augment. Report augmentationWithoutGetterDeclaration or augmentationWithoutSetterDeclaration.
Add diagnostics for augmenting fields and top-level variables when the
augmentation induces an accessor that has no corresponding declaration
to augment.

Report these errors on each variable name rather than on the augment
keyword, so multi-variable declarations can report missing augmentation
targets independently. Include context pointing to the matching declared
or induced accessor when only one side of the getter/setter pair exists.

Register the getter- and setter-specific diagnostics in the generated
diagnostic tables and correction status metadata.

Change-Id: I78393a6e8bffe8748eb0fbc5182a0d01770771d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504180
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-18 18:42:53 -07:00
Kallen Tu 7ca32bdbbf [migrate] Refactor version bumping from update_sdk_constraints to a util file.
This is a prerequisite CL to the next one that will add version bumping
to the dart migrate tool: https://dart-review.googlesource.com/c/sdk/+/504381

Refactoring the version bumping logic out of `update_sdk_constraints` so
it can be shared between the correction producer and the migrate tool.

`PubspecEdit` also contains the old and new versions so the migrate tool
can refer to those in its summary text.

Bug: https://github.com/dart-lang/sdk/issues/63268
Change-Id: I488cf10694b89df1ed770ee0f27f13a00d1dd3be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504340
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-18 14:40:27 -07:00
Danny Tuppeny 9a48747a61 [analysis_server] Fix hover on enum constant declaration
Fixes https://github.com/dart-lang/sdk/issues/63223

Change-Id: I42c75520ce11932bd1c894783cbfc27ac3c8ebd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504260
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2026-05-18 08:37:16 -07:00
Konstantin Shcheglov 5ed538a532 Bug fix: implement missing diagnostic implementsSuperClassConstraint.
It is disabled when augmentations feature is enabled.

This is not a breaking change, because CFE did report this error.

The relevant reason is indirect, not a single sentence saying “on A
implements A is forbidden”.

Spec chain:

1. In dartLangSpec.tex:6019, a mixin declaration is modeled as:

`mixin N<T...> on T1, ..., Tn implements I1, ..., Ik { ... }`

2. In dartLangSpec.tex:6065, the mixin interface M_I is defined as if
by:

`abstract class N<T...> implements T1, ..., Tn, I1, ..., Ik { ... }`

and dartLangSpec.tex:6078 says it is a compile-time error for the mixin
if that synthetic class declaration would be a compile-time error.

3. In dartLangSpec.tex:5189, class superinterfaces say:

It is a compile-time error if two elements in the type list of the
IMPLEMENTS clause of a class C specifies the same type T.

So:

`mixin M on A implements A {}`

is checked like:

`abstract class M implements A, A {}`

which violates the duplicate implements type rule.

Change-Id: I29e5fa17c47d111346ef6a6e321ab5dbab985ad1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503501
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-05-18 07:55:50 -07:00
Keerti Parthasarathy 001a3ba29b [data-driven]Support for replacing a deprecated library.
Bug: https://github.com/dart-lang/sdk/issues/62849


Change-Id: I2eb323319264ded024acf3b3ede2460eae974a83
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503700
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2026-05-15 08:55:14 -07:00
Paul Berry aaa48e2247 [deps] Roll prebuilt Dart SDK to 3.13.0-103.1.beta.
This will allow use of Dart 3.13 features (such as primary
constructors) within the SDK itself.

Note that some generated files required benign updates due to
formatter behavior changes.

Change-Id: I595554e9cff3dbaa3f11da407d6c26036a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503662
Auto-Submit: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-15 08:23:09 -07:00
Konstantin Shcheglov 56706b715d Augment. Report incomplete augmented executable declarations.
Report new diagnostics when an introductory function, member, or factory
constructor is still incomplete after applying all augmentations.

Keep the existing missing-body diagnostics for declarations that have no
augmentations, but report augmentation-specific diagnostics when an
augmentation chain exists and none of the fragments provides a body or
factory redirection.

Move the checks into error verification so that extension and extension
type members can participate in augmentation completion before reporting
the existing abstract-member diagnostics. Also suppress the
corresponding shared parser diagnostic when it is reported by the
verifier.

Consolidate body-related tests by declaration shape instead of by
individual diagnostic. This keeps missing bodies, external bodies,
augmentation completion, and already-complete checks side by side,
making the interaction between these rules easier to review and extend.

Move the constructorAlreadyComplete coverage from its dedicated test
file into constructor_body_test.dart, and add the factory body
completeness cases there as well. Add executable_body_test.dart for
function and member body coverage, including top-level declarations,
static members, extension members, and extension type members.

Add diagnostic definitions and fix-status entries for the new
diagnostics.

Change-Id: I9ee803c1e767ff47a608c86413ef7ffc71518cfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503540
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-05-14 15:08:39 -07:00
Brian Wilkerson a667cde7c1 Add a fix for initialize_in_field_declaration
The correction producer implements a fix. Pending discussion we might
choose to extend it to produce an assist, either in addition to the fix
(if we keep the lint) or instead of a fix (if we drop the lint).
Whatever we choose, I'd like to do that in a separate CL because I want
this to be available for testing purposes as soon as possible.

Change-Id: Icdd17ba0130149fc785c196be69e9ef990529800
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503520
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-14 12:11:59 -07:00
FMorschel 058b623fb7 [analyzer] Adds warning for missng await in return in try block
Bug: https://github.com/dart-lang/sdk/issues/62555
Change-Id: Ic152d89e94739aefd79f71972691722d4cdd0946
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486920
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Auto-Submit: FMorschel <git@fmorschel.dev>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-05-14 10:23:47 -07:00
Danny Tuppeny 4afd2e10be [analysis_server] Normalize URIs before normalizing paths in the session log
The session log normalizer replaces known paths/URIs in JSON but doesn't take into account different URI encoding between the client and the server. For example VS Code will encode ampersands whereas Dart does not:

```
file:///c:/uri&encoding&quirks
file:///c:/uri%26encoding%26quirks
```

This means not all file URIs are correctly normalized.

Adding additional groups for each potentially-encoded characters make the regex many times slower (the benchmark test here goes from around 25ms to over 1s per iteration), so instead this change has the normalizer accept the original JSON map and uses jsonEncode()s `toEncodable` option to normalize any URIs (by converting them to their file paths and then encoding using Dart's Uri class) so they will always be consistent before the replacement.

(I tried doing the replacement also in `toEncodable`, but invoking the regex many times also slowed things down a lot).

There is a small time increase (2-3ms) for a payload of 2MB. The "before" times quoted here are slightly higher than previously quoted, but that's because `jsonEncode()` was previously done inside `SessionLoggerFileSink` (and therefore excluded from the timings before), but is now done inside the normalizer to allow normalizing the URI escaping.

Replacing 250 paths in payload of 2097152 bytes
Iteration #1, First: 57ms, Rest: 40ms
Iteration #2, First: 49ms, Rest: 41ms
Iteration #3, First: 45ms, Rest: 41ms
Iteration #4, First: 47ms, Rest: 40ms
Iteration #5, First: 40ms, Rest: 40ms

Replacing 250 paths in payload of 2097152 bytes
Iteration #1, First: 59ms, Rest: 43ms
Iteration #2, First: 53ms, Rest: 44ms
Iteration #3, First: 52ms, Rest: 44ms
Iteration #4, First: 49ms, Rest: 43ms
Iteration #5, First: 49ms, Rest: 43ms

Fixes https://github.com/dart-lang/sdk/issues/63331

Change-Id: Ice2dc7ceceaa6c08e2ff634d7564efe9f0f7de44
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502940
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
2026-05-13 14:02:03 -07:00
Konstantin Shcheglov a33c0ccf84 Augment. Report constructorAlreadyComplete and functionAlreadyComplete.
Change-Id: I020a1c244b1ba31e040806103ccd83e0da851263
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502185
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-13 09:48:20 -07:00
Sam Rawlins 6fdfcc7ed4 DAS: Use correct nullability in add_return_type
Fixes https://github.com/dart-lang/sdk/issues/54865

The nullability of return types of async and generator functions is not
based on the nullability of the returned or yielded values.

Change-Id: Ieae534dbf64135129b9891b7db047f5617401021
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501121
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-05-13 08:35:17 -07:00
Helin Shiah 405b6c5614 Send IDE and plugin info to analytics
Bug: https://github.com/dart-lang/sdk/issues/62996
Change-Id: Id2bd122acf4a40a01a7dc760e44f164b04f204ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497123
Commit-Queue: Helin Shiah <helinx@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-05-12 12:39:44 -07:00
Danny Tuppeny 26c646642d [analysis_server] Add kinds to LSP document highlights
Populates the `kind` on the Document Highlights we return. This allows colouring reads and writes differently (which it turns out VS Code does by default).

The options are a bit limited (Read/Write/Text) and using Read/Write for things like type names feels slightly odd, but the spec does seem to encourage this and it's what TypeScript is doing.

Fixes https://github.com/dart-lang/sdk/issues/62929

Change-Id: I6a53450038cde31b399b5b1aca5f964083106763
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503060
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Keerti Parthasarathy <keertip@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
2026-05-12 12:04:29 -07:00
Brian Wilkerson 2b1ed6614e Add a fix for use_declaring_parameters
This is another step toward being able to maximally convert a body of
code to using the primary_constructors features.

This CL does two things:

- Changes `convert_to_declaring_parameter` to also be a fix and applies
  that fix to the `use_declaring_parameters` lint.

- Updated the `use_declaring_parameters` lint to also flag field formal
  parameters.

Change-Id: I8b584186658abc73c025b166c145efbab95acd8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502740
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-12 11:56:25 -07:00
Kallen Tu 509caefa07 [migrate] Update error message when failing to parse pubspec.
Danny mentioned that the error message is missing the file name because
we're using the directory path. Updated the message and added a small
test.
https://dart-review.googlesource.com/c/sdk/+/496801/comment/d1e2d8cf_83c52831/

Bug: https://github.com/dart-lang/sdk/issues/63247
Change-Id: I6bc7cbd18a70328cd0c549672459944c220b177a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2026-05-12 11:49:26 -07:00
Brian Wilkerson 2fa07c6488 Lint fields initialized in the initializer list instead of the field initializer
This CL adds a lint as part of the collection of lints used to automate
converting code to use the features under the primary constructors flag.
The lint flags initializers in a primary constructor body that
initialize a field in such a way that the initialization could be done
in the field declaration's initializer.

It only flags assignments to fields where the right-hand side of the
assignment includes a reference to one or more of the constructor's
parameters. Expressions that don't reference a parameter would have
been valid to move before primary constructors, so flagging them
wouldn't help find bugs in the impementation of the feature.

If we were going to ship this lint, then we might want to extend it to
find initializers that don't reference parameters, whether they are in
the primary constructor body's initializer list or in the initializer
list of a secondary constructor.

This doesn't include a fix. Once again, I wanted to make sure the lint
was covering all the important cases before implementing the lint.

Change-Id: Id4b1e02ec160af50af8f4fe7b8c675213e41abc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502202
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-12 10:47:20 -07:00
Brian Wilkerson d60a248196 Add a fix for empty_container_bodies
The fix replaces the empty braces with a semicolon.

Change-Id: Iadf423c1a3c08be2e67556ed9a33203238eb19a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502802
Reviewed-by: Keerti Parthasarathy <keertip@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-12 00:24:48 -07:00
Konstantin Shcheglov 6d6b2ae57f Augment. Report augmentationReturnTypeMismatch.
Add a compile-time diagnostic for augmentations that declare an explicit
return type different from the introductory declaration. Check top-level
functions, methods, and getters by comparing the augmentation annotation
against the introductory element return type using normal type equality.

Keep executable element return types initialized from the first fragment
only, so later augmentation fragments cannot overwrite the introductory
signature before validation. This also keeps synthetic getter/setter
variables based on the introductory declaration.

Change-Id: I08d55497e235ed2619a6915e0060bd5d8c8a45b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502200
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-09 11:44:34 -07:00
Konstantin Shcheglov d5ac7d4a57 AD. Use OwnedFiles to scope searches.
Use the collection-wide OwnedFiles map as the single source of truth for
deciding which analysis driver should process each file during search.
This replaces the per-query SearchEngineCache and SearchedFiles
ownership tracking with ownership recorded as files are discovered.

Store file paths, rather than URIs, in the analysis index so that
indexed element and subtype identifiers use the same File resources that
OwnedFiles tracks. Skip non-file sources when building or querying these
identifiers.

This lets search operations discover available files up front and then
search only files owned by the current driver. It avoids duplicate work
and duplicate results across drivers while keeping search ownership
consistent for references, subtypes, member declarations, top-level
declarations, and workspace symbols.

Bug: https://github.com/dart-lang/sdk/issues/63276
Bug: https://github.com/dart-lang/sdk/issues/63310
Change-Id: I27feed534cb84f52bffbd4da0c53e5c669910b1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-05-08 17:27:21 -07:00
Brian Wilkerson f7c06eb180 Add a new lint to find container bodies that could be a semicolon
The purpose of this lint is to be used with other lints to maximally
convert code to using the new features introduced by the primary
contructors feature. This one is targeted at finding container bodies
the could be replaced by a semicolon.

This CL does not include a fix. That will be added in a separate CL.

We will need to decide whether this lint is worth supporting beyond
the testing period.

Change-Id: I5d2d05117c9f1efc8c71279d5cde549eb48b480c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502182
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2026-05-08 13:55:19 -07:00
Brian Wilkerson 157baccaa5 Add a fix for use_primary_constructors
The use_primary_constructors lint is a temporary lint being used (along
with others) for testing the primary constructors feature. I don't
expect that it will ship to users in its current form, so these fixes
might be removed.

With that in mind, I updated the existing assist that can convert a
secondary constructor to a primary constructor so that it can be used
as a fix. (The assist will remain, even if the lint is removed.) I then
added a second fix to add a primary constructor when there are no
explicit constructors. I did this for two reasons:

1. I expect the fix to be removed before the feature is shipped because
   it seems unlikely that users would want to have an explicit primary
   constructor rather than the implicit default constructor.

2. Making it a separate lint allows it to have a better label on the
   context menu in case users actually see it during the beta period
   (or in the stable version if I'm wrong about #1.

The effect is that the lint can now be bulk fixed in order to maximally
convert a body of code.

Change-Id: I7c6dddd8735e67bbd1d398e4035ca578725d044f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502180
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-05-08 12:51:13 -07:00
Sam Rawlins 9bcf11f97e DAS: Do not lose comments in sort_child_property_last
Work towards https://github.com/dart-lang/sdk/issues/55662

There are several issues reported there. This CL fixes an issue of
comments being deleted, if they follow the comma of the `child` argument
and the `child` argument is the first argument.

Change-Id: Ic7cc0c653e9303ba7dbd2bf31dbdc50268f6a1c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501740
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-05-08 08:08:00 -07:00
Brian Wilkerson bec664e1e8 Add a lint to convert normal parameters to declaring parameters
This is another lint intended primarily for testing. It is intended to
flag every non-declaring formal parameter in a primary constructor that
could be converted to be a declaring parameter.

There is an existing assist to convert a non-declaring parameter to a
declaring parameter, but I want to make sure that this lint is catching
all of the right conditions before enhancing it to be a fix.

Change-Id: I10f8a4980bbc77d35a920a221ef26957f96d22d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501580
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-05-07 13:58:35 -07:00
Konstantin Shcheglov 1309dffc0a CQ. Move analyzer diagnostics back into analyzer.
Move the analyzer-only Diagnostic, DiagnosticMessage, Severity, and
locatable diagnostic helper types out of _fe_analyzer_shared and into
package:analyzer.

I paln to make changes outlined in
https://github.com/dart-lang/sdk/issues/63311 and chat discussion.
Keeping these classes in the analyzer simplifies the migration and
avoids introducing a shared abstraction before there is a concrete need
for one.

If we decide later need to have a shared abstraction, we can always
extract one at that point. With coding agents internal code motion is
cheap.

Update analyzer, analysis server plugin, analyzer plugin, linter, and
scanner call sites to import the moved APIs from analyzer libraries, and
refresh API baselines to reflect the new public owner.

Change-Id: Ie0ef0f01c6e4be7ebaac25619ac3e3fe991a44d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501000
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-05-07 13:54:59 -07:00