Commit Graph

14356 Commits

Author SHA1 Message Date
Konstantin Shcheglov fffd7cf17b Issue 56118. Add DartObject.toTypeValueNotExtensionTypeErased() as experimental.
Bug: https://github.com/dart-lang/sdk/issues/56118
Change-Id: Iab31aec4737267e03fff7435bd92c3226c9f1744
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488060
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2026-04-26 11:29:19 -07:00
Erik Ernst 3809c0f559 Introduce error for super in parameterless anonymous method
It is a compile-time error for `super` to be used in any way when in the
body of a parameterless anonymous method. This CL adds these error
messages to the analyzer.

It introduces a new `SuperContext` in order to maintain proper knowledge
about the situation when it is detected, but it uses a rather generic
error message (just saying that the context is wrong) following the
rationale that this is sufficient for occurrences of `super` in static
members, constructors, top-level declarations, and more.

Change-Id: I4552be0983e4d64a6e59fd03521cbe4f5c784f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498040
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2026-04-25 01:05:42 -07:00
Konstantin Shcheglov e86cdad403 Issue 63206. Use MissingRequiredSdkClassException to report from TypeProviderImpl.
Bug: https://github.com/dart-lang/sdk/issues/63206
Bug: https://github.com/dart-lang/sdk/issues/63224
Change-Id: I8c9b78e3f5829099ff4d23a745770f67ca61ba8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497180
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-24 12:21:51 -07:00
Sam Rawlins e9371b188c analyzer: unused_element: Check for overridden elements accessed in extension
Fixes https://github.com/dart-lang/sdk/issues/62198

Change-Id: I4506ccf7b7910e3ac257e846e08acad8fff7ac79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497740
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-24 11:30:00 -07:00
Kallen Tu 77cf3047a3 Dot Shorthands: Const selector chains.
I changed the parsing of const dot shorthands to parse the entire selector chain in `parsePrecedenceExpression` rather than parsing them in `parseConstExpression`. We were originally parsing the initial expression before the `.` and only flagging that as a dot shorthand which prevented any chaining on const constructors. Const expressions with chained methods/property accesses were not being flagged as a dot shorthand so we weren’t saving the context type properly which led to producing the “unknown context type” error.

Before:
```
class C {
  const new someConstCtor();
  C method() => this;
}

C c = const .someConstCtor.method();
// (const .someConstCtor) is parsed and handled as a const constructor
// (const .someConstCtor) is handled as a dot shorthand, context is
// saved on only this AST and not the outer chain.
// Then we parse the rest of the selector chain (.method())
//
// Error: No context type for (const .someConstCtor.method())
```

After:
```
class C {
  const new someConstCtor();
  C method() => this;
}

C c = const .someConstCtor.method();
// (const .someConstCtor) is parsed and handled as a const constructor.
// Then we parse the rest of the selector chain (.method())
// (const .someConstCtor.method()) is handled as a dot shorthand, context is saved for this outer node.
//
// OK. No error because we are able to retrieve the type for the
// entire dot shorthand chain.
```

Fixes: https://github.com/dart-lang/sdk/issues/63119
Change-Id: I3308d8eb7ce101466be257aba6b5448921bff136
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
2026-04-24 10:40:26 -07:00
Konstantin Shcheglov bf0f72ae14 CQ. Refactor test type construction to use parseType().
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>
2026-04-24 09:21:11 -07:00
Modestas Valauskas e20b492000 [analyzer] Fold AdjacentStrings via StringBuffer.
`ConstantVisitor.visitAdjacentStrings` previously delegated to
`_concatenateNodes`, which folds the list pairwise and materializes
a new `DartObjectImpl` / `StringState` at every step. For an
`AdjacentStrings` with `n` string pieces of total length `L`, this
is roughly O(L^2) work and garbage.

This is pathological on generated code: parser generators and other
codegen tools commonly emit a single large string constant as a long
sequence of adjacent string literals (e.g. encoded transition tables
for a table-driven parser). In those files, constant evaluation of
a single top-level `const` dominates analyzer runtime.

Fast-path `visitAdjacentStrings`: when every element evaluates to a
plain `StringState`, append into one `StringBuffer` and return a
single final `DartObjectImpl`. Fall back to the existing
`_concatenateNodes` path only when an element is not a plain string
(diagnostic, unknown, etc.).

Wall-clock time to resolve a library containing one `const table =`
of N adjacent 16-char string pieces, on an Apple M-series laptop
with a recent main-channel SDK:

  pieces  total_chars  baseline_ms  patched_ms  speedup
    1024        16384         218         222     ~1x
    4096        65536         180         189     ~1x
   16384       262144         245         166     ~1.5x
   65536      1048576        9229         246     ~37x

At larger sizes the baseline grows quadratically while the patched
path stays linear; n=262144 took multiple minutes on the baseline
and roughly half a second after the patch.

TEST=pkg/analyzer/test/src/dart/constant/evaluation_test.dart:test_visitAdjacentInterpolation_simple

Bug: https://github.com/dart-lang/sdk/issues/63222
Change-Id: Ibffe4124d025fceb5991ea88b4af9a03f36525b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497001
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-24 00:53:43 -07:00
Sam Rawlins d8cfa31e03 analyzer: Fix unused parameter warning w.r.t. annotation invocation
Fixes https://github.com/dart-lang/sdk/issues/63229

Change-Id: Ib49d9d9cf251533be1a70053c933b53dac59ca91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497720
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-04-23 13:29:25 -07:00
Konstantin Shcheglov 4eaddd74ab CQ. Clean up buildLibrariesFromSpec() and its clients.
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>
2026-04-22 14:39:26 -07:00
Sam Rawlins 0706afa1ef Introduce an 'analysis options page' in the insights pages.
Work towards https://github.com/dart-lang/sdk/issues/61496

This adds some "debug information" types and a method on
AnalysisOptionsImpl, so that the data can be shared into different
debug systems. Another one I'd like to implement is a command-line
view, as per https://github.com/dart-lang/sdk/issues/61496.

There is much code shared between the Contexts page and the Analysis
options page, so that goes into diagnostics.dart.

Change-Id: I054bd19ed2ca54c4b3d7d6898eba3a968c8ca209
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-04-22 13:57:30 -07:00
Konstantin Shcheglov 9d75d4db0d DeCo. Issue 63214. Add new tests for primary constructors and warnings.
Bug: https://github.com/dart-lang/sdk/issues/63214
Change-Id: I2054315eaddc87e0370f82ca8d2a1ebf140d4d18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497140
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-22 10:35:24 -07:00
Jens Johansen ff5858a2a1 [CFE] Set proper endOffset on constructor from primary constructor
If nothing else it's needed for
https://github.com/dart-lang/sdk/issues/62645.

Change-Id: Ibcc4cdd292cdec0c33a24c337861e1dd54da24f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496981
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2026-04-22 01:19:02 -07:00
Sam Rawlins b1061cbd71 analyzer: Report invalid @internal annotation on primary constructors
Change-Id: I75d3f1f06a27ea0c3f4e4a6b24d9794b47c80cea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497040
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-21 13:04:25 -07:00
Konstantin Shcheglov 40dc31eed9 Elements. Remove MixinFragment.superclassConstraints
This is a breaking change, fortunately we are in the state when
analyzer 13.0.0 is not published yet.

Change-Id: Iaef69a3c6051f6d3cfe84cd66287d26a11baba2e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-21 12:42:19 -07:00
Konstantin Shcheglov 18ab2664ca Augment. Report augmentationOfMixinApplicationClass.
Change-Id: I2649f4eb96fc232727fafa16129799ef3f207e20
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-21 09:57:59 -07:00
Konstantin Shcheglov 291d8ae07d CQ. Create TypeParameterElementImpl instances in owning elements.
Create `TypeParameterElementImpl` instances when their owning elements
are constructed, instead of materializing them later in builders,
fragment linkers, and bundle reading. This makes ownership explicit in
the element model.

Update synthetic executable construction in inheritance handling to
build fresh type parameter and formal parameter elements. Top-merge and
covariance inheritance were previously able to reuse fragments from
other executables, which could attach fragments to the wrong element and
produce invalid synthetic members for generic signatures.

For type aliases, serialize the first fragment directly instead of a
fragment list. This matches how type alias elements are constructed and
avoids a separate read-time step that recreated type parameter elements.

Bump the data version for the format change.

Change-Id: If4f203f65fb11bcd0ffd1dcc0e47956b9fb2597b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496780
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-21 09:06:50 -07:00
Konstantin Shcheglov d2394cda16 CQ. Use buildLibrariesFromSpec() in type tests.
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>
2026-04-21 08:51:43 -07:00
Sam Rawlins 6abc631520 analyzer: Fix bug with operator of generic extension being marked as unused
The `addMember` API automatically handles type-substituted elements, so
adds the correct element for tracking.

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

Change-Id: Ib0c8f846bbb43afea274ea24591bd5b145a18422
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496740
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-21 06:19:30 -07:00
Erik Ernst e05ce41c0d Add anonymous => method related implementation in the CFE
This CL adds an implementation of anonymous `=>` methods in the CFE
which is sufficiently complete to handle the existing test cases in
language/anonymous_methods/expression.

Coverage is handled by adding magic comments to ignore the fact that new
code is not covered by existing testcases. This will be settled in a
separate CL.

To keep the failures visible, the failures in configurations
dart2js-hostasserts-linux-d8-try, dart2js-linux-chrome-try,
dart2js-minified-linux-d8-try, and ddc-linux-chrome-try have not been
approved. It seems likely to me that those are bugs in dart2js and in
DDC.

Change-Id: Ia70fedd4de6166d6a3bf8a108f49728b6e16c9f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494440
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-21 02:09:41 -07:00
Sam Rawlins 877ded1a38 analyzer: Tidy deferred_import_of_extension message
Fixes https://github.com/dart-lang/sdk/issues/56716

Change-Id: I9ce1ba3139a3eb388b3ceb18a898069531ccfa3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496662
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2026-04-20 11:12:05 -07:00
Konstantin Shcheglov 9e690bdd06 Augment. Report augmentationOfDifferentDeclarationKind.
Keep track of the most recent same-named fragment even when it has a
different declaration kind. This lets augmentation validation
distinguish between a missing target and a target whose kind does not
match the augmentation.

Store this information on elements, serialize it through summaries, and
use it during error verification. When an augmentation finds a previous
declaration with the same name but a different kind, report
`augmentationOfDifferentDeclarationKind` and attach a context message
that points to the original declaration instead of falling back to
`augmentationWithoutDeclaration`.

This improves diagnostics for both top-level and member declarations,
including combinations such as constructors vs fields, methods vs
accessors, and functions vs variables.

Change-Id: Ic794c437fa160bb29d25f90559b544a7282ca697
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494301
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-20 09:33:03 -07:00
Konstantin Shcheglov 47bafbeaac Augment. Create TypeParameterElement(s) eagerly when building or reading element model.
Create `TypeParameterElementImpl` instances when fragments are built or
read, instead of synthesizing them lazily from
`TypeParameterFragmentImpl.element`.

This makes fragment-to-element wiring explicit and predictable across
the element model. To support this, accesses to `typeParameters` now
ensure that resolution has been read before returning element-backed
data.

The bundle format is adjusted so that type parameter metadata remains on
fragments, while variance, bounds, and default types are serialized with
the corresponding elements. This keeps the eager element creation model
consistent when reading summaries.

As part of this cleanup, generic function types and formal parameters
now create their nested type parameter elements up front, and
declarations that cannot have type parameters stop serializing empty
type parameter lists.

Change-Id: Ifcdc05bcccd2de6ae88d8102b10efe9a144e2545
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496520
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-20 08:38:59 -07:00
Konstantin Shcheglov 7874777488 CQ. Clarify bundle reader/writer fragment helpers.
Rename the bundle read/write helpers so their names reflect whether they
operate on elements, fragments, or whole library fragments. This makes
the serialization flow easier to follow and keeps the reader and writer
structured around the same concepts.

Also extract small helpers for imports, exports, parts, type parameters,
and formal parameters, so the bundle layout is spelled out more directly
instead of being spread across larger methods.

While doing this, move import prefix `enclosingFragment` wiring into the
`libraryImports` setter on `LibraryFragmentImpl`. This keeps prefix
fragments attached consistently whether they come from the library
builder or from summary deserialization.

Change-Id: I78f66f3e8a33d6c0dbf32bf9976ed666ceb6422c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496500
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-20 08:03:14 -07:00
Konstantin Shcheglov 6cd3938741 Breaking changes for analyzer 13.0.0
https://github.com/dart-lang/sdk/issues/62799
https://github.com/dart-lang/sdk/issues/62944
https://github.com/dart-lang/sdk/issues/63002
https://github.com/dart-lang/sdk/issues/62970

Looks mostly green in google3: https://fusion2.corp.google.com/presubmit/901021300/OCL:901021300:BASE:901308428:1776439417713:37cd1695

Change-Id: I44754a48f66a0b58851d7c20fcfa61f7fb1b555a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/488624
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-17 23:06:25 -07:00
Konstantin Shcheglov 0f6a0ebad7 CQ. Replace shouldUseTypeForInitializerInference with isTypeInferredFromInitializer for property-inducing elements.
The old flag described a resolver behavior and defaulted to true, which
made persisted element data less explicit and caused many declarations
to carry the flag even when their type did not actually come from an
initializer. The new flag records the underlying fact we care about:
whether top-level inference produced the element's type from its
initializer.

Make top-level inference return both the inferred type and whether it
was derived from the initializer, and store that result on the element
when the type is computed. Use this recorded fact when choosing the
context type for initializer resolution, so only declarations whose type
was taken from the initializer fall back to `UnknownInferredType`.

Update the stored flags, manifest matching, result printers, and
serialized expectations to reflect the renamed and narrower semantics,
and bump the analysis driver data version for the format change.

Change-Id: I120f3cc289454c8ffc0963dcb028e2d5250f16da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/496220
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-17 10:08:40 -07:00
Konstantin Shcheglov da16e9a256 Augment. Set isAbstract and isCompleteDeclaration for getters / setters originating from top-level variables.
Propagate flags to top-level variable accessors

Record `isAbstract` on top-level variable fragments and copy it to the
synthetic getter and setter fragments built from those variables. Also
mark those accessors as complete declarations when the originating
variable is external or not abstract. o later linking and element model
expectations stay consistent.

Change-Id: I36edfab18feaa2e2d9f8dca20dad837bd82f0836
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495943
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-17 09:26:32 -07:00
Konstantin Shcheglov 91af82981b CQ. Write element and fragment flags using generated flagsForTesting.
Replace the hand-written header flag formatting for elements and
fragments with writeHeaderFlags(...flagsForTesting). This makes the
printed output come from the same generated flag definitions as the
element model instead of maintaining separate lists of writeIf calls.

Mark computed element flags such as hasDefaultValue, hasInitializer, and
hasNonFinalField in the generated metadata, and add the missing
generated overrides needed to expose them through flagsForTesting. This
also lets the shared path report flags such as isSimplyBounded and
hasEnclosingTypeParameterReference consistently.

Because hasNonFinalField now needs to round-trip through bundles for
enums, update the bundle reader and writer and bump the data version.

Change-Id: I7c126fe4bc69fd6b191f339ddc420b05cd8b5ee7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495860
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-16 10:46:43 -07:00
Konstantin Shcheglov 6f9d551aba Elements. Generate: Map<String, bool> get flagsForTesting
So, that we can replace manual writing of flags in output with
these generated, always up-to-date maps.

Change-Id: I4a0528267e03885e5224f41c04e1c85b1a32d4ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495823
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-16 10:23:09 -07:00
Konstantin Shcheglov 9a87685ed9 Elements. Enforce that flag enums are sorted.
Change-Id: Ia8f2baafb0b43a702fe499e19a7d165181687f0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495822
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-16 09:58:23 -07:00
Konstantin Shcheglov 950f644a08 CQ. Remove 'genericClass' and related from GenericInferrer.
It is never provided.

Change-Id: Ibba893353afde7aec23184c032a321d1784fe6c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495820
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-16 09:20:43 -07:00
Srujan Gaddam 09adfce801 [linter] Fix JS annotation check in invalid_runtime_check_with_js_interop_types
Fixes https://github.com/dart-lang/sdk/issues/63173

hasJS now checks both dart:_js_annotations and dart:js_interop so check
only for dart:_js_annotations to restore the original intent of the
check.

Linter tests did not fail before because the mock SDK did not have the
equivalent @JS renames as the real js_interop.dart, so the hasJS check
reported the same answer as before and after its semantic change. With
the change in the mock SDK, multiple tests would now correctly fail
without the change in the lint rule to not use hasJS.

Change-Id: I79c5fbb35f0d868f932aa5ed42e484ea725debbe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495787
Reviewed-by: Nate Biggs <natebiggs@google.com>
Auto-Submit: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Nate Biggs <natebiggs@google.com>
2026-04-16 08:08:14 -07:00
Sam Rawlins a4f9d7b726 analyzer plugins: Support git plugins
Fixes https://github.com/dart-lang/sdk/issues/61794

This adds support for all of the fields specified in pubspecs: https://dart.dev/tools/pub/dependencies#git-packages

It's fairly dumb support, without much validation, because the YAML is more-or-less dumped wholesale into the generated pubspec; the values are not used for anything else.

Change-Id: Iec36c1c37ffb6f65665fb7f08faf237dc4474f26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495789
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-16 08:00:01 -07:00
Ivan Inozemtsev 437b17b1d5 Revert "CQ. Use Uri for checking _isConstructor() or _isTopGetter()."
This reverts commit 909f1f0044.

Reason for revert: b/503248215

Original change's description:
> CQ. Use Uri for checking _isConstructor() or _isTopGetter().
>
> Change-Id: Idf25747182eb0beb7d44fdf768cb64ec8ff67f57
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495680
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Paul Berry <paulberry@google.com>
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: Iec05d539fa7510654aa6bc006333f04aa1afec81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495882
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
2026-04-16 03:34:16 -07:00
Johnni Winther 5b0def4a87 [parser][Augmentations] Remove support for macro class and import augment
These were part of the macros experiments which has been cancelled.

Change-Id: I14071bc8e86025f273a533c313a3194c8eae5190
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495341
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-04-16 02:25:05 -07:00
Konstantin Shcheglov 46083a4d99 Augment. Replace fragment isSynthetic with origin flags.
Remove FragmentImpl.isSynthetic and record synthesized fragment origins
using more specific isOrigin... flags instead.

This adds dedicated origin markers for formal parameters and type
parameters synthesized to keep augmentation fragments aligned, and for
formal parameters synthesized for mixin application constructors. It
also stops marking other generated fragments as synthetic when their
origin is already represented by a more specific flag such as
isOriginVariable, isOriginGetterSetter, isOriginLoadLibrary, or
isOriginNotExistingFile.

Update summary serialization to preserve the new fragment flags and bump
the data version. This makes generated fragment provenance more precise
and avoids collapsing different synthesized cases into one generic
synthetic marker.

Change-Id: I99788b3372d05fd882f6e15e05af39e048f94122
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495786
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-15 17:31:12 -07:00
Konstantin Shcheglov 9c90b215c9 CQ. Comments for hasEnclosingTypeParameterReference, set to false for top-level functions.
Change-Id: I94a612a85d07419f7833427631d9cef1d2b88610
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495800
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-15 14:56:29 -07:00
Konstantin Shcheglov db0fb10384 CQ. Generate Element and Fragment flags.
Bug: https://github.com/dart-lang/sdk/issues/63159
Change-Id: I46976106c7afe6b38e7e20709241e17f0d94df2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494760
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2026-04-15 09:04:51 -07:00
Konstantin Shcheglov 909f1f0044 CQ. Use Uri for checking _isConstructor() or _isTopGetter().
Change-Id: Idf25747182eb0beb7d44fdf768cb64ec8ff67f57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495680
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-15 07:39:52 -07:00
Konstantin Shcheglov 50ab3d5acb CQ. Add cached InterfaceType._subsctitution, remove forTargetType().
Add a lazily initialized substitution to `InterfaceTypeImpl` and reuse
it when instantiating members for the target type.

Previously getters, setters, and methods went through specialized
`forTargetType()` helpers that rebuilt the same substitution from the
interface type before delegating to `substitute()`. This duplicated
logic and spread the target-type instantiation path across several
member classes.

Keep the substitution on `InterfaceTypeImpl` instead, and use
`element.substitute(_substitution)` at the call sites. This makes the
instantiation flow more direct, removes redundant helpers, and keeps
member substitution logic centered on the interface type that owns it.

Change-Id: I985c8da13ae8a8c9e36b85ad3be2af2743c386b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495640
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-15 07:31:52 -07:00
Konstantin Shcheglov fc6b7b9805 CQ. Use InternalFieldElement.substitute() instead of SubstitutedFieldElementImpl.from()
Add `InternalFieldElement.substitute()` and route field substitution
through the element itself instead of the static
`SubstitutedFieldElementImpl.from()` helper.

This makes fields follow the same substitution pattern as other internal
elements, so callers no longer need to special-case field members or
depend directly on the substituted implementation class. It also lets an
already substituted field compose another substitution, instead of
rebuilding the wrapper from scratch.

The new implementation avoids creating a substituted field when the
substitution is empty or the field does not reference enclosing type
parameters. This keeps the fast path cheap while preserving the same
behavior for fields that actually need instantiation.

Update the bundle reader and substituted field-formal parameters to call
`field.substitute(...)`, and remove the now-unused direct import of
`member.dart`.

Change-Id: I146b44bb81a6033bb19b2be6fe498046544cd235
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495621
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-15 07:31:49 -07:00
Sam Rawlins 612f961b52 analyzer: Update definition of @JS to include js_interop library
The new dart:js_interop library has its own definition of the JS class
used as `@JS`.

Change-Id: I6e04ad1259e140702b8d07aefe3afbefc46ae894
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495180
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2026-04-14 16:48:26 -07:00
Konstantin Shcheglov b9cc3370d7 CQ. Replace SubstitutedFormalParameterElementImpl.from() and switch with InternalFormalParameterElement.substitute()
Add `substitute()` to `InternalFormalParameterElement` and move formal
parameter substitution logic behind that interface.

This replaces `SubstitutedFormalParameterElementImpl.from()` helper and
the subtype switch in substituted executables with polymorphic dispatch
from each parameter element.

The change makes substitution follow the same pattern already used by
other internal element APIs, so callers no longer need to know which
formal parameter subtype they are handling. It also keeps composition of
existing substitutions local to substituted parameter implementations.

As part of this cleanup, field formal parameters now use a dedicated
internal mixin, and function type instantiation and super-formal lookup
reuse the new element-level substitution entry point.

Change-Id: I3efaa4ae3e08652328058338ad37715fe838e435
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495220
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-14 16:35:10 -07:00
Konstantin Shcheglov e7c6654312 Augment. Allow abstract top-level variables.
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>
2026-04-14 16:12:24 -07:00
Konstantin Shcheglov c4d497af67 Elements. Make ConstructorElementImpl.hasEnclosingTypeParameterReference a stored flag.
Change-Id: I7cc99e369771d7a74329e0dbcc799293d82fc74b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495481
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-14 14:10:58 -07:00
Konstantin Shcheglov 18d47a8650 CQ. Migrate all uses of SubstitutedExecutableElementImpl.from() to substitute().
Add `InterfaceType.interfaceMembers` and
`InterfaceType.inheritedConcreteMembers`, and implement them by applying
the type's substitution to the underlying element members.

This moves member instantiation to the `InterfaceType` API instead of
requiring callers to read raw element maps and wrap the results
manually. With this change, code that works with an instantiated type
can ask the type itself for the corresponding instantiated members.

Update completion, inheritance, extension resolution, and summary
reading code to use the new API and `ExecutableElement.substitute()`
instead of `SubstitutedExecutableElementImpl.from()`. This removes the
old helper, simplifies callers, and makes substitution behavior more
uniform across the analyzer.

Change-Id: I2349546d65e9745c2cdeda19ca6ff9283a5fd001
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495100
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-14 13:39:50 -07:00
Sam Rawlins 577a7abf67 analyzer: Validate plugin diagnostic configuration
This adds validation that plugin diagnostics are configured with one
of the valid values (taken from one of the test cases):

```
plugins:
  one:
    diagnostics:
      code1: ignore
      code2: warning
      code3: error
      code4: info
```

Change-Id: I2a77988c2efe1d9e0fdcd33558ed970fbe4c47c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494781
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2026-04-14 10:58:25 -07:00
Konstantin Shcheglov b3c0f6e31a Elements. Provide value for ConstructorElementImpl.hasEnclosingTypeParameterReference, test expectations.
Change-Id: I0a7feedc741977f455722b94f6e02af0ccf257d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/495140
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-14 09:45:30 -07:00
Fedor Shcheglov b809db2c48 Track complete declarations in element fragments
Add an explicit `isCompleteDeclaration` modifier to element fragments
and include it in unlinked API signatures where empty and non-empty
bodies differ semantically.

Change-Id: I8bb452fbf234c82c213567c26d07d6f749ca3175
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494740
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2026-04-14 09:35:37 -07:00
Konstantin Shcheglov 5661776557 CQ. Use InternalGetterElement.forSubstitution(), etc.
Replace the generic executable substitution helper with
`forSubstitution()` methods on internal executable and member elements.

This moves the logic for creating substituted constructors, methods,
getters, and setters onto the corresponding element implementations.
Each element kind can now decide whether a substituted wrapper is
needed, reject invalid cases such as non-member accessors, and combine
nested substitutions in a single place.

Also add `MapSubstitution.andThen()` so substituted elements can compose
an existing substitution with a new one directly, instead of rebuilding
maps ad hoc. This makes repeated substitution clearer and preserves the
intended order of application.

Overall, the change makes member substitution more explicit, removes
type casts and kind switches from the shared helper path, and keeps
substitution-specific behavior closer to the element types that own it.

Change-Id: I54a3bfea48ddf87b4db5c53094090f24d66a9a23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494780
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-13 15:39:16 -07:00
Konstantin Shcheglov 70c0e60aff Elements. Use withTypeParameters() in BundleWriter.
Use merged type parameters in BundleWriter

Use `withTypeParameters()` when writing type-parameterized fragments
instead of rebuilding a local scope from `fragment.typeParameters`.

The serialized data still comes from the fragment list, but the
resolution context now uses `fragment.element.typeParameters`. This
makes BundleWriter use the canonical merged type parameter elements when
writing bounds, default types, and other references that can point back
to those parameters.

Using the merged elements keeps the writer aligned with how later
resolution data refers to type parameters, especially when multiple
fragments are linked into a single element.

Also rename `_writeTypeParameterElement` to
`_writeTypeParameterFragment` to match what the method actually writes:
fragment declaration data, with element-backed resolution properties.

Change-Id: Iddcd7a4b15ad0717bd137da97813f761e0fba5eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/494569
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2026-04-13 14:46:00 -07:00