This makes the implementation consistent with the spec text in
1ed6bab4cc.
Change-Id: Ie25b928c5aacb45a18e85c6f9196b5b55f083478
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152983
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The handling of null shorting in the variable initializer interfered with
the declaration of the variable, making subsequent flow potentially
losing track of promotions.
Closes#42504
Change-Id: Idb17920ffe8746983825714f76160abcca54751b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152760
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
At the top of a loop, loop-assigned variables need to be marked as not
definitely unassigned, otherwise we will give incorrect results for
code like this:
```dart
f() {
late int x;
bool firstIteration = true;
while (true) {
if(firstIteration) {
x = 0;
firstIteration = false;
} else {
print(x); // BOGUS ERROR: x definitely unassigned
}
}
}
```
Previously, we were handling this by calling `joinUnassigned` at the
bottom of `removePromotedAll`, but it's simpler to just mark these
variables as not-unassigned while discarding promotions. This change
will make the implementation more closely match spec changes I'll be
making shortly.
Change-Id: If50e28d20a75730aa5187a62ae5cac8690b0dfaf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152861
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Fixes https://github.com/dart-lang/sdk/issues/42375
EdgeBuilder wishes to do its own GLB type-joining, as does FlowAnalysis.
When FlowAnalysis pushes a promotion in ifNullExpression_rightBegin,
and then in write, and then pops those two promotions to join them in
ifNullExpression_end, EdgeBuilder is not given a chance to make its
own GLB node. Instead promotion never happens: the DecoratedType which
is the variable's type is promoted to non-nullable, for the left side.
The DecoratedType for the right side expression is not considered
non-nullable, so the FlowAnalysis.join will always fail to promote.
TypeOperations.adjustPromotedTypes solves this. It is a no-op in all
implementations except in EdgeBuilder.
Additionally FlowAnalysis.write's promotion fails for the same reason:
the only type of interest is the declared type made non-nullable, and
no matter what, the writtenType is not a subtype of this.
TypeOperations.forcePromotion solves this. It is a no-op in all
implementations except EdgeBuilder.
Change-Id: Iba6b9a69583af8fe1aa23124c7d66047acfff495
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152104
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Rationale: internally we patch a number of diagnostic messages to add context to messages (and corrections). Introducing maps that allow for customization makes the internal patching process far easier and less prone to error.
Change-Id: I2d1e7488b451654dd24b8ae95647619c65d3974b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151664
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: David Morgan <davidmorgan@google.com>
This CL adds a Node.toText method together with an AstPrinter. These
facility and better toString implementation on AST nodes while allowing
for toString independent printing of AST to use in testing. This also
add support for an integrated toString of custom/internal nodes.
Some work is still needed in bringing the toString implementation on
all nodes to the old quality, and not all internal nodes have
customized textual representations yet. This work is left for future
CLs.
Change-Id: Ib0bf8a0bc02f489dfacdc8aa5f96da9c52f26058
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150923
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Remove false comment that was left in by accident when changing
typedef recovery.
Change-Id: I1b2a24664775a0405c8bf04233c5db1e27b53c73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150362
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
This CL embeds the sdk_nnbd/lib/_internal/allowed_experiments.json
into the CFE and uses this to allow experiments enabled on a
per library basis. The file is embedded through generated code to
avoid reliance on access to the file itself.
A presubmit check is also added to ensure that the json file and
the generated code are in sync.
This work is in preparation for https://github.com/dart-lang/sdk/issues/41538
This was reverted in https://dart-review.googlesource.com/c/sdk/+/149620
because flutter wasn't prepared for auto-enabling nnbd in dart:* libraries.
This has now been fixed in https://github.com/flutter/engine/pull/18714Closes#42162
Change-Id: I686ed6feaef8ee066b426068fe2a0f5080bf1713
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149588
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
This CL embeds the sdk_nnbd/lib/_internal/allowed_experiments.json
into the CFE and uses this to allow experiments enabled on a
per library basis. The file is embedded through generated code to
avoid reliance on access to the file itself.
A presubmit check is also added to ensure that the json file and
the generated code are in sync.
This work is in preparation for https://github.com/dart-lang/sdk/issues/41538
Change-Id: Ic03c0fc69684d124c685f2fe6e80423a7e751530
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149064
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
This is no longer valid. Since the SDK is agnostic we should default to weak mode.
Change-Id: Ia9fbf911e7ebb595c93a71afe3bb8de7495cebba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149065
Reviewed-by: Jens Johansen <jensj@google.com>
My recent revert (275b922ee8) mistakenly
reverted too much (I incorrectly attributed the angular failure to
1f9b5c1996 when it was actually due to
96df1f9e6c). Reapply the commits that
are ok.
This re-applies commit 1f9b5c1996.
This re-applies commit c40b24da48.
Change-Id: I4d64b1511b92d87197a5e939903a31e01f0b2e70
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147920
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Commit 1f9b5c1996 causes tests to fail
in angular when rolled into internal sources; the other two commits
need to be reverted as well to avoid merge conflicts.
This reverts commit 1f9b5c1996.
This reverts commit c40b24da48.
This reverts commit 96df1f9e6c.
Change-Id: Ic4e55181ef60e825ce4409a9a9528ecbf19c39c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147822
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
These were for some reason not updated by the update_all script on the
first run.
Change-Id: I49dc1f5524c120947a971356548755325c63e8d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147360
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Errors involving superinterfaces in class declarations will now mention
both the type alias and the unaliased type, e.g., in cases like
`class A extends T {}` where `typedef T = void;`.
Change-Id: I5bb575b98329e8338560d1ee5dc18e71da9711e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146720
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
This is the second part of the referenced issue.
Practically, we don't do anything special during demotion, we merely
demote when write T to such type S, that T <: S. This S must be a
type of interest (tested or declared). If it happens to be nullable,
and T < NonNull(S), we will promote to NonNull(S).
Bug: https://github.com/dart-lang/sdk/issues/40011
Change-Id: I254b4bfbbfad47fa2c2811def864c8ce0419b7c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145740
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
No semantic changes, I think.
Just a step closer to what the spec says.
R=paulberry@google.com
Change-Id: I3b27c3daa3b93d425ede56bc1b2b1056210135d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145243
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
So, we can use exact type for TypeOperations, and it will be convenient
for implementing promotion via initialization.
R=paulberry@google.com
Change-Id: I5b1243d5a4ac95f92ee1d08e6ed64be09e8c8f53
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145306
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>