Commit Graph

95 Commits

Author SHA1 Message Date
Paul Berry 0291de4bcf Migration: do not attempt to modify named expressions.
When a method call includes a named argument such as:

  f(named: x)

the analyzer represents the AST node `named: x` as an Expression.  But
it's not safe for the migration tool to try to modify it in the same
way that it modifies other expressions (e.g. by surrounding it with
`(...) as Type`), because that would produce a parse error.

Improves the analyzer behavior for #45583.  Note however that this is
not a complete fix yet; see the test case included in this CL for why.

Bug: https://github.com/dart-lang/sdk/issues/45583
Change-Id: I79ffcdd22654221ff7e0784b3355ecfd2ec0f01c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194008
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-06 05:02:16 +00:00
Paul Berry 0e8a84173e Migration: fix futures using .then rather than as
Previously, if the migration tool encountered a Future expression with
a bad type (e.g. a Future<String?> where a Future<String> was needed),
it would "fix" the problem by introducing a cast.  That is nearly
always the wrong thing to do; what we want to do is null check the
value that the future *completes* with.

This CL changes the migration tool so that it fixes this case by
appending `.then((value) => value!)` to the future expression.

Fixes #45472.

Bug: https://github.com/dart-lang/sdk/issues/45472
Change-Id: I7a35b54f673936e2e4b0f8f3a077ba8bf684b4eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193700
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-31 17:48:19 +00:00
Paul Berry 06682de751 Migration: Additional test cases for extension overrides.
These test cases were accidentally left out of
8ad4919482.

Change-Id: I2986e7d2763ff2ee0eea4800da185a5d45d69e1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180401
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-22 22:04:54 +00:00
Paul Berry 8ad4919482 Null safety migration: don't null check calls to extensions that permit null.
This partially addresses #44675 by ensuring that if an extension's
extended type is nullable, we won't try to insert an unnecessary null
check at the call site.

It's not a complete fix, though, because we still don't account for
obvious indications of non-null intent when analyzing the extension
definition itself.  I plan to address that in future CLs.

Bug: https://github.com/dart-lang/sdk/issues/44675
Change-Id: Ia0ca37b89470a2d4882ae32cd842552ffd34930e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180263
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2021-01-21 13:33:36 +00:00
Paul Berry 02b2e5398d Migration: permanently enable "transform where or null" feature.
This feature is now working reliably enough that we no longer need the
option of turning it off.

Change-Id: I2bbeb114ca1bd4e0dc8e94ac6775ec5e2fa8718e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171705
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-11-12 21:12:20 +00:00
Paul Berry 80ac9c999b Migration: update pubspec when adding import of package:collection.
Change-Id: Ia9e5090bafa7f67be87aa01367bec16f4fd80ee9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171701
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-11-12 21:12:20 +00:00
Paul Berry 65eb643181 Migration: don't produce null!.
Instead, produce `null /*no valid migration*/`.  This should lead to
less user confusion (`null!` seems crazy, since obviously a null
literal will fail a `!` check).  Note that this will be a static
error, which will give the user a better chance of noticing and fixing
the problem.

Fixes #43972.

Bug: https://github.com/dart-lang/sdk/issues/43972
Change-Id: Ibf83b786dc486b14c001c17ca2ba902dafcb8a18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169600
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-29 18:34:36 +00:00
Paul Berry a666ac7ffa Migration: add preview info when changing iterable method calls.
With this change, the functionality of changing iterable method calls
such as `.firstWhere` into extension method calls such as
`.firstWhereOrNull` is working well enough that I think we can switch
it on.

We don't update the pubspec properly yet; that will be addressed in
follow-up CLs.

Change-Id: I758332e9752b12d399ecb5c70cf37bbc8da77d6c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168988
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-25 18:57:35 +00:00
Paul Berry f1843b0abe Add special case migration logic for iterator methods.
This logic allows us to migrate code like this:

    int firstEven(Iterable<int> values)
        => values.firstWhere((i) => i.isEven, orElse: () => null);

Into:

    import 'package:collection/collection.dart' show IterableExtension;

    int? firstEven(Iterable<int> values)
        => values.firstWhereOrNull((i) => i.isEven);

Rather than the default behavior, which would migrate it to:

    int? firsteven(Iterable<int?> values)
        => values.firstWhere((i) => i!.isEven, orElse: () => null);

(The new migration is far superior because it doesn't require the
input iterable to accept null).

This functionality is disabled at the moment, because:
- The changes it makes don't show up properly in the web preview.
- The pubspec is not yet properly updated.

I will address these issues in follow-up CLs and then enable the
feature.

Change-Id: I96f3b12d682c586631920b38406bad6aa3f4789e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168500
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-20 17:45:04 +00:00
Konstantin Shcheglov 8de1bc0a07 Stop using getReadType() in nnbd_migration.
The packages 'analyzer' and 'nnbd_migration' tightly depend on each
other via MigrationResolutionHooks. I will publish analyzer 0.40.4
shortly after this CL lands.

Change-Id: I6f5e51f88e0020a1674ffb251712658e896170e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164900
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-09-29 17:18:25 +00:00
Paul Berry 2cb426f9fc Fix context type for compound operators.
This is partially in support of the new numeric typing rules for null
safety, however it turned out that the anaylzer wasn't setting the
context type properly even in legacy code.  I've fixed both legacy and
null safe behaviors and included tests to cover both.

Fixes #39642.

Bug: https://github.com/dart-lang/sdk/issues/39642
Change-Id: Ie4d0936d335b1f750eae4febe76f2b8879c228b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159965
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-08-26 18:21:05 +00:00
Paul Berry 08dd4b1faa Null-safe numbers: implement static typing rules, hook up for binary operators.
Future CLs will hook up the static typing rules for method calls
(`clamp` and `remainder`) and will implement the rules for contexts.

Bug: https://github.com/dart-lang/sdk/issues/42629
Change-Id: Iccfb1fa1ac9aff6c0832d65e4835b5b9bd51a804
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158501
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-08-24 15:34:33 +00:00
Paul Berry f907e561c9 Migration: never produce a type of the form FutureOr<T?>?.
`FutureOr<T?>` is already nullable, because `FutureOr<T?>` ==
`FutureOr<T | Null>` == `Future<T | Null> | T | Null`.  So the second
`?` is redundant.

Also fix a bug where we were treating a `Null` type as `Never` if we
couldn't find a reason to require it to be nullable; this was
inconsistent with how the FixBuilder was handling `Null` (which is to
leave it unchanged).

Change-Id: I5e0e4b7fb449988d8ff0dd87a2b4c3da4a6ecebb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155506
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-07-23 13:24:48 +00:00
Mike Fairhurst e11eb2cd08 [nnbd_migration] Fix #42263, tool inserting ! on toString/hashCode
Fixed: 42263
Change-Id: Ia4c6d3543bc7628c76b85d986b9709de58925884
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151441
Auto-Submit: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-06-16 20:21:31 +00:00
Paul Berry 96c2cc2589 Migration: fix class hierarchy handling in FixBuilder.
When running the FixBuilder we need to override the behavior of
ClassElement.interfaces so that it returns the post-migration
interface types.  We also need to override the behavior of
LibraryElement.isNonNullableByDefault so that the library being
migrated is considered opted in during FixBuilder analysis.  This
required adding hooks to the analyzer to allow those overrides.

Additionally, since the analyzer caches the InheritanceManager, we
need to clear that cache out just prior to running the FixBuilder, so
that no pre-migration interface types leak into the FixBuilder.

Fixes #40475.
Fixes #42139.

Change-Id: I45e2c30ebe8c12e4a599e2458d77a3731bad0f98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150260
Reviewed-by: Janice Collins <jcollins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-06-08 17:26:41 +00:00
Paul Berry 13b3d67278 Migration: test interactions between type promotion and new compound assignment diagnostics
Change-Id: I31d0389872640a54c962976754e65c3e2aeb2f1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145981
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-05-05 02:18:13 +00:00
Paul Berry eb3a42b789 Migration: test interactions between null-shorting and new compound assignment diagnostics
Change-Id: Ia46aaf380fad1c65b59fff214217658cfcaee973
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146000
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-05-04 23:02:17 +00:00
Paul Berry b71d09542c Migration: extend compound assignment diagnostics to ++ and --.
Bug: https://github.com/dart-lang/sdk/issues/38676
Change-Id: Iab5097359d8de7aa9411f51ee0ec6212c3adb678
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145920
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-05-04 23:02:17 +00:00
Paul Berry 2846ec88b3 Migration: test that new compound assignment checks respect potential nullability
Bug: https://github.com/dart-lang/sdk/issues/38676
Change-Id: I344a9c9ea1e79af864c239dbcc924f78e798a8aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145900
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-05-01 22:54:25 +00:00
Paul Berry bf56b2ca2c Migration: produce diagnostic information for assignments.
We produce a diagnostic under the following conditions:

- For compound assignments, if the type read from the LHS is nullable
  (this is illegal after NNBD, and requires user intervention to fix).

- For compound assignments, if the type returned from the combiner is
  not assignable to the LHS (this was required prior to NNBD, but it
  is a stricter condition after migration, both because the LHS might
  have a non-nullable type, and because implicit downcasts are not
  allowed).

- For null-aware assignments, if the type read from the LHS is
  non-nullable (this indicates that once strong mode is enabled, the
  assignment will be dead code).

Bug: https://github.com/dart-lang/sdk/issues/38676
Change-Id: Icb242ba36437e38364ada069880831eb05e3a513
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145664
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-05-01 22:54:25 +00:00
Paul Berry 8d79c1f470 Migration: allow assignment to de-promote local variables.
Fixes #41411.

Bug: https://github.com/dart-lang/sdk/issues/41411
Change-Id: Ia88216e3327f42ee1d93143afb2a66839cf05a2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144161
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-04-28 13:54:28 +00:00
Paul Berry 4c8da7543e Migration: handle field formal parameters properly in FixBuilder.
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>
2020-04-20 19:09:32 +00:00
Paul Berry 925e3fe782 Migration: detect weak-only code in conditional expressions.
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>
2020-04-20 19:09:32 +00:00
Paul Berry 3dff7f31a7 Migration: rename isEliminateDeadIf to isConditionalWithKnownValue
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>
2020-04-20 17:26:26 +00:00
Paul Berry 5eb399388e Migration: when not removing weak-only code, visit all subexpressions.
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>
2020-04-20 17:26:26 +00:00
Paul Berry fdc13e3f43 Migration: remove hints when performing migration.
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>
2020-04-17 00:17:15 +00:00
Paul Berry 1d3105e0b3 Migration: prioritize changes differently if they're due to hints.
Change-Id: I4dfdd0287e488dfac21923c71741d2218a2c070c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143334
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-04-14 23:33:46 +00:00
Paul Berry 46b49d23ec Migration: track multiple fix reasons for expressions with complex types.
Change-Id: I1a1f78377ed64504e5315b5096914219dc625e78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143188
Reviewed-by: Janice Collins <jcollins@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-04-14 23:33:46 +00:00
Paul Berry 03c15848d6 Migration: distinguish inserted casts based on whether they are downcasts.
Inserted casts that aren't downcasts are much less likely to be safe
than inserted downcasts.

Change-Id: I21e0ef54b1c4d58c54724a510b25828fc3018142
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142552
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-04-07 18:35:56 +00:00
Paul Berry 8c982a1373 Migration: categorize changes shown in the preview tool.
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>
2020-04-07 18:35:56 +00:00
Paul Berry b7130b0bf7 Migration: improve preview tool display when ! is added due to an explicit hint.
Change-Id: Ie9b2a6cabaf02c46da2e8b8ac1bffa0e699acc64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141741
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-03-31 22:04:46 +00:00
Mike Fairhurst 2eaa5bcec6 [nnbd_migration] Handle removing language comments after other comments
Change-Id: Iecee603fbef5ff2d0f822728b9ae0d83967afc21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140770
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-03-26 03:47:57 +00:00
Mike Fairhurst f10e1ed253 [nnbd_migration] Fix #38462, remove @ for @required nullable params
Change-Id: I755cd261a812a714f03cc09b1858d4925e98f88f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140907
Commit-Queue: Paul Berry <paulberry@google.com>
Auto-Submit: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-03-25 19:40:24 +00:00
Paul Berry 08c6dd6164 Migration: add FixBuilder support for expression null check hints.
Previously, null check hints were only affecting the behavior of
EdgeBuilder, which meant that we handled simple cases like:

  int f(int/*?*/ x) => x/*!*/;

(because the EdgeBuilder wouldn't build an edge from the type of `x`
to the return type of `f`, so the return type of `f` would be
non-nullable int, and hence the FixBuilder would insert a `!` in order
to prevent an error).

But if there were some *other* reason for the destination type to be
nullable, then no `!` would get inserted.

This CL adds explicit logic to the FixBuilder to ensure that a `/*!*/`
hint causes a `!` to be inserted whether it's necessary or not.

Change-Id: I283bb9793d8d01408333f5b56562286bf19d8773
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140904
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-03-25 19:38:34 +00:00
Mike Fairhurst 799560bff7 [nnbd_migration] Remove language version comments during migrate
Bug: 41095
Change-Id: I3262d6da485d78fee1e2dfe4ac22692c5e4b6daf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140369
Reviewed-by: Janice Collins <jcollins@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-03-24 16:44:05 +00:00
Paul Berry 41b67a9b52 Migration: add grayed-out spaces to indicate types not being made nullable.
Change-Id: I4fa076693c25cf9466d33332030df3983043ffd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139940
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-03-18 21:18:22 +00:00
Paul Berry 4b9b46ef01 Migration: improve specificity of FixBuilderTest.isMakeNullable
Change-Id: Ibef1db9d1426cc4e8a5e7286f26887504352a767
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139751
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-03-17 17:19:41 +00:00
Konstantin Shcheglov c9884ccf52 Analyze SDK with non-nullable experiment enabled, update MockSdk.
Initial:  https://dart-review.googlesource.com/c/sdk/+/134401
Reverted: https://dart-review.googlesource.com/c/sdk/+/134802

Internal presubmit is green.
https://test.corp.google.com/ui#id=OCL:294345942:BASE:297377939:1582738004318:fb4ae9fe

Change-Id: I25e6445bd0241a89850dff3d88ece0edd768053a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135241
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-02-26 21:08:21 +00:00
Paul Berry 2fa27b5d57 Introduce a "postmortem output" for nullability migration.
The postmortem output is currently only generated if the static
constant NullabilityMigrationImpl._postmortemPath is non-null.  The
generated file can be analyzed using
pkg/nnbd_migration/tool/postmortem.dart.

Change-Id: Ic5bf7aecc4176306839c00237eed668c2cd42571
Bug: https://github.com/dart-lang/sdk/issues/40624
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136003
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-02-19 16:44:40 +00:00
Paul Berry a017944035 Migration: fix hard crash in trial_migration when migrating package:async.
There were two problems:

1. An info object isn't being properly passed to
   NodeChangeForExpression, causing an assertion failure during the
   FixAggregator stage.  I've modified the assertion check so that it
   happens earlier, during the FixBuilder, so that the exception is
   caught by permissive mode logic and doesn't cause a hard crash.
   I'll work on fixing the assertion in a follow-up CL.

2. The hack described in https://github.com/dart-lang/sdk/issues/40536
   was causing a bogus assertion failure in
   _PassThroughBuilderImpl._checkParenLogic.  I've weakened the
   assertion slightly so that for now, the hack won't cause trouble.
   See the issue for more information about what's happening--this
   should be cleaned up eventually but it's probably not high
   priority.

Bug: https://github.com/dart-lang/sdk/issues/40533
Change-Id: Iee832fbd07e54b02d2c52f79a097ff9d973cda9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134980
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-02-10 20:19:54 +00:00
Konstantin Shcheglov 1f47e5b23d Revert "Analyze SDK with non-nullable experiment enabled, update MockSdk."
This reverts commit 545b80ef0e.

Reason for revert: this is a breaking change for MockSdk users, actually much more serious issue for un-forking SDK. https://github.com/dart-lang/sdk/issues/40500

Original change's description:
> Analyze SDK with non-nullable experiment enabled, update MockSdk.
> 
> Change-Id: I80264a6533045c33ed794a5938f6719f3b5a6d0b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134401
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>

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

Change-Id: If8c3d8322986b01012fa76f9c928f35309c00e3e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134802
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-02-06 22:55:29 +00:00
Konstantin Shcheglov 545b80ef0e Analyze SDK with non-nullable experiment enabled, update MockSdk.
Change-Id: I80264a6533045c33ed794a5938f6719f3b5a6d0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134401
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-02-06 18:04:02 +00:00
Paul Berry fecab44f59 Migration: Improve the tracking of type parameter bounds.
This CL extends ElementTypeProvider so that it also tracks type
parameter bounds.  This allows the FixBuilder to reason correctly
about the what generic function types will look like after migration,
and that in turn prevents it from trying to add unnecessary casts.

Change-Id: I3c909a3b5ba14bf9f2aad4e58d0981c1b7b5bdd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134412
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-02-05 20:51:49 +00:00
Paul Berry 655fcda015 Migration: rework how ElementTypeProvider overrides element types.
Previously, each piece of analyzer code needed during the FixBuilder
stage of migration needed to use the ElementTypeProvider interface to
access element types (rather than reading the types from the elements
directly), in order to ensure that the proper post-migration types
were used when building fixes.  This required a lot of plumbing, and
there was a high risk that we would accidentally fail to use the
indirection mechanism in a key location and access the elements
directly.

This CL changes the approach so that the ElementImpl classes
themselves are responsible for indirecting through
ElementTypeProvider.  This means that we can back out all the
plumbing, and there is no risk of accidentally failing to use the
indirection mechanism.

Change-Id: Ic1a0acc37f0350fc13b487f73fc1ad5225d7a090
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134360
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-02-04 22:29:20 +00:00
Paul Berry 763ce812ea Migration: properly handle type parameter types with nullable bounds.
This required adding logic to the `TypeParameterType` case of the
`toFinalType` function, so that we look up the decorated type of the
type parameter bound, and convert it to a final type as well.
(Previously we were just using the bound stored in the element model,
which was in many cases the bounds from prior to migration, and hence
it was a `*` type so it behaved as though it was non-nullable).

This required moving `toFinalType` into the `Variables` class so that
it could look up the decorated types of type parameter bounds.

Fixes #40355.

Change-Id: I53c2636aef6954500589e924b9755a297c2b30f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134061
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-02-03 19:59:38 +00:00
Paul Berry ab6d0ef178 Migration: change implicit downcasts to explicit ones when necessary.
Note that downcasts from dynamic may still be implicit.

Fixes #38481.

Change-Id: I35558ed3578707cc640108b85790adb042e88ee2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133865
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-30 21:33:12 +00:00
Paul Berry 208d8c2e52 Migration: Rework FixAggregator to reduce order dependencies.
Previously, FixAggregator provided one NodeChange-derived class for
each possible kind of fix; if multiple fixes had to be made to a
single AST node, its client (FixBuilder) was required to nest them in
the appropriate order.  FixBuilder accomplished this by carefully
controlling the order in which it decided on fixes.  Unfortunately,
this careful control of order is becoming burdensome for FixBuilder to
maintain.

With this change, the class hierarchy of NodeChange mirrors the class
hierarchy of AstNode, with different fields for each possible kind of
fix.  This means that FixBuilder can decide on fixes in whatever order
is convenient.

Change-Id: I1c79cfc37b6289051b3927c67867b77a1dbb5ebf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133541
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
2020-01-29 18:30:46 +00:00
Paul Berry 2edd8d17c0 Migration: replace ?. with . where appropriate.
Change-Id: Id32f60caec0c25099704652c03fafc8b184bf4d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133241
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-01-24 19:58:43 +00:00
Paul Berry 0673525175 Migration: add permissive mode support to FixBuilder
Change-Id: If9a82fc274ea89089df0c3b17bae02ba564a74ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132943
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-22 22:59:39 +00:00
Paul Berry 47950b5153 Migration: add logic to remove unnecessary "as" expressions.
Only works when the FixBuilder is enabled.

Change-Id: I9f2ee95603f9b6b247eae1ba00e817a71fc299d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132681
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-01-22 00:05:34 +00:00