Commit Graph

233 Commits

Author SHA1 Message Date
Konstantin Shcheglov db2aceaa42 Add getResolvedLibrary2(), deprecate getResolvedLibrary().
Change-Id: If502203708ed4c6a64e7054c2b12970eac11755b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195497
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2021-04-17 16:51:07 +00:00
Paul Berry 4e353ca98d Migration: properly assign types to collection literals.
Fixes #45583.

Change-Id: Ic411856968ec68b5ee6dd74718d08a4e9ea9c0d3
Bug: https://github.com/dart-lang/sdk/issues/45583
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195160
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-15 17:15:47 +00:00
Paul Berry 3186fa521e Migration: handle more complex extension method invocations.
Fixes #45574.

Bug: https://github.com/dart-lang/sdk/issues/45574
Change-Id: Iecf7acfebc1c59e5518edec4b8c287996d80c80d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194100
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-14 22:56:46 +00:00
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 32806f2e8d Migration: fix handling of loadLibrary.
Fixes #45396.

Bug: https://github.com/dart-lang/sdk/issues/45396
Change-Id: I150a1ded64ae2c22e5598d2023e605a45ddfe680
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193041
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-25 20:29:34 +00:00
Paul Berry a93a9a05a8 Migration: handle references to property accessors in extensions.
Fixes #42529.

Bug: https://github.com/dart-lang/sdk/issues/42529
Change-Id: I46be5511bf3929ba08da62bdc6ac6c85a307d0ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180400
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-21 19:04:12 +00:00
Paul Berry 5569f10236 Migration: infer non-null intent for this in extensions.
Since `this` is essentially a variable in extensions, it should be
treated similarly to variables in terms of inference of non-null
intent; for example, if an extension declaration contains a a method
that unconditionall dereferences `this` (either implicitly or
explicitly), that's a good indication that the user probably doesn't
intend for the extension to be applied to nullable types.

Fixes #44675.

Bug: https://github.com/dart-lang/sdk/issues/44675
Change-Id: I004328f5b1fd6710954363c07f4e9db6bc6ac2cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180268
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-21 13:33:36 +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 21bc3980fd Null safety migration: fix non-null intent in the presence of write captures.
After a variable is write captured, references to it should no longer
be considered to express non-null intent, because we can no longer
guarantee that an initially null value of the variable would
definitely lead to an exception.

Change-Id: I44c65350291a4c44cdb4b19529b13149d8170e34
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180100
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-20 14:15:15 +00:00
Paul Berry 5df3d0f5f7 Null safety migration: fix non-null intent inference in the presence of local functions.
Previously, code inside of local functions was treated as though it
appeared inline for the purpose of determining non-null intent.  As a
result, a return statement in such a local function would cause any
code references that followed to be incorrectly treated as *not*
expression non-null intent.

Fixes #44703.

Bug: https://github.com/dart-lang/sdk/issues/44703
Change-Id: Ia74da007eb5424c784d41afeb0e2da4771578553
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180081
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-20 05:40:26 +00:00
Paul Berry 306eb2fd97 Null safety migration: fix late inference when there is non-null intent
Previously, the nullability graph propagation algorithm identified
non-null intent prior to inference of `late`.  As a result, late
inference would be skipped for any variable with clear non-null
intent, so late inference was a lot less effective than it should be.

This requires updating several test cases where `late` should have
been inferred.

Change-Id: I0412ee7045e654185af08cc12b6ca1e6866112af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180080
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2021-01-20 05:40:26 +00:00
Paul Berry 011f98c959 Invoke flow analysis for if-elements during null safety migration.
Fixes #44702.

Bug: https://github.com/dart-lang/sdk/issues/44702
Change-Id: I70e50722572553dca42b21cea9aff010bd978bfe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180000
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-01-19 18:20:32 +00:00
Paul Berry 1bfcc2d8da Migration: handle for-each loops where the loop variable is not local.
Fixes #44071.

Bug: https://github.com/dart-lang/sdk/issues/44071
Change-Id: I6a1a9df22f70086860c36108e529f189d3d24875
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174565
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-12-02 15:00:53 +00:00
Paul Berry e047dd60d6 Ensure that function elements inside local variable elements have unique locations.
Fixes #44216.

Bug: https://github.com/dart-lang/sdk/issues/44216
Change-Id: I5ccf8bb5f90396eabfec470a289a193d2aef16ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173881
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-25 13:39:04 +00:00
Paul Berry f0d56055b6 Migration: handle is expressions where the type is a function type.
Change-Id: Ibdcb4a49bd51e218e58a52a3e2f32bef55bce61e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173020
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-20 12:26:36 +00:00
Paul Berry 4bde77e3c4 Migration: fix test_this_inside_extension.
This functionality is working now, the test was just broken.

Bug: https://github.com/dart-lang/sdk/issues/39387
Change-Id: I088a3bd40ac438d0a9cd2356badfaf9513aa4bbb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172280
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-16 21:21:06 +00:00
Paul Berry c0586277d7 Migration: fix handling of extensions on generic and function types
Bug: https://github.com/dart-lang/sdk/issues/39387
Change-Id: I037d29355dc86c071acc8dcc6f417a95e96e9728
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172200
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-16 17:11:58 +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 7322bc027e Migration: replace pub outdated check with a check on transitive imports.
Instead of running `pub outdated` to see if the user's dependencies
have been migrated yet, the migration tool now examines all of the
transitive import dependencies of the user's code to see if they are
opted in to null safety.  This produces a more accurate result than
`pub outdated`, because it is able to ignore files in transitive
package dependencies that aren't reachable via imports
(e.g. references to `package:analyzer` brought in by `package:test`).

Fixes #44061.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: I38465bcbf35e8552f0060b5d51c0f1cfc5d18c7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170561
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-11-05 23:05:51 +00:00
Paul Berry 9d3b932640 Migration: fix handling of .call tearoff on a function-typed expression.
Change-Id: I18b102ae83afdb051decfc26762619fb5746f73f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170364
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-05 19:18:54 +00:00
Paul Berry e8c8e51139 Migration: opt in dependencies in migration unit tests
Early in the development of the migration tool, due to language
versioning support being incomplete, it didn't have a good way to
distinguish opted in from opted out code, so we had the convention
that any code not being migrated was opted in.  Now that we have
language versioning support, we need to explicitly opt that code in.

Without this change, we'll get bogus failures when we add logic to
detect unmigrated dependencies.

Bug: https://github.com/dart-lang/sdk/issues/44061
Change-Id: I12920ea75b8af2142a044314b89b76bb602897c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170560
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-05 18:16:57 +00:00
Paul Berry 221c697f31 Migration: fix handling of .call on a function-typed expression.
Change-Id: Ibdee57d455215cd974ea34c8aeab578bd801f87b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170361
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-04 18:28:17 +00:00
Paul Berry 92587baee5 Migration: fix "whereOrNull" transformation to handle complex targets.
Previously, when analyzing a call to an iterable method that could
potentially be transformed into an `OrNull` extension, such as:

  allMatches(str).firstWhere(..., orElse: () => null);

the migration tool would erroneously identify some subexpressions of
the call target (`str` in this example) as the argument supplied to
`orElse`, resulting in a crash.

This CL fixes the logic so that we use an `identical` check to verify
when we are looking at the argument to `orElse`.

Fixes #43956.

Bug: https://github.com/dart-lang/sdk/issues/43956
Change-Id: I2f4a0e81becf789cab5334d4926e014bda2772f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170162
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-11-03 22:48:17 +00:00
Paul Berry 531ffd0e45 Migration: add repro for #44012
Bug: https://github.com/dart-lang/sdk/issues/44012
Change-Id: Iabddb6de213aa70feb42b273f0e48fc2b5fa582d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170020
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-11-02 14:43:29 +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 68c50f7f92 Migration: re-work test_informationalRegion_containsTraceLinks_separateDrive.
Previously, we were switching test paths to drive `D` at the start of
the test, after the `package_config.json` file had already been
generated to drive `C`; as a result, it didn't apply.  We will need
the `package_config.json` to apply when we flip the null safety flag
(so that the inputs to the migration tool are considered opted out
prior to migration).  This CL reworks the test so that the paths are
modified as part of test set-up, so `package_config.json` gets put in
the right place.

Fixes #43883.

Bug: https://github.com/dart-lang/sdk/issues/43883
Change-Id: I08f79ddb07d7a5ecf640370a32334a7ceb92ceff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169421
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-28 16:35:30 +00:00
Paul Berry 9181570513 Migration: Work around null reference exception with complex type parameters.
Change-Id: Ib3f081225f9ec7cb8714ca0aa789d4dea1a378db
Bug: https://github.com/dart-lang/sdk/issues/43945
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169252
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-28 14:01:57 +00:00
Paul Berry a777d2b798 Sort declarations in api_test.dart
Change-Id: Ia82546a1654ac11334fee380d358862385c17ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169253
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-10-28 14:01:57 +00:00
Sam Rawlins 360363efc1 Migrator: opt all test files _out_ of null safety.
Well not quite all; migration_cli_test tests are a bit of a different
beast so I am going to tackle them separately. But this fixes over
1000 test failures, and should clean up test output for further
debugging of the flip CL.

Each test file needs to be in a package with a package config file
which spells out that it is _opted out_ of null safety.

Bug: https://github.com/dart-lang/sdk/issues/43883
Change-Id: I583f66119df57031fd80824111923e15e0f91782
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168900
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-23 21:07:04 +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
Paul Berry 98ccfc33df Sort declarations in pkg/nnbd_migration/test/api_test.dart
Change-Id: Ic4990bbb40fe571a5fcba3a9b03366266cd565db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167725
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-17 01:11:43 +00:00
Sam Rawlins cddea627a7 Migrator: Accept 'late final' hint; same as 'late' hint
`late final` is not functionally different from `late`, as far
as the migrator is concerned; it is just an indication of late
in the face of missing initialization.

Fixes https://github.com/dart-lang/sdk/issues/41655

Change-Id: I1b0efd3de3b5c7064784ebd1e86c7d12436b1319
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167203
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-10-13 19:41:58 +00:00
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
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
Konstantin Shcheglov f9e6e38b21 Straighten up invocation of an Object method on dynamic.
Fixes https://github.com/dart-lang/sdk/issues/39609

Change-Id: I9b98d9bff8d4e9b75ab7625323f62eb6b6701a94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164256
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-25 16:46:04 +00:00
Konstantin Shcheglov d219bde703 Enforce await_only_futures and fix violations (in more packages).
Change-Id: I1812f7721915178e42956f988b9276bf8db0bfaa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164281
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-09-24 16:58:50 +00:00
Sam Rawlins 475ffb96c0 Migrator: Use pedantic 1.9.0
Change-Id: Ia53e84ac6b2f3ab0679710c14453fd65c8f9c00d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163161
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-09-17 20:52:43 +00:00
Paul Berry e8201aa761 Migration: fix a crash when downcasting to the Null type.
Change-Id: I905e5fe658989969fe72953485f86de1689c5b51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161140
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-08-31 20:38:48 +00:00
Paul Berry a832289de6 Migration: fix handling of late hints followed by an underscore.
Change-Id: If22d3b398c53912d0de8f5a9977c13411884840c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161142
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-08-31 20:38:29 +00:00
Paul Berry 194be0b23f During migration, if a getter is nullable, make the setter nullable too.
This is necessary because whatever type is returned by the getter must
be accepted by the setter.

Bug: https://github.com/dart-lang/sdk/issues/43119
Change-Id: I5a43ec3750328081c39c26ba6fb937a9be068eb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159644
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-08-21 20:03:00 +00:00
Konstantin Shcheglov 2bf61f4936 Don't call getFileSync() in tests.
I see no reason why this would be useful.

But it might be harmful.
When we create file1 that imports file2, and call getFileSync(file1),
the analyzer will read both file1 and file2 while building the
file graph. So, when we then create file2, it will not be read unless
we call changeFile(file2). And we don't.

Actually, if we want to simulate how migration works, we should first
create all files, and then migrate them.

R=paulberry@google.com

Change-Id: I22ff994d346c4ad985e5d06a34e9fd854d451757
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158960
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-08-18 14:58:30 +00:00
Paul Berry 2225b6f472 Migration: fix handling of async functions that return FutureOr.
Change-Id: I613d0bfd8340062bb78b20a8fd035d24a4ccdf8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155543
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2020-07-23 13:27:28 +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
Paul Berry 0fee7d6a14 Migration: fix handling of class C<T extends C<T>>
Fixes #42732.

Bug: https://github.com/dart-lang/sdk/issues/42732
Change-Id: Ifd3e294abceb0478a1f945ff8bd305cebbd043ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154847
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-07-20 16:01:47 +00:00
Paul Berry 22da8934ac Migration: properly handle extension override syntax.
There were two problems:

- EdgeBuilder wasn't handling the extension override syntax at all,
  causing a crash.

- FixBuilder wasn't overriding the behavior of
  ExtensionElement.extendedType, causing a star type to be used as a
  context for the target expression; this prevented the fix builder
  from realizing when it needed to insert `!` after the target
  expression.

Fixes #42455.

Bug: https://github.com/dart-lang/sdk/issues/42455
Change-Id: I5a9f66f83db73a796e72708022faefd527667e32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152941
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-06-30 16:00:47 +00:00
Sam Rawlins d022d4c9e1 Migrator: Fix if-null promotion with GLB
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>
2020-06-25 21:09:12 +00:00
Mike Fairhurst ea7e6f29bf [nnbd_migration] Fix #42374: mark types as non-null for assert(is T)
Fixed: 42374
Change-Id: I009cba3d0a3d16e57aec24c62fbb3e0cbfa03c01
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151925
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Mike Fairhurst <mfairhurst@google.com>
2020-06-22 18:08:36 +00:00
Paul Berry 717efd357f Migration: do not add ? after the Null type
Fixes #42322.

Change-Id: I4c26985da520e024b8a6c335834dd0fc2a41d59d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151561
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-06-17 21:29:51 +00:00