Commit Graph

507 Commits

Author SHA1 Message Date
Paul Berry e933e91aaa Reland "Flow analysis: promote to non-nullable on initialization"
This is a reland of 6a1c54ec30

Original change's description:
> Flow analysis: promote to non-nullable on initialization
>
> When flow analysis encounters a variable declaration of the form `T? x
> = expr;`, if the type of `expr` is `T`, then the variable is
> immediately promoted to type `T`.
>
> Fixes #43099.
>
> Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
> Bug: https://github.com/dart-lang/sdk/issues/43099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

Bug: https://github.com/dart-lang/sdk/issues/43099
Change-Id: I7530bb0f7c24674a7b500558b89d50b35e045aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166305
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-07 13:14:55 +00:00
Paul Berry 19995ba7cd Replace flow ranalysis reachability bool with a stack.
Currently we don't push or pop anything on the stack, we just
manipulate the single value that's on the stack.  So there's no
functional change.  Logic that pushes and pops the stack will be added
in a follow-up CL.

Bug: https://github.com/dart-lang/sdk/issues/40009
Change-Id: I4deb4cbe06644a2b2c9b5e2c1dc140fb4cd805cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165145
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-10-07 12:13:54 +00:00
Paul Berry ab4818c251 Fix bad flow analysis unit test for restrict.
I'd always meant to test the cartesian product of possible
reachabilities for the `restrict` function.  Due to a copy/paste error
I was missing one of the four possibilities.

Change-Id: I3a99c72051e7f12afd8f345d8c2dafe92d6e2c48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166220
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-06 21:20:27 +00:00
Johnni Winther 28c6ab316d [cfe] Report errors on incompatible getter/setter types
Closes #42702

Change-Id: I9af4b8d616c4368c9f955f658f27e581352a3cd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165806
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-10-05 21:53:42 +00:00
Johnni Winther 4c29f26fc6 [cfe] Report errors in invalid main declarations
Closes #43554
Closes #43556
Closes #43558

Change-Id: Ib3e2b891473f07bad7b4a373152be684095619b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165904
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2020-10-05 14:37:33 +00:00
Konstantin Shcheglov 3a59eafbe5 Include promotedBound into the TypeParameterType display string.
Change-Id: I7d34a041559875d34a66de4504b8df1b57497e55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165684
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-10-02 18:42:21 +00:00
Paul Berry 7704cc9dbe Fix flow analysis of a late initializer that is an assignment expression
Fixes #43621.

Bug: https://github.com/dart-lang/sdk/issues/43621
Change-Id: I5847e34fba9d892085dd8e388f6d96912c46eb5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165682
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-02 12:09:08 +00:00
Paul Berry d73c2b05d2 Fix FlowAnalysisDebug.isUnassigned
Change-Id: Ia655a35d53c013018d8cbb1770ca2b11820c2dd9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165700
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-10-02 12:09:08 +00:00
Dmitry Stefantsov 0c8109c964 [cfe] Adjust error location for const constructors with late fields
Closes #43354.

Bug: https://github.com/dart-lang/sdk/issues/43354
Change-Id: Idc8f4757a5589638eb4e3ce08cda2c5afa8d5202
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165604
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-10-02 08:30:16 +00:00
Clement Skau b4f49dc255 Revert "Flow analysis: promote to non-nullable on initialization"
This reverts commit 6a1c54ec30.

Reason for revert: Triggers test failure:
https://ci.chromium.org/p/dart/builders/ci.sandbox/vm-kernel-precomp-linux-debug-x64/8247

Original change's description:
> Flow analysis: promote to non-nullable on initialization
>
> When flow analysis encounters a variable declaration of the form `T? x
> = expr;`, if the type of `expr` is `T`, then the variable is
> immediately promoted to type `T`.
>
> Fixes #43099.
>
> Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
> Bug: https://github.com/dart-lang/sdk/issues/43099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

TBR=paulberry@google.com,scheglov@google.com,rnystrom@google.com,johnniwinther@google.com

Change-Id: I8549b48a734f527194ce11d82235b9d5c6e58185
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/43099
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165564
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2020-10-01 08:41:15 +00:00
Paul Berry 6a1c54ec30 Flow analysis: promote to non-nullable on initialization
When flow analysis encounters a variable declaration of the form `T? x
= expr;`, if the type of `expr` is `T`, then the variable is
immediately promoted to type `T`.

Fixes #43099.

Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
Bug: https://github.com/dart-lang/sdk/issues/43099
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-10-01 01:15:31 +00:00
Paul Berry 94f1c0b4eb Reland "Generate "late definitely assigned" error regardless of nullability"
This is a reland of 2d22e74e54

Original change's description:
> Generate "late definitely assigned" error regardless of nullability
>
> Change-Id: If55bd3312afa2ce87312bd4ebf31ab5ada40cc3f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164981
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

Change-Id: I2dda875039c56be93430bf8f6bdca9098141d35a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165400
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-01 00:44:31 +00:00
Paul Berry a4ecdfc6a2 Revert "Generate "late definitely assigned" error regardless of nullability"
This reverts commit 2d22e74e54.

Reason for revert: Broke CFE bots

Original change's description:
> Generate "late definitely assigned" error regardless of nullability
>
> Change-Id: If55bd3312afa2ce87312bd4ebf31ab5ada40cc3f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164981
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

TBR=paulberry@google.com,johnniwinther@google.com

Change-Id: I595d5bd307bba3a94aac43ef96040f8cd25e1b97
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165261
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-30 14:11:56 +00:00
Paul Berry 0d35cf733e Replace flow analysis's setReachable with setUnreachable.
The setReachable method took a bool indicating whether the new state
should be considered reachable or not, however outside of tests the
value that was passed in was always `false`.  Change to a
`setUnreachable` method taking no arguments.

This should make it easier to transition to a stack representation for
reachability.

Bug: https://github.com/dart-lang/sdk/issues/40009
Change-Id: I16a35ec3d5f44763a60e42f200a3caa619fac118
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165142
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-30 12:03:54 +00:00
Paul Berry 954ba3f31c Flow analysis: don't propagate unassigned info out of closures.
All the logic we need for handling unassigned info in the presence of
closures already happens on entry to the closure, when we use
conservativeJoin to mark any variables assigned within the closure as
potentially assigned.  We don't need any additional logic at the end
of a closure.

Fixes #43006.

Bug: https://github.com/dart-lang/sdk/issues/43006
Change-Id: Ibcaaacd5bd1d18d39be013f13a7ba771d29adce4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162661
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-30 12:02:34 +00:00
Paul Berry 2d22e74e54 Generate "late definitely assigned" error regardless of nullability
Change-Id: If55bd3312afa2ce87312bd4ebf31ab5ada40cc3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164981
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-30 11:54:54 +00:00
Jens Johansen 6d7c92f016 [CFE] Add "strong" tests of the constant evaluator
This increases our "local" coverage of the constant evaluator.
Run with something like
`pkg/front_end/test/fasta/strong_tester.dart -DupdateExpectations=true -DstressConstantEvaluator=true -DskipVm=true`
there is now almost coverage of everything (or a comment in the code
suggests that the path is probably unreachable).

Note that
`out/ReleaseX64/dart pkg/front_end/test/vm_service_coverage_constant_evaluator.dart pkg/front_end/test/fasta/strong_tester.dart -DupdateExpectations=true -DstressConstantEvaluator=true -DskipVm=true`
has erroneous misses, for instance (but not limited to) asserts.
These are caused by errors in the VM.

A follow-up CL will be created to turn on "stressConstantEvaluator" by
default and print out any sucesses in the expect files.

Change-Id: I837837be4f0487fdbe57c5107e4b3415de189177
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163060
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-30 07:54:32 +00:00
Paul Berry 5e8b2722c7 Fix handling of for-elements with unparenthesized bodies.
The CFE defers the final build of the body of a for-element until
after building the rest of the body.  This caused a bug: if the body
was an assignment expression, flow analysis was not picking up on the
fact that the assignment was inside the loop.

Fixed by introducing a mechanism that allows the CFE to temporarily
pop the innermost structure on the AssignedVariables stack and then
push it again.

Change-Id: I11d526302934e9283807124ebd4a23e9d3e5ec66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164980
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-29 19:27:18 +00:00
Konstantin Shcheglov 2b246127f7 Prepare to publish analyzer 0.40.4 and _fe_analyzer_shared 11.0.0.
Change-Id: I19d92bf9f107a82826c2d6d41f18315f25afc411
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165040
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-29 18:46:27 +00:00
Paul Berry 2575008f25 Generate "late definitely unassigned" error regardless of nullability
Change-Id: I3c3244cb1042087d31c6e90acc9863369e15ad44
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164801
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-29 12:38:14 +00:00
Paul Berry 0176a3d4c5 Fix flow analysis handling of late variables with initializers.
A late variable with an initializer is very similar to a function
expression, in that it may be evaluated at any time in the future
(possibly more than once, if it throws an exception), so flow analysis
models it that way.

Fixes #42990.

Change-Id: I90ed00c8fd7388145f89011628e31ff7e85a5c43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164420
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-28 14:40:02 +00:00
Paul Berry ca0f61fc84 Generate an error if writing to a potentially-already-assigned final var.
Change-Id: Iee4dccbc2c11290cdf56b3a95259f6401a123620
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164246
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-28 14:36:14 +00:00
Srujan Gaddam c990450628 [package:js] Add checks for external keyword
Checks to see if a JS interop member is correctly annotated with
the `external` keyword. If it is not, it must be one of several
exceptions to be allowed.

This CL also changes static errors to first check for `JS` and
`external` before processing the member as a JS interop member.
This makes it clearer whether a member is a JS member.

Change-Id: I412eeafbfe8773847bfb9c864e4fb9b65e2d632a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158083
Commit-Queue: Srujan Gaddam <srujzs@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2020-09-25 23:30:34 +00:00
Konstantin Shcheglov b53d016f71 Prepare to publish analyzer 0.40.3 and _fe_analyzer_shared 10.0.0.
Bug: https://github.com/dart-lang/sdk/issues/43550
Change-Id: I555a958c14eb435ab6a8522e89cd90dd851da2c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164600
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-25 17:52:29 +00:00
Paul Berry def50905c2 Make flow analysis handling of is/==/??=/?. consistent with mixed mode semantics
Bug: https://github.com/dart-lang/language/issues/1143
Change-Id: Id177f8b19c15ef246f21ddd840410cddfee2e5cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163600
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-09-25 08:35:03 +00:00
Johnni Winther 2414b293e1 [cfe] Throw error on exhaustive switch and expression of type Never
This requires a change to flow analysis that does not promote
expressions to Never through is-tests and equality tests.

Change-Id: Iec2ba5b78e61d205ad21dad6f07dbdb25fc746d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163380
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-09-25 08:35:03 +00:00
Paul Berry f157b5ff80 Flow analysis: promote type X&T on initialization.
When flow analysis encounters a variable declaration of the form `var
x = expr;`, if the type of `expr` is `X&T`, then the variable is given
the inferred type `X`, but it is immediately promoted to `X&T`.

Change-Id: I2a5ffca3860ab009f0942e6efc641c1604ab6323
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163840
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-23 16:58:09 +00:00
Paul Berry 2366d27822 Flow analysis: add API to support promotion on initialization.
Change-Id: If0258862c22234292c461af8de9f305cebcd491d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163731
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-09-23 16:58:09 +00:00
Paul Berry ef4c85e243 In null safe code, error if a final local is read when unassigned.
Previously, we did not permit a final local variable without an initializer.

This allows constructions like:

  final int i;
  if (...) {
    i = 0;
  } else {
    i = 1;
  }
  use(i);

Change-Id: I0ca20c810993627c70ce84a9ad238e683df41595
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163702
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-22 15:26:14 +00:00
Paul Berry f860868740 Flow analysis: remove old "promotable via initialization" logic.
This logic was removed from the spec in
https://github.com/dart-lang/language/commit/b70bb3f90679eb1c67b7ee852e1322046b2e4777.

Only a few places in the SDK itself were relying on this promotion
logic; I've fixed those places by adding explicit types.

Change-Id: Iaeaebe8dd5ab3e848699bc8ebc64a1ae80c1027a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163681
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-22 12:22:13 +00:00
Paul Berry 53e707f26d Flow analysis: don't consider a foreach-declared variable to be written to.
When performing flow analysis for a "for each" loop such as `for (var
x in ...) { ... }`, we don't need to consider the iterated value to be
"written to" the variable `x`, since the actual runtime semantics are
to create a fresh instance of the variable `x` each time through the
loop, initialized to the iterated value.

Fixes #43136.

Bug: https://github.com/dart-lang/sdk/issues/43136
Change-Id: I497c408c3efc26e93502de8ba0530bb5278e74c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162581
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-16 19:07:58 +00:00
Paul Berry 0eec9ee53c Use promoted type to infer for-each iterables.
Fixes #42653.

Change-Id: I90319b775207e6cc1c6b7a79d29b2c237b750845
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162625
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-16 18:20:48 +00:00
Paul Berry 745c648eb3 Flow analysis: propagate types of interest out of "for" and "while" loops.
Bug: https://github.com/dart-lang/language/issues/1203
Change-Id: Ie46c6a46e69c8eb4cd55e8d080bc3b66d2fd90b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162483
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-14 14:33:39 +00:00
Jens Johansen e6ffc0b285 [parser] Issue different warnings for missing identifier based on whether the token is used or not.
E.g. "var = 42;" now has a different error message than "var default = 42;".

Fixes #22553

Change-Id: I58affe988569d8e79190b63f7267b471a1b0ebc8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162182
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-09-14 08:55:18 +00:00
Paul Berry 337dd5d355 Make flow analysis handle for-each loops more consistently with their desugaring.
Previously the flow analysis equations for a for-each loop `N` of the
form `for (var V in E) S` were approximately as follows:

- Let `before(E) = before(N)`
- Let `before(S) = conservativeJoin(after(E), assignedIn(N), capturedIn(N))`
- Let `after(N) = join(after(E), break(S))`

This CL changes the behavior to:

- Let `before(E) = before(N)`
- Let `before(S) = conservativeJoin(after(E), assignedIn(N), capturedIn(N))`
- Let `after(N) = join(before(S), break(S))`

(In other words, the result of the conservative join is carried
through to the state after the loop).  This isn't strictly necessary
for soundness, but it makes the behavior of a for-each loop more
consistent with its desugared equivalent.  In particular, it means
that if a variable is potentially assigned to or captured in the body
of the loop, then the effect of that potential assignment or capture
will be felt in the code that follows the loop, even if the potential
assignment or capture is not connected to the flow control path.

Change-Id: I7a70a8ae9f87bd40b6592992d8ee985a9aa87e80
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162480
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-12 15:18:15 +00:00
Jens Johansen f4d3f8e0a2 [parser] Delete unused TokenStreamGhostWriter; test used UndoableTokenStreamRewriter
Change-Id: I7f4f053273f70d282b2ced7338715ca314055065
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162190
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-09-11 06:46:11 +00:00
Jens Johansen b0acaea1e5 [parser] Recover written out binary operators
* Add mechanisms to try out a recovery and only perform it if is
  successful.
* Recover written out binary operators, e.g. "a xor b", "a or b" etc.
  This fixes #26810 and is also how these operators are written in e.g.
  Kotlin. This might be somewhat controversial though.
* Adds a mechanism to _replace_ a token by another token.
  This might be controversial.
  It is done because just inserting the operator causes the same rewrite
  to be attempted on the same token stream several times (at least with
  the way the token stream is parsed via the CFE) in turn causing it to
  be recovered *sometimes*. This is now avoided by actually replacing
  the token.

Change-Id: Icfa806045575d2aa2e5f35126708651b275bcf84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162003
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-10 06:23:33 +00:00
Johnni Winther 22db21590d [cfe] Report error on nullable spread access
Closes #43256

Change-Id: I15b0f5a9353566af290b78151f7889fa06a44406
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162002
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-09-09 12:44:37 +00:00
Jens Johansen 0c90775fd6 [CFE] Better error messages for class initialization errors
Change-Id: Ic7c489b0bfffd05cdd71dc254db042956fd25c3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161944
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-09-09 11:37:47 +00:00
Jens Johansen a06e53b557 [parser] Set forIn = true when recovering 'in' written as ':'
Before this change the CFE crashed with an assert error.

Change-Id: Ide486388fbba8c6cda4bb75e5339ae3c10623351
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161949
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-09-09 06:41:14 +00:00
Jens Johansen b4673b58b9 [parser] Better recovery of typedefs with missing 'Function' keyword
This CL improves recovery in situations like this:

typedef c = foo(int x);
 => recovers like typedef c = foo Function(int x);

typedef d = (int x);
 => recovers like typedef d = Function(int x);

typedef e = foo<F>(int x);
 => recovers like typedef e = foo<F> Function(int x);

typedef f = <F>(int x);
 => recovers like Function<F>(int x);

typedef g = foo<F, G, H, I, J>(int x);
 => recovers like typedef g = foo<F, G, H, I, J> Function(int x);

typedef h = <F, G, H, I, J>(int x);
 => recovers like typedef h = Function<F, G, H, I, J>(int x);

typedef i = <F, G, H, I, J>;
 => recovers like typedef i = Function<F, G, H, I, J>();

And appropriate error messages are given:
"Expected 'Function' before this." and (when inserting parenthesis)
"A typedef needs an explicit list of parameters.".

Fixes #26073.

Change-Id: I368f36f2993033d62b36315198bc993eed74bc92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161485
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-09-08 11:43:14 +00:00
Paul Berry a4b2047d9d Reland "Flow analysis changes to fix mixed-mode unsoundness loophole."
This is a reland of d833f2f65c

Original change's description:
> Flow analysis changes to fix mixed-mode unsoundness loophole.
> 
> This is the flow analysis portion of the fix to
> https://github.com/dart-lang/language/issues/1143.  Follow-up changes
> will be needed in the CFE and/or backends to ensure that exceptions
> are thrown under appropriate circumstances.
> 
> This CL also makes some improvements to flow analysis's reachability
> analysis so that it accounts for nullability of the target when
> analyzing the reachability of `??=` and `?.`.  Hopefully these
> improvements should make the fix to
> https://github.com/dart-lang/language/issues/1143 clearer and more
> consistent.
> 
> Change-Id: I5fa5c070f13fd57ac4c2fb87f2d67588861594b0
> Bug: https://github.com/dart-lang/language/issues/1143
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160440
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

Bug: https://github.com/dart-lang/language/issues/1143
Change-Id: If9c45649c1e9f4b19f7c282e7a1c4c956a7bc17f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161622
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-09-03 01:01:43 +00:00
Mike Fairhurst 3317d47c7d [_fe_analyzer_shared] Remove unused dart:async import
Change-Id: I6f34f9c00399a6edd15ac50d17c11675d0e11f6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161465
Auto-Submit: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-09-02 17:22:27 +00:00
Paul Berry ab16d79af9 Revert "Flow analysis changes to fix mixed-mode unsoundness loophole."
This reverts commit d833f2f65c.

Reason for revert: Broke build, e.g. https://ci.chromium.org/p/dart/builders/ci/dart-sdk-mac/12688

Original change's description:
> Flow analysis changes to fix mixed-mode unsoundness loophole.
> 
> This is the flow analysis portion of the fix to
> https://github.com/dart-lang/language/issues/1143.  Follow-up changes
> will be needed in the CFE and/or backends to ensure that exceptions
> are thrown under appropriate circumstances.
> 
> This CL also makes some improvements to flow analysis's reachability
> analysis so that it accounts for nullability of the target when
> analyzing the reachability of `??=` and `?.`.  Hopefully these
> improvements should make the fix to
> https://github.com/dart-lang/language/issues/1143 clearer and more
> consistent.
> 
> Change-Id: I5fa5c070f13fd57ac4c2fb87f2d67588861594b0
> Bug: https://github.com/dart-lang/language/issues/1143
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160440
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Paul Berry <paulberry@google.com>

TBR=paulberry@google.com,scheglov@google.com,johnniwinther@google.com

Change-Id: If1215b19975e0958d612dd69767088095d853879
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/language/issues/1143
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161580
Reviewed-by: Paul Berry <paulberry@google.com>
2020-09-02 15:02:46 +00:00
Paul Berry d833f2f65c Flow analysis changes to fix mixed-mode unsoundness loophole.
This is the flow analysis portion of the fix to
https://github.com/dart-lang/language/issues/1143.  Follow-up changes
will be needed in the CFE and/or backends to ensure that exceptions
are thrown under appropriate circumstances.

This CL also makes some improvements to flow analysis's reachability
analysis so that it accounts for nullability of the target when
analyzing the reachability of `??=` and `?.`.  Hopefully these
improvements should make the fix to
https://github.com/dart-lang/language/issues/1143 clearer and more
consistent.

Change-Id: I5fa5c070f13fd57ac4c2fb87f2d67588861594b0
Bug: https://github.com/dart-lang/language/issues/1143
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160440
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-09-02 14:27:52 +00:00
Johnni Winther 7130dd4d3d [cfe] Report error on non-void setter return type
This CL also adds fileUri/charOffset to all TypeBuilder's and renames
Void/FutureOr/Never/Dynamic/BuiltInTypeBuilder to *TypeDeclarationBuilder
so match their relation to TypeBuilder/TypeDeclarationBuilder.

Closes #42962

Change-Id: Iee5102134574d24f748103282a37bb9a85a0ac2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161165
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2020-09-02 12:43:12 +00:00
Konstantin Shcheglov ebc055b4d2 Prepare to publish analyzer 0.40.1 and _fe_analyzer_shared 9.0.0.
R=brianwilkerson@google.com, devoncarew@google.com

Change-Id: I2cf281ef7a3238e0313b6ab7aa9634278f72f122
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161420
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-01 22:04:12 +00:00
Jens Johansen 3a1f732c0f [parser] Make begin/end events always come in pairs
This CL:
* Changes the events so beginX and endX events always comes in pairs
  (though technically not right as some specific events can be beginX
  endY --- but in those cases it is at least documented and used in code
  that actually tests it).
  -> This entails adding some events and converting something from
    "beginX" to "handleX" instead.
* Adds a utility that can generate an AST of sorts directly from the
  parser via a listener using the begin/end matching (and knowing of the
  specific ones that doesn't match directly).
* Adds a test that checks that - at least for all tested (50,000+) files
  - the AST actually generate "correctly", i.e. matches up begin/ends
  and ends up with a single top entry "CompilationUnit".
* Adds a different visualization to the parser listener events by
  displaying the "AST directly from the parser" in a UI that can be
  navigated. The visualization may not be the best, but it's certainly
  a stepping stone.

Change-Id: I9b27f7bbf3be442adc92f357c7b3c46da6f84cf7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159664
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-09-01 09:30:43 +00:00
Jens Johansen 0967d19156 [parser] Fix assert error in scanner
If an identifier starts with a non-ascii-character and has a comment
an assert was triggered about the comment not being attached to the
token. This CL attaches the comment to the token (which it should be)
and thus avoiding the assert trigger.

Change-Id: Id261970b88ca721d4b3a996abfb8ff43f0ec8341
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161102
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-08-31 14:19:48 +00:00
Jens Johansen c679be7b8b [parser] Remove 'suppressParseErrors' from Listener
It was never called anyway.

Change-Id: I86cb58d1543476f1865f23eb9a107082a2f7f677
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159663
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-08-27 11:52:27 +00:00