Commit Graph

1221 Commits

Author SHA1 Message Date
Joshua Litt c4167766f2 [js] Restrict imports in strict mode.
Change-Id: I90cdf408e60cf8115c6321448623cf363dc92f66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292960
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Srujan Gaddam <srujzs@google.com>
2023-04-18 17:21:27 +00:00
Jake Macdonald cb4c9c74de Add support for mixin declarations in the macro APIs
Adds MixinDeclaration/IntrospectableMixinDeclaration for introspection.

Adds MixinTypesMacro/MixinDeclarationsMacro/MixinDefinitionsMacro macro
interfaces.

Updates supporting serialization/execution code and tests.

Change-Id: I57245fe7d177b6d5ba57649455fbd844ba1f85c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294380
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-04-18 16:04:00 +00:00
Daco Harkes fa3a72fa7e [cfe/ffi] Error on compound constructors
TEST=co19/LibTest/ffi/Struct/Struct_A02_t01
TEST=co19/LibTest/ffi/Union/Union_A03_t01
TEST=co19/LibTest/ffi/Union/Union_A03_t02
TEST=co19/LibTest/ffi/Union/Union_A03_t03
TEST=co19/LibTest/ffi/Union/Union_A04_t01

Closes: https://github.com/dart-lang/sdk/issues/46813
Change-Id: I2a057613a62eccc0de81083a6f63f8ba68430fc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293684
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-04-17 11:03:57 +00:00
Kallen Tu 2954986a7e [parser] Add errors for using class modifiers on enums.
Otherwise, in its current state, there's no clear error for any modifiers when used before an enum declaration.
This follows the same format to FINAL_MIXIN_CLASS and those groups of errors.

Bug: https://github.com/dart-lang/sdk/issues/51935
Change-Id: I8174b6894c95fef5c0f4704927b161942c19d3ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294122
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2023-04-13 14:59:57 +00:00
Srujan Gaddam 568469b896 Reland "[dart:js_interop] Export some package:js annotations and check them"
This reverts commit df761ba9e7.

This also rebases the original CL onto HEAD so it can be landed first.

CoreLibraryReviewExempt: Reland of backend-specific library changes.
Change-Id: I4f9a017be3ec1924c021f941291d79d7aee06663
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294131
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
2023-04-12 18:15:00 +00:00
William Hesse 7bac8ed687 [Release] Bump minor version of main to version 3.1.
Change-Id: Icf489686d790be195e37db37727782227d2f3704
TEST=Version bump autogenerated by scripts
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294600
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: William Hesse <whesse@google.com>
2023-04-12 16:36:20 +00:00
Lasse R.H. Nielsen 80de9162c8 Retire 2.19 experiment.
Tested: No tests. Removing functionality, all existing tests running is a success.
Change-Id: I25eb84347e1d133d465671223f4d3b037116c5e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294241
Reviewed-by: Liam Appelbe <liama@google.com>
Auto-Submit: Lasse Nielsen <lrn@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Kevin Chisholm <kevinjchisholm@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2023-04-12 12:46:41 +00:00
Paul Berry b4fa47f654 Add dependency overrides for pkg/_fe_analyzer_shared
These dependency overrides prevent pub from getting confused about the
fact that our SDK development is in a mono-repo; that in turn allows
unit tests to be run from inside vscode using the standard test
integration.

Change-Id: I952010c8adfe068912a15b56a53cb148fa2fccf5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294640
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-12 12:23:00 +00:00
Paul Berry dc639c13cb Patterns flow analysis: recognize [...] (and related patterns) as trivially exhaustive.
If a list pattern consists of a single rest pattern, and that rest
pattern is guaranteed to match, then the whole list pattern is
guaranteed to match as well (provided that the matched value type is a
subtype of the list pattern's required type).

Bug: https://github.com/dart-lang/language/issues/2980
Change-Id: I316cc93d4e696f094716be92e1fbc1cd3a43a73c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294622
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-11 19:54:20 +00:00
Jens Johansen 99395b2b0c [parser] Recover differently from mixin with clause
Fixes #50838 (https://github.com/dart-lang/sdk/issues/50838)

Change-Id: Ib0f0c01a07ab6232732a2be6c3aec34cb4bfdd29
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292360
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-04-11 16:29:53 +00:00
Jake Macdonald 70559a9514 Add support for enums in the macro APIs
This includes introspection support, support for annotating and executing macros targeted at enums and enum entries, and support for creating library augmentations of enums with proper syntax (including enum entries).

I also refactored some of the Class support to be more general so we can share interfaces where appropriate.

Change-Id: Ie9111ff280405496e55e32478a19c104341aee37
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294100
Commit-Queue: Jake Macdonald <jakemac@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2023-04-07 19:57:55 +00:00
Zach Anderson df761ba9e7 Revert "[dart:js_interop] Export some package:js annotations and check them"
This reverts commit ef7d8d3f9a.

Reason for revert: Breaks Dart -> Engine roll?

See:
https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20linux_web_engine/1821/overview
https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20Engine%20Drone/666824/overview

Original change's description:
> [dart:js_interop] Export some package:js annotations and check them
>
> To disallow package:js on dart2wasm, we need to export @staticInterop
> and @anonymous through dart:js_interop. However, users should not mix
> the two @JS annotations, so we add some static checks for that. We also
> export @JSExport to support export classes with dart:js_interop.
>
> CoreLibraryReviewExempt: Reexporting annotations through backend-specific library.
> Change-Id: I54610965da332320170d991d785192341049607e
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293500
> Reviewed-by: Joshua Litt <joshualitt@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Srujan Gaddam <srujzs@google.com>

Change-Id: I2af0755e054a1b0452a5fc617a93257209703793
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293961
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2023-04-06 14:42:36 +00:00
Srujan Gaddam ef7d8d3f9a [dart:js_interop] Export some package:js annotations and check them
To disallow package:js on dart2wasm, we need to export @staticInterop
and @anonymous through dart:js_interop. However, users should not mix
the two @JS annotations, so we add some static checks for that. We also
export @JSExport to support export classes with dart:js_interop.

CoreLibraryReviewExempt: Reexporting annotations through backend-specific library.
Change-Id: I54610965da332320170d991d785192341049607e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293500
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Srujan Gaddam <srujzs@google.com>
2023-04-06 00:29:12 +00:00
Paul Berry 2ec3b513db Patterns flow analysis: recognize trivially exhaustive switches.
This fixes a minor bug in flow analysis which was preventing it from
recognizing when a switch statement was trivially exhaustive, meaning
one of its reachable cases was guaranteed to always match.

This mostly addresses
https://github.com/dart-lang/language/issues/2980, but flow analysis
still fails to recognize that:

- A list pattern containing a just a single rest pattern always
  matches (unless the rest pattern has a subpattern that may fail to
  match).

- A null check pattern always matches if its subpattern always matches
  and the matched value type is non-nullable.

- The relational pattern `!= null` always matches if its subpattern
  always matches and the matched value type is non-nullable.

Fortunately, these drawbacks are small and don't lead to unsoundness.
I'll try to address them in follow up CLs.

Bug: https://github.com/dart-lang/language/issues/2980
Change-Id: Ie9f8564cde66a5a2c41114033ca3ff0e1a0f139a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293860
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-04-05 23:32:28 +00:00
Chloe Stefantsova 9f4f7faaa4 [cfe] Improve error message on incomplete joint pattern variables
Closes https://github.com/dart-lang/sdk/issues/51604
Closes https://github.com/dart-lang/sdk/issues/51962

Part of https://github.com/dart-lang/sdk/issues/49749

Change-Id: I9ada7a3a0194964af5c9e2afea1c2ea3ead67641
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292890
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-05 19:43:59 +00:00
Johnni Winther 65335cb4b3 [_fe_analyzer_shared] Handle empty types in exhaustiveness
This handles Never, and as a consequence, empty sealed types in
exhaustiveness. Since these contain no value, we should not try to
exhaust them. This avoid invalid non-exhaustive errors in these cases.

Included is handling of a scrutinee with invalid type as Never in the
CFE, thus avoid cascading non-exhaustive or unreachable errors.

Change-Id: Ife097731bb5399c42bf83f1d77aff773346adfb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293682
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-05 18:26:06 +00:00
Johnni Winther 20354f87fd [cfe] Report error on a assignment in guard
This reports an error when a pattern variable is assigned in the
guard of the case that declares it.

Change-Id: Ic9281350480d1eddcbbe4f35fba4ded4f35c13c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292892
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-05 15:16:22 +00:00
Paul Berry a3f5cfdc7f Patterns parsing: recover when switch statement syntax used for switch expressions.
This change ensure that if the user makes an erroneous switch
expression by imitating the syntax of case statements (i.e. using
`case`, `default`, `:` instead of `=>`, or `;` instead of `,`), error
recovery will understand the user's intent, avoiding follow-on errors.

Fixes #51886.

Bug: https://github.com/dart-lang/sdk/issues/51886, https://github.com/dart-lang/sdk/issues/51943
Change-Id: Icd405d4fd4ddfb1aadcf0867e5a51ba898d4cdbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293200
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-04 18:52:59 +00:00
Paul Berry 8aa48712be Patterns parsing: recover from patternVariableDeclaration non-statement.
Previously, if a pattern variable declaration appeared outside of a
function or method, the parser would get very confused.  Now it
recognizes the situation, issues a comprehensible error message, and
replaces the pattern with a synthetic identifier token so that the
analyzer AST is somewhat sensible.

Fixes #51322.

Bug: https://github.com/dart-lang/sdk/issues/51322
Change-Id: Ica5f060cb483a39c4e50942d639939b1fab40bea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293087
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-04 14:55:00 +00:00
Johnni Winther 5518abf1c7 [_fe_analyzer_shared] Update non-exhaustive message
This updates the message report for non-exhaustive switch statements
and expressions to include the witness in the problem message and
a reduced witness, which doesn't include properties that fully cover the
static type. The message is also split into two messages; one for
switch statements and one for switch expressions, allowing for a
better wording regarding the default/wildcard pattern case.

Change-Id: I17db657ef12ade5d47fa96bf69b8807e33ed5b8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293040
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-04 09:44:59 +00:00
Johnni Winther 31e119e594 [cfe] Report error on empty map pattern
This reports the error on empty map pattern and moves the reporting
of rest patterns in map patterns to the shared analysis.

Change-Id: I317d0c42a3bc7534462b1b9781c1f6471746fc0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292860
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-04 09:36:38 +00:00
Paul Berry c2713ca752 Patterns parsing: improve error recovery for switch expressions.
If the parser gets lost during a switch expression, it now attempts to
pick back up at the next `,` in between the curly braces (ignoring
more deeply nested commas).  This allows much better error recovery in
the case where an illegal function expression appears in a guard.

Fixes #51906.

Bug: https://github.com/dart-lang/sdk/issues/51906
Change-Id: I1cb43857ccc04f0e4146c23c9e07acb02a80d405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293083
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-04 03:29:39 +00:00
Paul Berry d78fe25542 Patterns parsing: fix error recovery for switch expression using :
If a user attempts to use `:` instead of `=>` in a switch expression,
we now generate an error at the location of each `:` token (and
otherwise interpret the switch expression in the way the user
intended).

Fixes #50930.

Bug: https://github.com/dart-lang/sdk/issues/50930
Change-Id: I3687fb464b6875424745e664b0d28346b3cd6375
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292982
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-03 21:28:41 +00:00
Johnni Winther 0fcdb66666 [_fe_analyzer_shared] Don't add '?' if type is nullable
This adds an `isImplicitlyNullable` property to `StaticType`. This
is used to avoid the `?` suffix when printing implicitly nullable
types such as `void`.

Change-Id: I02d4197688b37c08aef231b249574e3fdd87cf21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292861
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-04-03 20:47:43 +00:00
Johnni Winther 3b56301f3d [_fe_analyzer_shared] Add support for extension members in exhaustiveness checking
This adds support for extension members in exhaustiveness checking. These are different from regular members in that the type cannot be derived from the matched type but instead is determined by the required type of the object pattern.

To support this a new ExtensionKey is added which holds the static type of the property and whose identity is determined by the name of the property _and_ the type of the receiver (taken from the required type of the object pattern).

When expanding properties, the type of the ExtensionKey is used when the
SingleSpace doesn't have the corresponding property instead of looking up the property type on the static type of the SingleSpace.

Closes #51854

Change-Id: I7a54005972d0640b7dc79e92950bf6d1f89c3fd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292741
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-04-03 16:47:33 +00:00
Chloe Stefantsova d758cf1392 [cfe] Report more errors on mismatching joint variables
Part of https://github.com/dart-lang/sdk/issues/49749

Change-Id: Ie3dd75209f40681590e378138cbe2b86a5e1619f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292361
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2023-04-03 16:41:54 +00:00
Paul Berry f537137c67 Patterns parsing: eliminate an unnecessary TODO.
The grammar was updated in
https://github.com/dart-lang/language/commit/f06d416a1a4e0348b9f6d6717489bd9ab9075e9f
so that it now matches the implementation.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I2aa7d395360c96e39b77336c46f415f1b2280439
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292801
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-03 15:55:09 +00:00
Paul Berry 8d16c1dc87 Patterns parsing: improve error recovery for late in patternVariableDeclaration.
Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: Id706ff0afab3f14d817fbf99112f772d1f1f7817
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292800
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-04-03 15:04:07 +00:00
Johnni Winther 9d557edcd8 [_fe_analyzer_shared] Rename fields to properties
Change-Id: I2458867b6dbc770335f12f3d52a0eb4fb67516be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292721
Reviewed-by: Paul Berry <paulberry@google.com>
2023-04-03 12:16:43 +00:00
Johnni Winther b28d43b3d3 [_fe_analyzer_shared] Base WrappedStaticType on _BaseStaticType
The WrappedStaticType was wrongly based on the NonNullableStaticType
even though it could be nullable through its components. This made
the WrappedStaticType(Null, T & bool), i.e the Null type that is also
implicitly a T, which is the nullable part of T & bool?, not seen as
a subtype of Null.

The WrappedStaticType is moved to be a subclass of _BaseStaticType and
the isSubtypeOf implementation is updated accordingly.

Closes #51897

Change-Id: I6ac87c56d709b85f0db28efd327ff41b220ea00d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292701
Reviewed-by: Paul Berry <paulberry@google.com>
2023-04-03 07:21:34 +00:00
Paul Berry 489aefbe80 Patterns parsing: add error recovery tests.
Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: If63ee17234f0b63ebbdfda8a046350def8851472
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292662
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-04-02 23:32:17 +00:00
Paul Berry 45429b3f7f Patterns parser: remove bogus error recovery logic.
The "recovery" condition `|| /* recovery */ optional(':', next)` had
no effect, because that case was already covered by the previous `if`
statement.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I4eeeeb2ff6b3558888f07c65d85e9f79e334d9eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292661
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-04-02 23:30:36 +00:00
Paul Berry 22a8877452 Patterns parser: test that dynamic can be used in an object pattern.
This resolves a TODO in the patterns parser implementation.

(Note: the TODO says to file an issue, but there is no need; the spec
clearly states that `dynamic` is allowed).

Change-Id: I2ebbf5401052ce5b96679ac3cf8a1aba3cd384d4
Bug: https://github.com/dart-lang/sdk/issues/50035
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292541
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-04-02 12:28:58 +00:00
Johnni Winther 70056ed8c7 [_fe_analyzer_shared] Fix getField for WrappedStaticType
WrappedStaticType didn't forward 'getField' to its 'wrappedType',
thereby missing support for Object members on type variables.

Change-Id: I9b81d7e1f7c4fcc1620fd7d151af53b9046beda2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292362
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-04-01 21:16:19 +00:00
Paul Berry 7a5136032f Parser: test that objectPattern accepts OTHER_IDENTIFIER.
The type name in an object pattern is a `typeIdentifier`; in the spec
grammar, `typeIdentifier` includes `OTHER_IDENTIFIER`, which is defined as:

    OTHER_IDENTIFIER ::=
        `async` | `hide` | `of` | `on` | `show` | `sync` | `await` | `yield`

This adds tests to verify that all these identifiers are accepted as
type names in an object pattern.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I6b9d752e1b34f7bc93dedc4304f695e7cb42df48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292542
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-04-01 16:39:34 +00:00
Paul Berry 406bdf33e8 Fix precedence of expression inside relational patterns.
According to the spec, the expression inside a relational pattern is
`bitwiseOrExpression`.  We were only allowing `shiftExpression`.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: Ie1a5746f1060b84e6e1b856a622e89db698b4684
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292285
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-04-01 16:30:49 +00:00
Paul Berry d2184a9d03 Patterns parsing: disallow unaryPattern or relationalPattern in unaryPattern.
The precedence-based pattern parser can understand a unary pattern
inside another unary pattern (e.g. `_ as int as num`) or a relational
pattern inside a unary pattern (e.g. `> 1?`), but the specification
prohibits these constructions because they're difficult to read and
not very useful.

This change updates the implementation to match the spec, by producing
the appropriate error.  The offset and length of the error cover the
inner pattern, so it should be easy to construct an analysis server
quick fix that inserts the necessary parentheses.

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I33e74d6d1f863e7162851d26fefbacd4fd17277c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292120
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-03-31 16:43:01 +00:00
Paul Berry 452dcdf517 Fix parsing of PATTERN as T? when
The logic for parsing types has special disambiguation rules for
deciding whether a trailing `?` should be included in the type, based
on what token(s) follow the `?`.  In the case where the token that
follows the `?` is `when`, we need to look further ahead to
disambiguate, to distinguish `PATTERN as T? when guard` from something
like `EXPRESSION is T ? when : otherwise`.

(Note: an alternative implementation would be to disambiguate based on
whether we're parsing a pattern or an expression.  But in the future I
want to move toward an architecture where expression parsing and
pattern parsing are combined, so that if the parser makes the wrong
decision about whether it's looking at a pattern or an expression,
error recovery will do a better job.  So I'm disambiguating based
solely on what follows the `?`.)

Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: Idbc780b7b54fecc7fd01cae868c34771564dd804
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292282
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2023-03-31 13:12:48 +00:00
Johnni Winther e6d352dec1 [_fe_analyzer_shared] Update exhaustiveness checking to new semantics
In response to https://github.com/dart-lang/language/pull/2960

Change-Id: I26430aa7666de69b9bbc34ded65e0e54160e3d3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292004
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-03-31 12:54:23 +00:00
Lasse R.H. Nielsen 9e76983782 Reland "Add more interface and final modifiers to dart:core."
This is another reland of 4f8333e80e.
Third time is the charm.

CoreLibraryReviewExempt: Reland of accepted CL.
Change-Id: I4ea8326af91c168b044d252162571d3fe697e4b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289826
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-03-30 20:34:09 +00:00
Paul Berry 134007af32 Patterns parsing: make it an error to use var before a type in a variable pattern.
Bug: https://github.com/dart-lang/sdk/issues/50035
Change-Id: I46b23ef0d1856401eac4b0a05c6bc6008711d35a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291780
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2023-03-30 18:25:03 +00:00
Konstantin Shcheglov 1ec1e7358a Changes for map pattern: report an error for rest elements, empty map pattern.
Bug: https://github.com/dart-lang/language/issues/2861
Change-Id: I00ccb3ea03aa476f96c2ecf3e3a9e13bd4926193
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291940
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Marya Belanger <mbelanger@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-03-30 17:54:06 +00:00
Paul Berry 104ac30cf4 Parser: clean up handling of variable patterns.
The listener API for variable patterns is split into three separate
functions, to handle the three separate behaviors:

- `handleAssignedVariablePattern` for variable names appearing in an
  assignment context (these assign to an existing variable upon a
  successful match).

- `handleDeclaredVariablePattern` for variable declarations appearing
  in a declaration or matching context (these cause a new variable
  name to come into scope).

- `handleWildcardPattern` for wildcards in any context (these don't
  capture the matched value).

Also, responsibility is shifted to the parser for reporting the
following error conditions:

- VariablePatternKeywordInDeclarationContext (e.g.
  `var (var x) = ...;`)

- PatternAssignmentDeclaresVariable (e.g. `[x, var y] = ...;`)

Previously these errors were detected by the implementations, and
weren't fully covering all possible error scenarios.

In the case of VariablePatternKeywordInDeclarationContext, the
listener method `handleDeclaredVariablePattern` is called instead of
`handleAssignedVariablePattern`.  This ensures that no tokens are
dropped from the analyzer AST.  The CFE uses the `inAssignmentPattern`
argument of `handleDeclaredVariablePattern` to distinguish this error
recovery case from a legitimate declared variable pattern.

Fixes #51868.

Bug: https://github.com/dart-lang/sdk/issues/51868
Change-Id: I28ec679b73d64033166721c6460be35f15e23171
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291583
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-03-30 14:12:03 +00:00
Jens Johansen ea3000f1d4 [parser] Fix setting endGroup with triple shift
Fixes #51759 (https://github.com/dart-lang/sdk/issues/51759).

Also fixes #45662 (https://github.com/dart-lang/sdk/issues/45662) (which
was already closed but apparently wasn't really fixed --- the `int.>>`
variant still crashed and fixing #51759 made the `int.>>>` crash again).

Change-Id: Ia218d20123ecc36636ad35c15a1b51fb196a07d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292005
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2023-03-30 13:57:21 +00:00
Paul Berry f1dcdd092a Sort declarations in type_analysis_result.dart.
No functional change.

Change-Id: I412f44cd6e38d1c10aed0b40afc3745aa1126814
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291881
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-03-30 12:22:24 +00:00
Paul Berry 2366a35dab Clean up hacky code in Parser.parseTopLevelMethod
This hack was needed to cover a short time period in 2020 where an
improvement to flow analysis had landed in master but hadn't yet
landed in the checked-in SDK that is used for presubmit checks.  We
are long past needing it anymore.

Change-Id: I0d0cd3d4d9829cc4b0798a07feaac09bb4929f31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291841
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-03-30 12:22:09 +00:00
Kallen Tu f7bc72fce6 [analyzer/cfe] Remove interface mixin, final mixin and sealed mixin.
Added error messages for when users try to use invalid mixins + a language test that tests that (and tests in each of the front ends).

Removed the tokens from the parser listeners.

Removed all behaviours and error reporting related to these invalid mixins.

Change-Id: I558595826dae7e2c176bd1929e97caa2335c167c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290614
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Kallen Tu <kallentu@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-03-30 11:56:08 +00:00
Johnni Winther c4677b9d54 [_fe_shared_analyzer] Check supertype before subtypes in exhaustiveness checking
This updates the checking order of the exhaustiveness algorithm to
process the sealed type on its own before checking the subtypes. This
has the benefit that for fields that fully covered by (a supertype of)
the sealed type itself, like a wildcard pattern, we avoid checking
each individual subtype.

For the exponential cases added in
https://dart-review.googlesource.com/c/sdk/+/291800
this avoids the exponential growth, bringing the number of checked
witness candidates from 837932 to 6 for the "subtype" test with n = 30 and from 12207032 to 12 for the "fields" test with n = 10.

The change also fixes a problem in the 'future_or_members.dart' caused by the non-null version of 'FutureOr<dynamic>' still being nullable. The old algorithm tried to use 'Object' as a witness canditate but filtered out 'FutureOr<dynamic>' because 'Object' wasn't a subtype if it. The new algorithm starts by using 'Object?' and therefore sees that 'FutureOr<dynamic>' exhausts it. This is an inherent problem in the modelling of StaticType and it should still be addressed.

Change-Id: Iaa5d5604afc4662fe1983d670638223eae5dbf6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291822
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-03-30 11:24:13 +00:00
Johnni Winther 4ada8386f7 [_fe_analyzer_shared] Add test for issue51878
The test shows that both the switch statement and the switch expression
of the issue example are consider exhaustive by the exhaustiveness
checker.

Closes #51878

Change-Id: I5418448a69f8741cc6f40ebc027b24d825d29344
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291085
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-03-29 23:34:13 +00:00
Johnni Winther a7205526c4 [_fe_analyzer_shared] Add benchmark for exponential exhaustiveness
The tests in the benchmark show some pitfalls of the exhaustiveness
checking algorithm where the witness canodidate count is exponential
in the size of the user code.

Change-Id: I310c42513bf76c88fed7ffdb5a60c165c089dfa9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291800
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-03-29 21:48:23 +00:00