Fixes https://github.com/dart-lang/sdk/issues/38291
This change also involves moving the "package" where test sources are
written and analyzed; It used to be /home/test (or /project in some
places); and a pubspec.yaml was written (or a .packages file) which
specified the package's name was "test". However, this conflicts with
adding an entry for a mock copy of the actual _test_ package. A
.packages file cannot have two entries for a package named "test", so
the package where all test sources are written is changed to "tests"
(located at /home/tests).
Change-Id: I462b88a814931dc2d4f1e72d07e3daf64768a399
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144994
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Without this, it's possible for a unit test failure to result in a
preview server remaining open, which can prevent test execution from
terminating.
Change-Id: I8a11056da5bea003dfa46e3871a241e8f5ce8cc1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145440
Reviewed-by: Janice Collins <jcollins@google.com>
We really should switch this, if possible, to use the edit kind APIs
that the preview tool uses, so that we can categorize this without
guesswork.
However this will keep it as a rough list, and I don't know if we need
anything fancier that currently -- and it will no longer produce noise
if new changes are added.
(currently produces "and 0 other changes" when running on flutter, so
it's probably mostly comprehensive currently).
Change-Id: I9cb2662995af340346a61d38eba3469927a0f4ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145160
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
This mechanism is simpler, and it has the advantage that if the
preview server fails to start for some reason, we get a useful failure
message rather than a timeout.
Change-Id: I6ead899b3af02431c2a022fa104c6596ff952917
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145142
Reviewed-by: Samuel Rawlins <srawlins@google.com>
This will allow us to publish the migration tool on pub, so that we
can ship improvements to it that aren't coupled to SDK releases.
As of this CL, basic read-only functionality of the preview site is
working. However, the ability to apply migrations and add hints to
existing code has not yet been tested.
Change-Id: Ib1588e741efa7be7861fa75b962fd1565765e794
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144808
Reviewed-by: Janice Collins <jcollins@google.com>
Originally, edit links were implemented as generic "post links," that
had no special handling except to fire a post request.
At this point, this is no longer the case. We at least want to
specialize the error message, and we have TODOs to do more
specialization (targeted reloading of the UI).
Note that 'edit-link' is already a class, it refers to the edits the
migration tool suggests as the migration. Therefore I used the class
'add-hint-link' instead of 'edit-link.'
Lastly, post-links were styled like buttons. But they are not the only
links that should be styled as buttons now, so just use that class
instead of having special styling.
Change-Id: I8241a5ec24e6a290b94a75327c06257abdfc011b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144660
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
NonNullableFix now communicates with DartFixListener through the
abstract interface DartFixListenerInterface; this will allow us to
build a version of DartFixListenerInterface that doesn't require the
analysis server.
Change-Id: I106d769b0e6ed49a916e2f1665a7e31a9a63be86
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144471
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
The migration logic doesn't need to access the AnalysisDriver object;
it just needs access to the AnalysisSession (which the driver holds).
By changing the interface so that it requests the session directly, we
pave the way for making a version of the migration tool that doesn't
require the analysis server.
Change-Id: Ib99725bbb2c1728a4c57b46659e9d94cbfe65ee0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144470
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
This removes most of the imports from nnbd_migration to
analysis_server by replacing them with abstract interfaces that are in
turn implemented by classes in analysis_server.
Change-Id: I9be9a5bd69b1664f0fea9ff3b6ba4678f134f0e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144468
Reviewed-by: Janice Collins <jcollins@google.com>
Previously, all parameters returned by
MigrationResolutionHooksImpl.getExecutableParameters were synthetic
ones that came from translating the executable element's decorated
function type to its final post-migration type. Synthetic parameters
can't be field formal parameters, so this meant that when the
FixBuilder was re-resolving a constructor containing field formal
parameters, references to the field in the constructor body would get
incorrectly interpreted as pointing to the parameter rather than the
field, and that would cause them to be subject to promotion.
The fix is to only return synthetic parameters from
MigrationResolutionHooksImpl.getExecutableParameters when the
executable in question is in a library *not* being migrated. When
it's in a library that *is* being migrated, we can just return all of
the executable's parameters without translating them, because we know
that the parameters themselves have been visited by the NodeBuilder
and EdgeBuilder, hence they all have thier own associated decorated
types.
Fixes#41405.
Change-Id: I5e3c411dc92fe242a959a5670b9253fbccea2b31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144122
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Consider the following code:
int f(int i) => i == null ? null : i + 1;
Previously, migration would mark the return type of `f` as nullable
even if `i` was non-nullable. This happened because the edge
connecting the explicit `null` (in the "then branch" of the
conditional) to the return type of `f` is created after visiting the
conditional expression, so the condition guards are no longer in
scope.
With this CL, we create an extra graph node when needed to ensure that
the guard is applied to the expression type.
Change-Id: Ie00eea0b431905241612c6661d69bdb55c0910d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144121
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
This change adds the ability to detect when one branch of a
conditional expression is weak-only due to nullability. For example,
in the following code:
int f(int/*!*/ i) => i == null ? g(null) : i;
int g(int j) => ...;
the call to `g` can only happen in weak checking mode. The migrator
also now understands that j only needs to be nullable if i is
nullable.
Fixes#41555.
Partially addresses #41551.
Bug: https://github.com/dart-lang/sdk/issues/41555
Change-Id: I02c9c3072f0104db0f1a5b432fb1f2f8f06d5282
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144120
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
The new name more accurately reflects the purpose, and will make tests
less confusing when we add analysis of weak-only conditional
expressions in a follow-up CL.
Change-Id: I388f68173a1b41456690ebd0082e9c8d0ebe2e06
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144003
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
In the FixBuilder, when we are discarding one of the branches of an
if-statement or if-element due to it being weak-only, we only visit
the branch we're keeping; this avoids trying to make changes to code
that's being removed. However, if we are keeping both branches and
simply warning about one of them being weak-only, then we need to
visit both branches so that fixes are applied to both of them.
Change-Id: I26a1bfcb5f2ef4a111b1117637bce74e42d3db07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144000
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Previously, the spaces inserted by EditPlanner.addCommentPostfix
didn't carry the correct isInformative flag, so they would show up in
final migrated output.
Change-Id: I100ba88040ebff9ae5d406c49b242f6fb17ce7b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143887
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Previously we considered such code "dead", but it's not really dead
until Dart 3.0. Removing it changes weak mode semantics, and we don't
want to do that automatically.
Fixes#41231
Change-Id: I6a88f016b4f3fcba160dcb738558867219715cbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143941
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Technically, accepting a hint requires two edits, one to remove the
`/*` and one to remove the `*/`. But we only want it to show up as
one edit in the "Proposed Edits" pane.
Fixes#38471
Change-Id: Ica7880a2ffab98715a1c9f3bbe723363fd481086
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143484
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Previously, if we migrated a code snippet like this:
void f(int/*?*/ i) {
/*late*/ int j = i/*!*/;
}
the migration result would leave the hints and add the hinted text,
resulting in:
void f(int?/*?*/ i) {
/*late*/ late int j = i!/*!*/;
}
We now simply remove the `/*` and `*/` surrounding each hint (with
whitespace corrections as needed), to produce:
void f(int? i) {
late int j = i!;
}
Change-Id: Ic4e1216cb4693d73d71c9ab1a37d5cc15b8ef334
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143460
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Currently these are just equal to sourceNode.offset and sourceNode.end
respectively. In a follow-up CL, I'll introduce situations in they
might differ (in particular, the edit might include changes to a
nullability comment that precedes or follows the sourceNode).
Change-Id: I1c728454bafe9b154662dbb4c21d28fc62415abf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143340
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
We should only set the listener to non-null in permissive mode, since
a non-null listener is the signal to FixBuilder that it should report
expections rather than letting them bubble up the stack.
Change-Id: Ief047a54a5c8d63369420370e0ab891d03ce287f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142551
Reviewed-by: Samuel Rawlins <srawlins@google.com>
We now sort changes into the following categories (in order):
- Dead code removals
- Casts added
- Null checks added
- Required keywords added
- Types made nullable
- Casts now unnecessary
- Language version comments removed
The reasoning is that this corresponds roughly to how important it is
for a human to inspect each kind of change to make sure it is safe
(dead code removals, for example, are highly likely to indicate an
incorrect migration, where as dropping of unnecessary casts is benign
and almost certainly correct).
Change-Id: I49e3adac3ac98de1a9298f9caadb76c73a9c67d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142542
Reviewed-by: Janice Collins <jcollins@google.com>