Commit Graph

1123 Commits

Author SHA1 Message Date
Paul Berry 722b505316 NNBD migration: Fix an implicit downcast error.
Change-Id: I2762d60dc739adc046d7c438ae8eadae550bfa97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109941
Reviewed-by: Mike Fairhurst <mfairhurst@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-07-22 20:25:59 +00:00
Kevin Moore 0352fb2cb7 Fix package dependencies in analyzer_cli, dartfix, nnbd_migration
Change-Id: Ib7f3b3f12d95b59b81164321e7d2176179adc957
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109890
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-07-22 19:55:43 +00:00
Paul Berry b912aebf5c Flow analysis: change tryPromoteToNonNull to promoteToNonNull.
The flow analysis engine is now responsible for figuring out whether a
promotion actually occurred; this is less error prone.

Change-Id: Idce8af01fae982a9cc240ec4675812f8d7fd68a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109883
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-07-22 15:58:48 +00:00
Paul Berry c8587ce199 Flow analysis: don't use == to compare types.
Includes an integration test illustrating where this would have caused
incorrect behavior (due to the fact that the analyzer's `DartType.==`
doesn't yet distinguish nullabilities - see #37587), as well as unit
tests that will ensure we don't regress even after #37587 is fixed.

Change-Id: Ief92cf5a052bc2b96e4e74f69f2268b0565d920f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109820
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-07-21 20:33:55 +00:00
Paul Berry 7b6c667863 Flow analysis: rework tracking of nullability.
We now track nullability via type promotion, e.g. by promoting from
`int?` to `int` to represent a non-nullable value.

I've added a few more unit tests of flow analysis that were helpful
while preparing this CL.  I plan to add more tests in follow-up CLs.

A few behaviors are lost by this change:

- We no longer track whether a variable's value is exactly null
  (previously the tests annotated such variables as "nullable", which
  was a bit misleading).  I'm not sure whether we really want this
  feature or not; I've filed
  https://github.com/dart-lang/language/issues/461 for discussion.

- Assignment of a non-null value to a nullable-typed variable no
  longer promotes it to non-nullable.  I think we want to get this
  behavior back, but we'll need to add a little bit more machinery to
  get it back (we need to allow assignments in general to promote.
  I'll address in follow-up CLs.  See
  https://github.com/dart-lang/language/issues/440 for discussion.

- A promotion to non-nullable that happens during a "try" block is
  lost if there is a "finally" block.  I think we want to get this
  behavior back, but we'll need to add a little bit more machinery to
  do so, to allow promotions in general to be preserved by
  try/finally.  I'll address in follow-up CLs.

Change-Id: Ibc45d70043725697fbee063a8dcefb1179506e9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109780
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-07-21 04:09:14 +00:00
Paul Berry 851eaad61a Flow analysis: Rename Element to Variable.
The "elements" used by flow analysis always represent variables
anyway, and the front end has no notion called "element", so just
calling them variables is clearer.

Change-Id: Ibd450742b97aafea77d3339609f5a83090405b0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109743
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-07-20 05:01:43 +00:00
Devon Carew ddc9b9d492 [analyzer] tweaks to the dartfix UI
Change-Id: I32b61f1331b6c3c4fe37ced3dd1a5d68ebcb9d4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109547
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2019-07-18 20:47:00 +00:00
Brian Wilkerson 97587b554f Update the element model to support extension methods
Change-Id: Ia3bd6a19514368b3e046fead2eed0a4d0bfb133d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108504
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2019-07-11 13:28:37 +00:00
danrubel 766e542e53 handle return in async function
This updates EdgeBuilder to handle return statements in async functions
when the return value is not a Future...

  Future<int> f() async { return 1; }

Change-Id: Icc2a375546d01592c99ababb9652ce8108ae7dd6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108181
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2019-07-03 20:14:37 +00:00
danrubel 86ce74caaa update NodeBuilder for default value type arguments
This updates NodeBuilder to build nodes for type arguments
in default parameter values.

Change-Id: I8999bdfca9a60d9e1d3feff5cdbd1cdc62cdb4fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108120
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
2019-07-03 17:52:41 +00:00
danrubel 9b53686ffb update NodeBuilder for declared identifier implicit type
This updates NodeBuilder to handle for loops of the form

  for (var i in <int>[1, 2, 3]) ...

Change-Id: If796379ff4c95df1e2e5087ca71d3d4cac5c0853
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108040
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2019-07-03 12:39:27 +00:00
danrubel 851958ee54 update NodeBuilder to handle for loop
This updates NodeBUilder to build a node for the identifier in

  for (int i in <int>[1, 2, 3]) ...

Change-Id: Ifcb90f7b1511dc29ecedceb043986f6705bdbe1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107980
Commit-Queue: Dan Rubel <danrubel@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2019-07-02 23:40:43 +00:00
danrubel 7a73682c6a update NodeBuilder to handle catch clause
This updates NodeBuilder to create a node for the exception parameter
in a catch clause. Not doing so creates an exception downstream
in the EdgeBuilder.

Change-Id: Idaf0ab62e47018a634ff028af0e3af1d504c02ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107923
Reviewed-by: Paul Berry <paulberry@google.com>
2019-07-02 23:40:43 +00:00
danrubel e0eeffaf9b update NodeBuilder parameter tracking when visiting executable declarations
This updates NodeBuilder so that when it visits a method declaration,
it does not count any parameters defined in body statements
as part of the parameters defined in the method signature.

Change-Id: I4da3989eb2bc65c422d94fa264885910850b0ed2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107921
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
2019-07-02 17:39:33 +00:00
danrubel 1427a218f3 update DecoratedType asserts
Once https://dart-review.googlesource.com/c/sdk/+/107901 lands
to implement FunctionTypes in conditional expressions,
this CL can land to updates the DecoratedType asserts

Change-Id: Ia9924859243e6621dcbbd61ac471bd013069e5a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107920
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
2019-07-02 17:15:50 +00:00
Paul Berry f4dc001729 Migration: begin adding support for LUB computations in conditional expressions.
A number of corner cases still need to be addressed, and I need to
generalize the logic to work for `??` expressions.

Change-Id: I6998058698c8b293f7d7b99f3c231a9173b9ff58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107901
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-07-02 16:12:07 +00:00
Paul Berry 26f369eb8e Fix doc comment for NullabilityNode.forLUB
Change-Id: Ibc87629b81eea7d2e56dfe143d037d10e6cfbe32
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107900
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-07-02 14:35:57 +00:00
Paul Berry fc7049ae7d Migration: implement support for user-definable prefix expressions.
Change-Id: Ie2316625d8ed6fd9ab3aee3b592ce5b82b0cb1e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107750
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-07-02 10:23:21 +00:00
Paul Berry 77aa5f0c02 Migration: Add support for function-typed formal parameters.
Change-Id: Iae4ba1c052e854bc832fdba7a2e2f53635d5033d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107749
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-07-02 10:23:21 +00:00
Paul Berry 326e970b81 Migration: handle method invocations that resolve to a getter.
Change-Id: I9a41190d883ee50a63d8cd60699da14084da09d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107748
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-07-02 07:41:45 +00:00
danrubel 686742585a Migration: add a more robust assertion to the DecoratedType constructor
This CL takes https://dart-review.googlesource.com/c/sdk/+/107740
and add the following condition so that all the current tests pass.

  if (positionalParameters.length <= positionalParameterCount) {
    // TODO(danrubel): Track down why this happens
    // and remove this if statement
  } else {
    ...

My next task is to track down and fix the underlying issue
then remove the temporary code above from the asserts.

Change-Id: I683beac46835ed7b8c1a7b856804db84a74142f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107860
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
2019-07-01 20:41:49 +00:00
danrubel 2fd4ca570b set DecoratedType.returnType for FunctionType
This CL updates creation of DecoratedType to ensure that the return type
is set if the DecoratedType's type is FunctionType.

Change-Id: I9fd031693f5fd07ea5f0e6e16723b7c9659410ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107702
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Dan Rubel <danrubel@google.com>
2019-07-01 19:49:49 +00:00
Paul Berry 0c6b3d1277 Migration: do better function type formatting in DecoratedType.toString.
We now wrap named argument types in `{}` and optional positional
argument types in `[]`.

A few unit tests have been added to verify this functionality; I
didn't exhaustively test the implementation of DecoratedType though.

Change-Id: I1e3135adc3abc966f8a41d90c1c6e95e9c7c1eda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107747
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-07-01 15:36:14 +00:00
Paul Berry a76c459239 Migration: Remove unnecessary duplicate type test
Change-Id: Ia99aabee8e5aa40ac301786d5b0b129a932209fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107744
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-07-01 14:14:32 +00:00
Paul Berry 79f276e07d Migration: handle field formal parameters.
Change-Id: I15fb64a2cb7ed9bc56593fc8b27170aaa34af8a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107743
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry c8c3572ca9 Migration: standardize method names in EdgeBuilderTest.
Two methods had names beginning with "visit", to reflect the name of
the visitor method they tested.  But this was inconsistent with the
rest of the methods in EdgeBuilderTest, which are simply named after
the structure whose visitor method they test.

Change-Id: I4616eeff959f4ef84fc8a5da3263ab9c88d8fba2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107742
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry c0c15c1283 Migration: build nullability node for default type parameter bounds directly.
Change-Id: I29e9aa8004641a3ef24e44e13b8ee233d8ffb521
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107741
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry b57ff85906 Migration: clean up and test implicit dynamic return type of Function() syntax.
Change-Id: I6a010f5aa32cee4ece094188992ba472444293c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107519
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry 0f2eda8644 Migration: add support for function expression invocations.
Change-Id: Icf92c81f677421b00f023c02ce784122dd570e87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107518
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry a200980da0 Migration: add support for variable and field type inference.
Change-Id: Iae66992d4f9734438776af34b68aabf20f5c15d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107517
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry ca25f56883 Migration: add support for type inference of function types.
Change-Id: Ic0ebbc4d412e7273127564089431ebe9058ee790
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107516
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry a436c0621f Migration: fix DecoratedType.toString to support named function parameters.
Change-Id: Ia49e4b381de5928d26be16fe4a9ab45fe8a64678
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107515
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry 9dee307bdb Migration: update nullability graph debug dump to support union edges.
Change-Id: Ic9b85656b1e0d81468c73c89a08bfac611060534
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107514
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 16:39:17 +00:00
Paul Berry b60dcdbf73 Migration: Remove the create parameter from Variables.decoratedElementType.
We can tell whether a decorated type needs to be created based on
whether the library is being migrated.

Change-Id: I440c9a310ad103c800de6409d717492bc539b838
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107660
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-30 10:43:45 +00:00
Paul Berry 18c21ee9d1 Migration: add support for generic instance creation.
Change-Id: I46d24159a58b7e889cdfa54a9dbb8a94b6c13410
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107645
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 10:43:45 +00:00
Paul Berry f7ddfdf6ca Migration: don't forget to visit variable initializers in NodeBuilder.
Also visit any annotations present in a variable declaration (we can't
yet test this part well but we might as well add the proper code now).

Change-Id: I1c8f19c9516d1e0f17f024fa136bd7d331ed8ae1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107643
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-06-30 10:43:45 +00:00
Paul Berry f91375405e Migration: remove defunct TODO comment about substitution.
Substitution is now handled by _handleInvocationArguments.

Change-Id: Ife85444c6f224a48b2989ca6efe3796deae1cf10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107642
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-28 19:52:09 +00:00
Paul Berry 881ca948fd Migration: handle constructor redirections.
Change-Id: I1c74768f94956f830621e238780243c8d974a745
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107641
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Dan Rubel <danrubel@google.com>
2019-06-28 17:45:29 +00:00
Paul Berry a5070b88de Migration: Remove unused variables from test.
Change-Id: Id052dea7d4f1c464fd57c9482ee8f37cec4e014b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107640
Reviewed-by: Dan Rubel <danrubel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-28 14:09:55 +00:00
Paul Berry bf79e4604c Migration: Add support for synthetic constructors in generic class type aliases.
Change-Id: I8eee88e4dd607623fe109143d01438a5271b3230
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107521
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-27 19:34:05 +00:00
Paul Berry 9329d9da59 Migration: Make use of findElement.unnamedConstructor in tests
Change-Id: I2ce903de379b6c6fa1cb5ac7db80e6702bdf37c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107457
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-27 14:47:43 +00:00
Paul Berry 014cca1abd Migration: add support for invocation of generic functions.
Change-Id: I56dbedad452e24aaf57ec1d622ce776089e28de7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107449
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-27 02:29:51 +00:00
Paul Berry c1c24c2e19 Migration: Enable support for factory constructors.
It turns out that we don't need any special support for factory
constructors; the migration engine already knows that their return
type should be non-nullable, and it propagates that non-nullability
properly backward from return statements.  So we just need to remove
the error handling logic that prevented factory constructors from
being used.

Change-Id: I7875750fd603ecb2fb65f3831a7883a2d4c9a11a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107380
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-26 18:18:46 +00:00
Paul Berry dde0c68dfb Migration: Add support for named constructors.
Change-Id: Ibb1b5daf8ae06a84f3eaf1e70ce703266de4b04c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107361
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-26 18:18:46 +00:00
Paul Berry 0db6f216ba Migration: add void type support to DecoratedType.forImplicitType.
Change-Id: Ifae57627d13a4913d86ab8a4789615a23ec66c1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107441
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-26 18:04:46 +00:00
Paul Berry 74071981d7 Migration: Handle contravariant uses of already-migrated classes.
Change-Id: I1ce1adc1975461010ce993ba31ac74856033351e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107320
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-26 17:23:56 +00:00
Paul Berry 9ec7b3ebea Migration: add the ability to union decorated function types.
Change-Id: Ife92ab951ee0a60edea12c0d1fe4f242135a8ae3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107440
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-26 16:40:36 +00:00
Paul Berry 4c75f452fa Fix a misleading variable name in node_builder_test.dart
Change-Id: If9802562c362efe8d43b30c822211de3a49cca8f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107420
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-06-26 16:40:36 +00:00
Paul Berry 40609fc30e Migration: build decorated types for implicit constructors of class type aliases (with parameters).
Change-Id: I3ff55830e07cba115db7784998b013112d4d07b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107304
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-06-25 22:13:44 +00:00
Brian Wilkerson 29c0341678 Skip library directives when building edges
Change-Id: I43602f5cfc7455e83b408ccb7ee8adfba0e26d64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107194
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
2019-06-24 22:21:21 +00:00