Commit graph

1373 commits

Author SHA1 Message Date
Konstantin Shcheglov 8cb82a35e8 Expose greatestLowerBound() from TypeSystem.
Bug: https://github.com/dart-lang/sdk/issues/53042
Change-Id: Ib332a7ab005a432d98066d79c2e48a5f06e88716
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318000
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-08-04 20:47:46 +00:00
Konstantin Shcheglov 508a293029 Revert a few not published API changes.
Change-Id: I093c3d3f6e221cfe874e82b598f52087670ce24e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/318020
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-08-04 19:21:58 +00:00
Samuel Rawlins 008cb0bbc1 Revert "Separate out UNUSED_ELEMENT_PARAMETER from UNUSED_ELEMENT"
This reverts commit a458bab09a.

Reason for revert: broke flutter snippet tests, and maybe customer tests

Work towards https://github.com/flutter/flutter/issues/131096

Original change's description:
> Separate out UNUSED_ELEMENT_PARAMETER from UNUSED_ELEMENT
>
> Fixes https://github.com/dart-lang/sdk/issues/49025
>
> Change-Id: I401093e5b76bcf707060ce022c346e26c6807aa0
> Tested: try-bots
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303261
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

Change-Id: Ib0c9afc4911efd620013896fb895ab7825c50aa4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315940
Commit-Queue: Siva Annamalai <asiva@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-07-24 16:25:07 +00:00
Konstantin Shcheglov 4bb8312b4a Revert "Move API declarations of elements into src/, re-export."
This reverts commit 43db92d9ed.


Revert "Tweaks for comments of classes around augmentations."

This reverts commit 6d0fb5094f.

Change-Id: I9508169158d536302579346defebf696edfe4bec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315660
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-23 16:43:30 +00:00
Konstantin Shcheglov 43db92d9ed Move API declarations of elements into src/, re-export.
In following CLs I plan to add `final` and `sealed` modifiers.

Change-Id: Ia6b9091034ed9f8f6f8576dbe6029d7e72a9d6b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315249
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-21 16:05:21 +00:00
Sam Rawlins a458bab09a Separate out UNUSED_ELEMENT_PARAMETER from UNUSED_ELEMENT
Fixes https://github.com/dart-lang/sdk/issues/49025

Change-Id: I401093e5b76bcf707060ce022c346e26c6807aa0
Tested: try-bots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303261
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-07-20 18:33:58 +00:00
Konstantin Shcheglov 37003ee3be Add InterfaceElementImpl, move many methods into it.
Change-Id: I7f77e318586b2c05874b3a0d25d2d940869b6a0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312240
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-07-04 01:41:38 +00:00
Konstantin Shcheglov 8828fee865 Deprecate ExecutableElement.returnType, use returnType2 instead.
Change-Id: Ibd29c3fbec0439236c2cf45c57f820c45427df9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311932
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-29 23:16:59 +00:00
Konstantin Shcheglov fae9e418ea Deprecate Element.enclosingElement, use enclosingElement2 instead.
Change-Id: I78edb6d433949eb8bd86f397fb873a078edf9fc4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311827
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-06-29 19:45:19 +00:00
Konstantin Shcheglov edd17a8638 Merge AST interfaces into implementation library, re-export.
Bug: https://github.com/dart-lang/language/issues/3135
Change-Id: Icbc2a4e506e9e58c830b53f7aecce92189bb2d1b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308402
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-06-10 16:57:59 +00:00
Konstantin Shcheglov 38546e90ab Pre-fix unreachable_from_main for instance members.
https://github.com/dart-lang/linter/pull/4441

Change-Id: I55afa6b7d78bc1114ce97c1b5bebcf7a8bca5b98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307975
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-06-09 22:39:27 +00:00
Paul Berry 709c0e4ccd Flow analysis: combine ExpressionInfo, ReferenceWithType, and EqualityInfo.
Previously, flow analysis used three classes to keep track of
information about expressions that have been visited:

- ExpressionInfo, to keep track of information about expressions whose
  truth or falsity has an effect on flow analysis (such as `== null`
  checks, `is` checks, and combinations thereof those using `&&` and
  `||`), as well as identifying the literal expression `Null`.

- ReferenceWithType, to keep track of information about expressions
  that represent something that can be promoted (references to
  variables and fields), as well as the static type of the expression.

- EqualityInfo, which wrapped ExpressionInfo and ReferenceWithType,
  and also redundantly stored the static type of the expression.

These have now been combined into a single class hierarchy with a base
class called `ExpressionInfo`. This makes the code easier to reason
about, because it is no longer necessary to think about which of the
three above classes is needed in a given situation. Also, it helps
prepare for a follow-up CL in which I plan to refactor how flow
analysis gathers this information; the refactor will be easier with
just a single class hierarchy of information to be gathered.

This required a modest expansion of the API to flow analysis to
include more static types, since previously, static types weren't
needed by the ExpressionInfo class.

Change-Id: Id3de8b19049f8d920ebe85ab58c624ae3e55f226
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304211
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-06-01 15:53:18 +00:00
Ilya Yanok 55d0c059ad migration: fix crash on getter/setter from mixins
Change-Id: Ie47d2799f2e43e02377a40c02d35354eea657d15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305940
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-05-26 14:39:30 +00:00
Paul Berry ab239cf6e1 Upgrade pkg/nnbd_migration to language version 3.0
Change-Id: Ia1cb8add108ccf9a65bca090a233fb8a02b701d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305462
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-05-24 20:38:01 +00:00
Paul Berry f7e8d0c424 Ignore TODOs in nnbd_migration
Change-Id: I9ed746730547c0872cc1098b36231bf82b151205
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304764
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-22 21:58:37 +00:00
Konstantin Shcheglov 64fcb8de1b Prepare for removing deprecated methods from NamedType.
The actual removal will happen in (to be rebased on top of this):
https://dart-review.googlesource.com/c/sdk/+/303280

Fixing direct uses of the deprecated `Identifier get name` is apparently
only about a half of the work. I should have followed my own advice to
the clients and prepared better.

These changes are necessary because we will stop creating and
visiting `Identifier`, and so `NamedType` should be handled directly.

Change-Id: Ie07b75b15eab277ed6c9b29a838561a7eb71f588
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303425
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-05-18 01:54:21 +00:00
Konstantin Shcheglov f4af6af85d Prepare for removing deprecated methods from ExtensionOverride.
The removal itself will happen in a separate CL, as a breaking change.
But we still had a few places that relied on `SimpleIdentifier` being visited.

Change-Id: I8f554cec77858cb8bc7deb29d98f0d6def8685ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303008
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-05-12 21:24:49 +00:00
Brian Wilkerson d40890582c Convert uri completion tests
I am concerned about the tests marked with TODOs because I don't know
why the behavior changed. It's possible that the contributor is still
producing the suggestions but that they're being filtered out later.

I checked using the debugger, and they're not in the list of results
that we're getting back, so it seems likely that they represent real
bugs. If we just weren't detecting the bug before then we're good.

But I can't think how rewriting the tests could effect what the user
is seeing, so I think it's safe to make these changes.

Change-Id: If72042b7ec24b97994a12449c811213b8f708f72
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303000
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-05-12 18:08:15 +00:00
Konstantin Shcheglov a3956e49d0 Use InvalidType instead of DynamicType when unresolved.
Bug: https://github.com/dart-lang/sdk/issues/36697
Change-Id: If982ca46030959160f21950c5b5e3127895d937b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300181
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-10 20:38:48 +00:00
yanok@google.com 6e18b083dd Support non-function type aliases
I'm actually not sure we are doing the right thing for general
aliases (that can now be nested arbitrarily deep), but at least
this commit avoids throwing an exception.

Change-Id: Ide3f7035b476f79fff5c542e2ddbb342045a874e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301983
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-05-08 15:50:28 +00:00
yanok@google.com c15d215653 Don't force target type equality for null-aware extension method calls
Null-aware calls, like `v?.extMethod()` don't require `v` to be
non-nullable, even if `extMethod` was declared on a non-nullable type.

Tested: added a new test.
Change-Id: I113ecde21e480bcd467367d0954b721c2ad9f7e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301982
Reviewed-by: Paul Berry <paulberry@google.com>
2023-05-08 15:50:28 +00:00
Ilya Yanok a84e6461b2 Fix a test failing at HEAD
It looks like it's failing as a result of my previous changes
to make public function/method arguments nullable by default.

I probably missed it, since it doesn't run with assertions
enabled.

Change-Id: Ifcf045d778302a0be771c3a75c94cec97cbf8060
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/301981
Reviewed-by: Paul Berry <paulberry@google.com>
2023-05-08 15:50:28 +00:00
Konstantin Shcheglov 4d6f49b1cd Update ExtensionOverride to use ImportPrefixReference and name token.
Change-Id: Ifc5852c775a95908992d33a7949b4f4bea396d66
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/299920
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-05-05 15:42:36 +00:00
Konstantin Shcheglov b06b994a4e Use errorType for element type when an error in for-in.
Change-Id: I8be4c1521a819f26d249d688f72dc672ee4994fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300561
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-03 21:17:08 +00:00
Konstantin Shcheglov ec330b47de Deprecate 'DartType.isDynamic', use 'is DynamicType' instead.
Change-Id: Ia3660a0d38f01a590dd3e034f40dbdb5a432638a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/300042
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-05-01 16:09:08 +00:00
Konstantin Shcheglov 4756d077ed Update NamedType to use ImportPrefixReference and name token.
Using Identifier expression inside NamedType does not make sense.

Change-Id: I4a61d2b472fd66fb7c5e6e92a80cccb391b06d49
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294920
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-04-28 17:31:46 +00:00
Konstantin Shcheglov dc34fe9f86 Deprecate IfElement/IfStatement.condition, use 'expression'.
Change-Id: If43b4b71a21fd256ce8d1367d4b233e1cff764b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296122
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-04-19 17:17:28 +00:00
Sam Rawlins 2f30f88916 Mark deprecated Hints with Warning aliases as deprecated
This will help with any references to deprecated Hints in other
codebases, like nnbd_migraion or linter...

Change-Id: Iccd43d8e3113e6e3e0e458bf959c7f4d48185f35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294182
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-04-13 20:07:36 +00:00
Paul Berry 2ec3b513db Patterns flow analysis: recognize trivially exhaustive switches.
This fixes a minor bug in flow analysis which was preventing it from
recognizing when a switch statement was trivially exhaustive, meaning
one of its reachable cases was guaranteed to always match.

This mostly addresses
https://github.com/dart-lang/language/issues/2980, but flow analysis
still fails to recognize that:

- A list pattern containing a just a single rest pattern always
  matches (unless the rest pattern has a subpattern that may fail to
  match).

- A null check pattern always matches if its subpattern always matches
  and the matched value type is non-nullable.

- The relational pattern `!= null` always matches if its subpattern
  always matches and the matched value type is non-nullable.

Fortunately, these drawbacks are small and don't lead to unsoundness.
I'll try to address them in follow up CLs.

Bug: https://github.com/dart-lang/language/issues/2980
Change-Id: Ie9f8564cde66a5a2c41114033ca3ff0e1a0f139a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293860
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2023-04-05 23:32:28 +00:00
Sam Rawlins 23b73d7ca4 ignore unreachable constructors in reflective tests
These were flagged as unused by `unreachable_from_main` but they are
used by `dart:mirrors`.

Change-Id: I3637b4b234f0bf7fe795977cb7ec6a1ca5449810
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293006
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-04-04 21:37:18 +00:00
Samuel Rawlins 77446204da Reland "[analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*"
This reverts commit e48f35b43d.

Reason for revert: linter is fixed.

Original change's description:
> Revert "[analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*"
>
> This reverts commit 0ef7ed2ebd.
>
> Reason for revert: Tests are failing in google3 - linter needs to be bumped
>
> Original change's description:
> > [analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*
> >
> > Bug: https://github.com/dart-lang/sdk/issues/50796
> > Change-Id: Ib5b153bc6e64bc433df1f05c53d82f71b470bbec
> > TEST=presubmit bots
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290703
> > Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> > Reviewed-by: Alexander Aprelev <aam@google.com>
> > Commit-Queue: Samuel Rawlins <srawlins@google.com>
> > Reviewed-by: Nate Bosch <nbosch@google.com>
>
> Bug: https://github.com/dart-lang/sdk/issues/50796
> Change-Id: If1c460bdcf422033648417da5ba2f5fbc1b459c2
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291460
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Auto-Submit: Oleh Prypin <oprypin@google.com>
> Reviewed-by: Alexander Thomas <athom@google.com>
> Commit-Queue: Alexander Thomas <athom@google.com>
> Commit-Queue: Oleh Prypin <oprypin@google.com>

Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: Ie503b57a19df1a50cb3dfe50c840d20779310e87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291560
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Oleh Prypin <oprypin@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-03-28 21:26:58 +00:00
Oleh Prypin e48f35b43d Revert "[analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*"
This reverts commit 0ef7ed2ebd.

Reason for revert: Tests are failing in google3 - linter needs to be bumped

Original change's description:
> [analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*
>
> Bug: https://github.com/dart-lang/sdk/issues/50796
> Change-Id: Ib5b153bc6e64bc433df1f05c53d82f71b470bbec
> TEST=presubmit bots
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290703
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Commit-Queue: Samuel Rawlins <srawlins@google.com>
> Reviewed-by: Nate Bosch <nbosch@google.com>

Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: If1c460bdcf422033648417da5ba2f5fbc1b459c2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291460
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Oleh Prypin <oprypin@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Commit-Queue: Oleh Prypin <oprypin@google.com>
2023-03-28 07:16:42 +00:00
Sam Rawlins 0ef7ed2ebd [analyzer] Move 4 more HintCodes to be WarningCodes, UNUSED_*
Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: Ib5b153bc6e64bc433df1f05c53d82f71b470bbec
TEST=presubmit bots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/290703
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2023-03-27 21:41:12 +00:00
Sam Rawlins 6333e318cd [analyzer] Move 2 more Hints to be Warnings, DEAD_CODE*
Bug: https://github.com/dart-lang/sdk/issues/50796
Change-Id: Ie7a6cb94cefaf4f551ed766e637bac3606c0f5ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279463
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2023-03-21 21:55:08 +00:00
Ilya Yanok d190e16766 Fix handling of @Injectable functions
Recent changes that made migration tool more conservative affected
functions used in Angular's DI: functions annotated with `@Injectable`
must have non-nullable non-annotated arguments. Previously that
worked just because there was no reason to make them nullable.

Make such functions' arguments explicitly non-nullable.

Bug: b/250862403
Change-Id: I27207994b058ba845aafd7776d14380e8104e8f8
Tested: added a test
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289505
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-03-17 17:28:41 +00:00
Ilya Yanok 43b74160e0 Fix crash when trying to do cast X to FutureOr<X>
Bug: b/273826476
Change-Id: Ifcaa5c936c87ea494658a547a7514e0fbd0c0b7f
Tested: added a test
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289504
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Ilya Yanok <yanok@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-03-17 15:36:34 +00:00
Ilya Yanok 134b614fca nnbd_migration: fix widening overriden methods' arguments
With the last change to make public methods' arguments
nullable by default, people started complaining about arguments'
type being widened in overrides.

Stop the migration tool from doing this.

Change-Id: I4ada6e15d21e91c0e17bd4452fba5b42b6133930
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288244
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Ilya Yanok <yanok@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-03-15 14:06:47 +00:00
Konstantin Shcheglov 5ecf6db857 Deprecate 'DartType.isVoid', use 'is VoidType' instead.
Maybe? With an explicit type check we don't try to make an impression
that anything more happens here, e.g. for type parameters.

Similarly, for https://github.com/dart-lang/sdk/issues/36697 we would need to introduce `InvalidType`, which is not `DynamicType`. And so, `DartType.isDynamic` should not return `true` for `InvalidType`, it is not a property that various types may have, and should be replaced with explicit `is DynamicType`.

We also have `UnknownInferredType`, but it should never leak to clients.

Change-Id: I302b06355143d97bb52922c805dbad585a522e0a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/288340
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-03-14 18:50:33 +00:00
Konstantin Shcheglov c084056d45 Add a few @Since annotations for mock SDK.
Change-Id: Ie2d726918b16f38261c2c848a59a0f3f1e4b3675
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287060
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2023-03-07 21:44:57 +00:00
Ilya Yanok 4df95de549 Add nullability edge for public functions/methods' arguments
That forces them to be nullable, unless there is a
reason to be non-nullable.

I excluded setters and generic arguments from this
nullification. Also we don't touch `operator ==`, where
changing argument type to `Object?` doesn't make sense.

This is a response to some teams asking for the migration
tool to be super conservative. Otherwise people migrate
some methods to have non-nullable arguments and they are
still called with `null`s at runtime in mixed mode.

That was the only way I found to implement the "nullable
arguments by default" request.

It broke a good deal of tests. I updated them mostly to use
private functions, so the old behavior is preserved, but
sometimes I couldn't figure out a way to trigger the desired
codepath with the new behavior... I also suspect that now
there is a non-zero amount of tests that are passing but
don't really exercise what they were supposed to exercise.

Change-Id: I2eb8020008c6cd5c7507e7782e977d70bceac58b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285680
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2023-03-02 10:14:53 +00:00
Ilya Yanok b74f4e1818 Count comparisons to null literal as a nullability signal
This breaks a good deal of tests and overall feels like preventing
a whole bunch of "make it non-nullable" stuff from working.

On the other hand, in cases where not the whole program is migrated
at once, and pieces of it keep being legacy and the whole thing
running in mixed mode, we would like to keep it on the conservative
side, so treat comparisons to `null` as a nullability signal.

I deleted some tests while updating others, I think a good deal of
updated tests probably should be deleted instead, but I kept them
for review, as these diffs show what exactly this change breaks.

Change-Id: I3d29dd446aefb7cfeb6219cffd9060ca8f57e50d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283681
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
2023-02-20 12:58:37 +00:00
Paul Berry 6e6f89a255 Flow analysis: fix handling of promotions in when clauses with shared case bodies.
Previously, if multiple switch cases shared a body, and at least one
of those cases promoted a match variable using a `when` clause, the
promotion would not be carried over to the merged variable seen in the
shared case body.  This was happening because promotions performed in
the `when` clause were applied to the promotion key associated with
the client's representation of the variable, whereas flow analysis was
computing the state of the merged variable based on the promotion keys
used internally while visiting the pattern (which don't include
promotions from the `when` clause).

With this change, flow analysis now computes the merged variable state
based on the promotion keys associated with the client's
representation of the variable components, so promotions from `when`
clauses take effect.

In the process, I've moved a lot of the tracking of these promotion
keys from the `TypeAnalyzer` class to the `_FlowAnalysisImpl` class.
This avoids the need to expose more flow analysis internals through
its public API.

Fixes #51399.

Bug: https://github.com/dart-lang/sdk/issues/51399
Change-Id: I8f1bb6e49ceb8441bb743c63af61c119df9041f2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283441
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-02-16 18:11:14 +00:00
Konstantin Shcheglov b880af5bca Support for 'await' in pattern for-in statement/element.
Change-Id: Ib629768add8454a7f8e02824237c378ea78c9562
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281862
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-02-08 22:29:53 +00:00
Konstantin Shcheglov 0a93b04d66 Issue 51137. Don't use the type inferred from the initializer to resolve the initializer.
Bug: https://github.com/dart-lang/sdk/issues/51137
Change-Id: I5979e2531b285d86141d60cd844919456ff17c47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/281462
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2023-02-08 17:52:20 +00:00
Ilya Yanok 0117e75b41 migration: Don't generate casts of unrelated types
If we statically know the types are unrelated, there is like
no chance for the cast to succeed at runtime. This is likely
a sign that automatic migration went wrong somewhere and human
intervention is needed. The cast just delays the problem to
runtime. Skip the cast and let it fail at compile time instead.

Change-Id: Ib557650b368c8f2839029e8a2e54c6bf9474035b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280119
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-01-31 22:21:11 +00:00
Paul Berry 0ad96e6895 [analyzer] correctly handle continue inside switch
Fixes #51145

Change-Id: Ifee8c96d578c24a294e2ddacead3129a68d74b8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280084
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-01-31 18:53:27 +00:00
Paul Berry 9b9cf3c928 Flow analysis: allow null to be passed to handleBreak/handleContinue
This should allow for better error recovery in the case where a label
target can't be found.

Change-Id: I05ec107a4ecef3f73cfba5931b77b8250707d2ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280120
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-01-31 17:00:40 +00:00
Ilya Yanok 062b3aa7c4 migration: better handling throwing closures
`() => throw bla` has type `Null Function()` in legacy mode.
That's get recorded by the migration tool, so, when it later
checks if the type is compatible to the expected one, it
inserts an unnecessary cast.

Change-Id: I80d86ff715e16b038b4cbceae2fccfa76948320d
Bug: b/173016016
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279380
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2023-01-31 09:51:24 +00:00
Josh Soref 77978889eb Spelling
Closes https://github.com/dart-lang/sdk/pull/51143

GitOrigin-RevId: 9e21c99a222d588e4fc95980725a2f8c9784965c
Change-Id: If0870e8936c7649935dce7e23cd783d62aa5610c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279916
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-30 18:29:59 +00:00
Ahmed Ashour 63180b95ed Remove superfluous words.
Fixes #51095

TEST=ci

CoreLibraryReviewExempt: There are no API changes, just removal of superfluous words in the comments.
Change-Id: Ib1020c62fe6baed5ca68f0074323f025cc90e9f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279500
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-01-30 15:58:38 +00:00