Commit Graph

4523 Commits

Author SHA1 Message Date
Konstantin Shcheglov 796147c4e8 DeCo. Finish verifySuperFormalParameters() migration.
Change-Id: Ifd2f9d8c92b6c081e3dbaa5be8df76346831688e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472661
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-01-13 14:06:41 -08:00
Konstantin Shcheglov 9fd938f558 DeCo. Report constConstructorWithMixinWithField and constConstructorWithNonConstSuper.
Change-Id: I6f9b6281aca31f59a0b407637d54a304fe5056b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472442
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-01-13 09:45:43 -08:00
Konstantin Shcheglov 98d0db74e8 CQ. Use tryCast() instead of ifTypeOrNull().
Change-Id: I2a13f6b3a56c045cc35944360bc5a76894acf03f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472480
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-01-13 09:41:53 -08:00
Paul Berry 863d0a5bb0 [messages] Remove duplicate report of awaitInWrongContext.
This diagnostic is already reported by the parser. It doesn't need to
be reported by the `ErrorVerifier`.

Change-Id: I6a6a69643fe327ca43a289d46a2f73a1571422f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472040
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-13 09:35:43 -08:00
Sam Rawlins 6e1ee45164 analyzer: Remove dead code
From a generous dead-code report at https://github.com/dart-lang/sdk/issues/51704.

Change-Id: Ie7bcf96c832d5443d523d937c7a83d30b23b5d7b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472420
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-01-12 13:37:24 -08:00
Konstantin Shcheglov 3560719250 DeCo. Check implicitly invoked unnamed super constructor.
Change-Id: I18d34ef524c5771e209c9f0c461820e50a850c4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472100
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-01-12 11:04:03 -08:00
Paul Berry b8f4042327 [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a696467d5dd49e7b44e9fc9000af67504f71c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471762
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-12 08:33:10 -08:00
Paul Berry 1a3b42e4bf [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a6964bd3211ce15e9b7d96eb98e30d94e9cc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471922
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-09 21:53:15 -08:00
Paul Berry bdecb496bc [messages] Use literate API in _reportUnresolvedIndex.
Changes the method `PropertyElementResolver._reportUnresolvedIndex` to
use the literate diagnostic reporting API.

Change-Id: I6a6a6964a88f66afb65ae900bc028d24d4c265c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471921
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 21:46:33 -08:00
Paul Berry c365318574 [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a696493d545d721d88cb436dba69bd772c21c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471902
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 21:45:12 -08:00
Paul Berry ba4e751dcb [messages] Use literate API for undefined getter/enum constant.
Changes the analyzer code that reports the following errors to use the
literate diagnostic reporting API:

- `undefinedEnumConstant`.
- `undefinedGetter`.

In the process I've cleaned up the type of the second argument (now
called `type`). Previously, some call sites passed in a type and
others passed in a string; now all call sites pass in a type.

Change-Id: I6a6a6964ebeb31ee388432242374df288c896350
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471892
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-09 15:49:29 -08:00
Paul Berry 994c0ca9de [messages] Use literate API for undefinedConstructorInInitializerDefault.
Converts all analyzer logic that reports the error
`undefinedConstructorInInitializerDefault` to use the literate
diagnostic reporting API.

Previously, one of the call sites passed in a `String` for the
argument, and the other call site passed in a `DartType`. To improve
type safety, I've converted the error to always expect a `String`.

Change-Id: I6a6a69646678a9a0de8f252908eb0b2f6db56854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471920
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 15:48:50 -08:00
Paul Berry 46d21697b8 [messages] Use literate API in _checkDirectSuperTypeNode.
Changes the method `_ClassVerifier._checkDirectSuperTypeNode` to use
the literate diagnostic reporting API.

Also removes the `DiagnosticCode` parameter from
`ErrorVerifier._checkForExtendsOrImplementsDisallowedClass`, which was
not used.

Change-Id: I6a6a696491f4d87d019bd1435f555da1835e7a28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471887
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 15:33:22 -08:00
Paul Berry 2740bcb88c [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a6964f4240aa3dafdd7535fdf387143d7e8be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471900
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-09 15:32:43 -08:00
Paul Berry 46e2987b0f [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a6964f37eb51e19869171c9fde662e916f573
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471883
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 15:25:19 -08:00
Paul Berry ba3b1ca9cc [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a696472b2c2edc6a90a3068ac506980a6aa30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471581
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 13:22:01 -08:00
Paul Berry 9f676fad61 [messages] Use literate API for TopLevelInferenceError.
Changes all uses of the analyzer's `TopLevelInferenceError` class to
use the literate diagnostic reporting API. To preserve the type safety
guarantees that the literate API provides, I reworked the
`TopLevelInferenceError` class so that it is a sealed class hierarchy,
with each subclass containing a field of the appropriate argument
type.

I also removed the enum value `TopLevelInferenceErrorKind.none`, which
was not used (the lack of a top level inference error is represented
by `null` rather than this enum value).

Change-Id: I6a6a6964c1a39bd700d5fc00e5a782585d63a73f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471864
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-09 11:26:59 -08:00
Paul Berry 2e750b92bb [messages] Use literate API in _reportNotEnoughPositionalArguments.
Changes the method
`ResolverVisitor._reportNotEnoughPositionalArguments` to use the
literate diagnostic reporting API.

Change-Id: I6a6a6964418f5eefa45a05f5995927b3220d4f17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471800
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 11:09:34 -08:00
Paul Berry 7bca8a30c3 [messages] Use literate API for checkForNonBoolExpression.
Changes the method `BoolExpressionVerifier.checkForNonBoolExpression`
to use the literate diagnostic reporting API.

Change-Id: I6a6a6964cb421319bf6d45e6cc49675bbe624ae3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471760
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 10:22:19 -08:00
Paul Berry 2209786253 [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a696471331bc9175265619206a0011959bf6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471611
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 08:14:53 -08:00
Paul Berry 5e143f0b3c [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a6964fd5560c41fa4f08a6ecae3a33d887dfd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471604
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 08:14:44 -08:00
Paul Berry 3195dd6b8f [messages] Use literate API for _checkForOutOfRange.
Changes the code in `ErrorVerifier._checkForOutOfRange` to report
errors using the literate diagnostic reporting API.

Change-Id: I6a6a6964b278ba61d094cdaf06a3c2d0b59753fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471407
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-01-09 07:58:45 -08:00
Paul Berry 4f4513cb88 [messages] Use literate API in _checkForInvalidModifierOnBody.
Changes the `ErrorVerifier._checkForInvalidModifierOnBody` method to
use the literate diagnostic reporting API.

Note that although there was a parameter to allow the caller to
specify the diagnostic code, the value passed into that parameter was
always `diag.invalidModifierOnConstructor`, so I went ahead and
inlined it.

Change-Id: I6a6a6964eeb862205a74b70c9aa541fadb8d1945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471600
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-09 07:58:37 -08:00
Konstantin Shcheglov 9a2bc9327f DeCo. Use primary initializer scope for field initializers.
Change-Id: If035464a318262270b05774c2945ce5b073e486d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471406
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-01-08 19:23:07 -08:00
Paul Berry df5b13122f [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a696445970ebc7cb0438e7d86ab08da4eed55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471582
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-08 17:06:29 -08:00
Paul Berry a6a775d441 [messages] Use literate API for mixinApplicationNoConcreteSuperInvoked errors.
Changes the analyzer logic that reports the following errors to use
the literate diagnostic API:
- mixinApplicationNoConcreteSuperInvokedMember
- mixinApplicationNoConcreteSuperInvokedSetter

Change-Id: I6a6a6964c7d457f8cae92ae2830cca95bd754558
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471606
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-08 16:11:55 -08:00
Paul Berry 5970cbd17b [messages] Use literate API to report missingDefaultValueForParameter errors.
Changes the analyzer logic that reports the following errors to use
the literate diagnostic reporting API:
- missingDefaultValueForParameter
- missingDefaultValueForParameterPositional

Change-Id: I6a6a6964db77147967d14c03e5bbbb5637565a0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471622
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 16:05:52 -08:00
Paul Berry d45d2a7986 [messages] Use literate API for _checkForRepeatedType.
Changes the method `ErrorVerifier._checkForRepeatedType` to use the
literate diagnostic reporting API.

Change-Id: I6a6a6964f46138fcdc8d20a569e9ccda4ffc4fb3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471405
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 16:03:50 -08:00
Paul Berry fd33bca7ed [_fe_analyzer_shared] Change return type of shared analysis methods.
The return types of the following methods are changed to
`ExpressionTypeAnalysisResult`:

- `NullShortingMixin.finishNullShorting` (previously returned
  `SharedTypeView`).

- `NullShortingMixin.handleNullShortingStep` (previously returned
  `void`).

- `TypeAnalysisNullShortingInterface.finishNullShorting` (previously
  returned `SharedTypeView`).

- `TypeAnalyzer.analyzeExpression` (previously returned
  `SharedTypeView`).

With one exception, these methods previously returned a
`SharedTypeView` representing the expression's static type. (The
exception was `NullShortingMixin.handleNullShortingStep`, which
previously returned `void`).

This paves the way for allowing these methods to return additional
information beyond the static type of the expression, such as flow
analysis results and tree rewrite information. (This information is
currently carried around in auxiliary data structures, which leads to
bookkeeping headaches and increases the risk of bugs.)

Change-Id: I6a6a6964572a5fd7fac5496cdbfbc82a10272bba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471323
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 14:40:52 -08:00
Paul Berry 28e0678026 [messages] Use literate API for extraPositionalArguments errors.
Converts the analyzer code that reports the errors
`extraPositionalArguments` and `extraPositionalArgumentsCouldBeNamed`
to use the literate diagnostic reporting API.

Change-Id: I6a6a6964e8d83f460c8ecb95c4a85920d189a211
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471580
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 14:06:20 -08:00
Paul Berry d7782b8909 [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a6964a03b0adf56bde690957bdbe2bf96743a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471520
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-08 10:34:59 -08:00
Konstantin Shcheglov e2086ed690 DeCo. Use FormalParameterElementImpl(s) in executableDeclaration_enter().
Change-Id: I9a87d8b0ab4eaf63595973fec403b4ed7ebe0397
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471345
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-01-08 10:27:49 -08:00
Paul Berry 4941503947 [messages] Convert uses of atConstructorDeclaration to literate diagnostic API.
Converts all the calls to
`DiagnosticReporter.atConstructorDeclaration` to use the new literate
diagnostic reporting API.

This change had to be done manually because there is no
`atConstructorDeclaration` method in the new API; instead, the
extension method `ConstructorDeclarationExtension.errorRange` is used.

Change-Id: I6a6a696455c1897bc6b079735266cf80e12458ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471540
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 10:21:31 -08:00
Paul Berry f3953a0d3b [messages] Migrate diagnostic_factory.dart to literate diagnostic reporting.
Also, reworks the error reporting logic in `diagnostic_factory.dart`
to use the analyzer's literate diagnostic reporting API.

This required giving parameter names to the following diagnostic messages:

- duplicatePatternAssignmentVariable
- duplicatePatternField
- referencedBeforeDeclaration

Change-Id: I6a6a6964b53b6571e992702ffb622fc7791f6ee2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471303
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 09:45:23 -08:00
Paul Berry 6f6bc2f5f6 [messages] Convert _checkForUnnecessaryNullAware to literate diagnostic API.
Converts all the diagnostic reporting logic in
`ErrorVerifier._checkForUnnecessaryNullAware` to use the new literate
diagnostic reporting API.

This required a nontrivial rewrite of
`ErrorVerifier._checkForUnnecessaryNullAware`, because the previous
version had some nontrivial interleaving of the logic that computes
the `DiagnosticCode` to report, and the logic that computes the
`List<Object>` of arguments to pass to it. It wasn't possible to
trivially convert this to the more type-safe literate diagnostic API
without untangling it first.

I believe the new version is more straightforward and easier to read,
because:

- In the old version, the logic for deciding which diagnostic to
  report was based in part on the kind of null-aware operator, and in
  part on an enum value passed in by the caller. In the new version,
  it's almost entirely based on an enum passed in by the caller
  (except that the choice between `invalidNullAwareOperator` and
  `invalidNullAwareOperatorAfterShortCircuit` is made at the last
  minute, because it depends on whether short-circuiting is in
  effect).

- All the logic for choosing the `DiagnosticCode` and the arguments to
  apply to it is now in one place
  (`_NullAwareKind.locatableDiagnostic`), so it's easy for the reader
  (and the compiler) to verify that the diagnostic code and its
  arguments are properly matched up.

- In the old version, the role of deciding whether the expression in
  question was null-aware (and thus needs an "unnecessary null aware"
  check) was split between the caller and
  `_checkForUnnecessaryNullAware`. In the new version,
  `_checkForUnnecessaryNullAware` is only called when the expression
  is truly null-aware.

- In the old version, there were three separate calls to
  `diagnosticReporter`: one to handle static member accesses, one to
  handle short-circuiting, and one to handle all other cases; one of
  these three made use of the helper function
  `DiagnosticFactory.invalidNullAwareAfterShortCircuit`, making the
  calls look quite different even though their behavior was quite
  similar. In the new version, all the logic funnels into a single
  call to `diagnosticReporter`.

Change-Id: I6a6a6964b75016ae5f92a86c176c066c41542445
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471027
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 09:44:40 -08:00
Paul Berry 1cde280830 [flow analysis] Streamline starting of null-aware cascades.
Changes the behavior of `FlowAnalysis.cascadeExpression_afterTarget`
so that if the cascade is null-aware, flow analysis automatically
accounts for the resulting control flow split. Previously, the caller
had to account for the control flow split via a separate call to
`FlowAnalysis.nullAwareAccess_rightBegin`.

This is accomplished by extracting the implementation of
`FlowAnalysis.nullAwareAccess_rightBegin` to a private internal
method, and calling it from
`FlowAnalysis.cascadeExpression_afterTarget`.

This paves the way for a chain of follow-up CLs that will simplify how
flow analysis associates `ExpressionInfo` objects with expressions. It
makes the follow-up CL chain simpler by avoiding the need for some
complex gymnastics to carry an `ExpressionInfo` object between the
call to `FlowAnalysis.cascadeExpression_afterTarget` and a follow-up
call to `FlowAnalysis.nullAwareAccess_rightBegin`.

Note that this change creates some asymmetry, because it is still
necessary for the caller to call `FlowAnalysis.nullAwareAccess_end`
before calling `cascadeExpression_end`. I will address this in a
follow-up CL; for now I've left a TODO comment in
`_FlowAnalysisImpl.cascadeExpression_end`.

Change-Id: I6a6a696483dec4eb4770f63a05cd7c0e16443ae4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471341
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-08 08:08:51 -08:00
Sam Rawlins 745112cc0b analyzer: Simplify API of AnalysisOptionsMap to look like a Map
The main bit of this change is to change `add` to `operator []=` and
`getOptions` to `operator []`.

`firstOrDefault` is unused, `forEachOptionsObject` can be replaced with
a for-loop over the options values, and `get _allOptions` can be folded into `get options`.

I also removed all of the "this API is experimental and subject to change" as I think that ship has sailed.

Change-Id: Id9ebe21f35dbad822fa71a5f987b8cf0885c29d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471326
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-01-07 15:49:29 -08:00
Paul Berry 52e230c242 [analyzer] Resolve rewritten invocations earlier.
Changes the resolution logic that rewrites `DotShorthandInvocation` or
`MethodInvocation` into `DotShorthandConstructorInvocation` or
`FunctionExpressionInvocation`, so that it the newly created
expression objects are resolved immediately (by calling
`InstanceCreationExpressionResolver.resolveDotShorthand` or
`FunctionExpressionInvocationResolver.resolve`). Previously the
resolution of these new objects was deferred several layers up the
call stack, to `ResolverVisitor.visitDotShorthandInvocation` or
`ResolverVisitor.visitMethodInvocation`.

This reduces bookkeeping, allowing many resolution methods to return
`void` that previously returned the rewritten expression object. It
also makes resolution logic easier to reason about, by changing the
behavior of methods like `MethodInvocationResolver.resolve` and
`ElementResolver.visitMethodInvocation` so that they always fully
resolve the node they are acting upon (previously they only fully
resolved the node if it was not rewritten).

Note that a few methods still return the rewritten node
:
- `MethodInvocationResolver._resolveReceiverTypeLiteralForDotShorthand`
- `MethodInvocationResolver._rewriteAsFunctionExpressionInvocation`
- `MethodInvocationResolver.resolveDotShorthand`
- `ElementResolver.visitDotShorthandInvocation`

This is necessary because there is some logic in
`ResolverVisitor.visitDotShorthandInvocation` that is skipped if the
node is rewritten into a `DotShorthandConstructorInvocation`. I'm not
certain why this logic needs to be skipped. I will investigate this
and do additional clean-up in a future CL. For now I've left a TODO
comment.

Change-Id: I6a6a6964fbc8dab2d3f3d86c780a7659717ab076
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469480
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-07 14:56:09 -08:00
Konstantin Shcheglov 8be9f9fa3b PrNP. Use element model to report diag.privateNamedNonFieldParameter
Change-Id: If7790d834ad1d6ae15f03112bab516bff249e79c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470943
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-01-06 14:55:55 -08:00
Konstantin Shcheglov 60f870baae PrNP. Move reporting errors to analyzer/ and front_end/.
This simplifies reporting logic by avoiding "already reported by the
parser" case. Also, in a follow up CL I plan to support declaring formal
parameters, which do not look as `this._foo` syntax. Supporting this in
the parser would require duplicating more complex logic of building
elements in the analyzer.

Another way to think about it, is that from parser point of view the
code is fine - we did not skip or add any tokens. We can parse and
format this code. But the semantics is not quite right, so it makes
sense to put it in a different place.

Change-Id: I783ed6780e6d66e276c5ed44f08e6ac04145cd1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470920
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-01-06 11:30:01 -08:00
Paul Berry 658b656941 [messages] Clean up constWithUndefinedConstructor diagnostic.
This diagnostic is reported in two circumstances:

- During resolution of a dot shorthand like `const .foo()`, when the
  implicitly-referred to class doesn't have a constructor with the
  given name.

- During resolution of a const constructor invocation like `const
  int.foo()`, when the explicitly-referred to class (`int` in this
  example) doesn't have a constructor with the given name.

In both cases, the diagnostic message includes the names of both the
class and the constructor that was sought. But in the first case, the
class name was accidentally derived from the type inference context
rather than the dot shorthand context; these are different in the case
where the dot shorthand appears on the RHS of `==`. Fixed by supplying
the correct context type.

This bug was discovered in the process of converting the analyzer to
use the new literate error reporting mechanism: I needed to assign a
type to the diagnostic message parameter that was to contain the class
name and discovered that I couldn't give a consistent type, because it
was sometimes being filled in with a class name string, and it was
sometimes being filled in with a type. With the fix, it is always
filled in with a class name string.

I also included tests of the other dot shorthand related diagnostics
that mention the class name (they don't exhibit the same bug), as well
as a typo fix for `wrongNumberOfTypeArgumentsDotShorthandConstructor`
(which had mismatched quote symbols).

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

Change-Id: I6a6a696421b68397b86aac9b1a6e91cce08250ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470942
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-06 11:14:50 -08:00
Paul Berry f4dfbbe4a4 [messages] Convert more diagnostics to literate diagnostic reporting API.
The only changes in this CL that were manually written are those in
`messages.yaml`. The others were produced by running the standard
diagnostic message code generator and then running the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a69645bab7cf8f26ec9524a7bc2294e4a3b3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471020
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-01-06 10:16:24 -08:00
Paul Berry 33d7b34d6e [messages] Convert uses of atElement2 in error_verifier.dart.
Changes the uses of `DiagnosticReporter.atElement2` in
`inheritance_override.dart` to use the new literate diagnostic
reporting mechanism.

Change-Id: I6a6a6964b4585d173bbdf2918b3ec1c9e27503fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470804
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-01-06 05:54:31 -08:00
Paul Berry 8f3a678dce [messages] Convert more uses of atElement2.
Changes the uses of `DiagnosticReporter.atElement2` in
`evaluation.dart`, `base_or_final_type_verifier.dart`, and
`getter_setter_types_verifier.dart` to use the new literate diagnostic
reporting mechanism.

Change-Id: I6a6a6964cff8afd9867c2606f3aea334f135cf03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470820
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2026-01-06 05:54:20 -08:00
Paul Berry a1cf5d8d0d [messages] Convert some more analyzer diagnostic reporting logic.
These changes were produced automatically by the script
`use_literate_api_in_analyzer.dart`.

Change-Id: I6a6a696455cd0a49533eb5e69cc99773c602bea4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470780
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-05 13:38:42 -08:00
Fedor Shcheglov 09dcc24207 Test that primary constructors can initilaize fields
Change-Id: Ia43d8c44c9b695f823fd80087dfd08efd47367e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470480
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-01-05 10:46:02 -08:00
Fedor Shcheglov df5701473c Make sure a primary constructor body without a declaration doesn't result in a crash.
Change-Id: If441900bf5bd9556c2f51caa8a477c59f81094b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470460
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-01-02 20:53:42 -08:00
Fedor Shcheglov d36d50a95c Report primaryConstructorBodyWithoutDeclaration.
Change-Id: I14e76e514f1aeee2a171784b778d8f8747a3dada
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/470200
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2026-01-01 12:14:25 -08:00
Konstantin Shcheglov 6caef97f21 DeCo. Support for PrimaryConstructorBodyImpl.
- Add `PrimaryParameterScope`.
- Add `thisKeywordOffset`.
- Store body metadata and initializers into `ConstructorElement`.
- Resolve.

Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: Ifc7b408cfddb1d83e325ab654fa25f072459e3c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469960
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-12-30 12:14:24 -08:00
Fedor Shcheglov bf5cfaedd9 Renamed variables, formal parameters, and declared identifiers that were incorrectly named elements, when they had a fragment type.
Change-Id: Id201a1f319ee2ae1e328c1d551a98df97bdc2b5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469640
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-12-29 18:04:29 -08:00