Commit graph

64 commits

Author SHA1 Message Date
Paul Berry a42244f73b Flow analysis: begin tracking non-promotion reasons.
This CL implements the core flow analysis infrastructure for tracking
reasons why an expression was not promoted.  It supports the following
reasons:

- Expression was a property access
- Expression has been written to since it was promoted

I expect to add support for other non-promotion reasons in the future,
for example:

- `this` cannot be promoted
- Expression has been write captured
- Expression was a reference to a static field or top level variable

These non-promotion reasons are plumbed through to the CFE and
analyzer for the purpose of making errors easier for the user to
understand.  For example, given the following code:

  class C {
    int? i;
    f() {
      if (i == null) return;
      print(i.isEven);
    }
  }

The front end now prints:

  ../../tmp/test.dart:5:13: Error: Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
  Try accessing using ?. instead.
      print(i.isEven);
              ^^^^^^
  Context: 'i' refers to a property so it could not be promoted.

Much work still needs to be done to round out this feature, for example:

- Currently the analyzer only shows the new "why not promoted"
  messages when the "--verbose" flag is specified; this means the
  feature is unlikely to be noticed by users.

- Currently the analyzer doesn't show a "why not promoted" message
  when the non-promotion reason is that the expression is a property
  access.

- We need one or more web pages explaining non-promotion reasons in
  more detail so that the error messages can contain pointers to them.

- The analyzer and front end currently only show non-promotion reasons
  for expressions of the form `x.y` where `x` fails to be promoted to
  non-nullable.  There are many other scenarios that should be
  handled.

Change-Id: I0a12df74d0fc6274dfb3cb555abea81a75884231
Bug: https://github.com/dart-lang/sdk/issues/38773
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181741
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-02-02 16:15:34 +00:00
Robert Nystrom c4a1eaf4c7 Require an SDK constraint in the package config generator.
Also, fix the one package that didn't have one, and regenerate the
config.

Change-Id: Id7f210e9a3f73b2070e52df6ae9d4b1c4d4aeae3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172081
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2020-11-17 00:11:00 +00:00
Alexander Thomas 44f3881be6 [infra] Update checked-in SDKs to 2.12.0-0.0.dev
This is the first checked-in SDK with null-safety enabled by default.

Change-Id: I8f6fcdfd8856483f4737eb200ed4623a244cb0cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170085
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2020-11-05 07:53:22 +00:00
Robert Nystrom 9d570fe9cf Add tools/package_deps to package config generator and regenerate.
Change-Id: Ia84bba1fcbd1b04e557b3fd851f16b812e7170b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167905
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2020-10-17 02:10:14 +00:00
Leaf Petersen e9c0b2a1c2 Update package_config.json
Change-Id: I807f8eb6daf148bd3c69f3bfd10a44bb1c6353b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166801
Commit-Queue: Nate Bosch <nbosch@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Auto-Submit: Leaf Petersen <leafp@google.com>
2020-10-09 20:02:57 +00:00
Johnni Winther e597681d22 [cfe] Update messages for failures to opt in to non-nullable experiment
Change-Id: I16d71feeb51a7eee13048195898adfe7bf5761d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157482
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-08-14 09:01:07 +00:00
jlcontreras ee1ee7ee15 [cfe] Add mixin tests and runtime tests for the value class feature
Change naming value classes -> value class

Change-Id: Ifab5e0be8b816192b5716fd3433afb721bd9394c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156881
Commit-Queue: Javier López-Contreras <jlcontreras@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-08-12 16:46:17 +00:00
Johnni Winther 9d279d41e3 Add pseudo-packages for _fe_analyzer_shared test data folders
Change-Id: I6995cd65b547f0dc6159c90acb194babb819c4ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/156908
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-08-10 08:03:29 +00:00
Kevin Moore 3aa7484f6a Remove references to removed tools/gardening
Follow-up to 84ca34bf8b

Change-Id: I87d2bf0a77dc70f15a378a149dc95be6f33ee3c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147803
Commit-Queue: Kevin Moore <kevmoo@google.com>
Commit-Queue: Karl Klose <karlklose@google.com>
Reviewed-by: Karl Klose <karlklose@google.com>
2020-05-12 18:42:30 +00:00
Johnni Winther dc0fcc7472 [tool] Update tool/generate_package_config to work on Windows
Change-Id: I39f69162857f1477df117e0c25601846ddd0a507
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147480
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
2020-05-12 09:24:19 +00:00
Robert Nystrom 328f1be1fe Opt package:meta in to null safety.
This is done by setting the SDK constraint min version in the package's
pubspec to 2.9.0 which is the version that CFE currently uses to mean
"opt in".

However, the pre-built SDK currently checked into the repo can't handle
that version. To work around that, this CL has a gross hack to simply
omit the language version in the generated package config if the
pubspect's version is 2.9. This has the effect of telling CFE to use
the current language version, which is what we want, while also allowing
us to put the right SDK constraint in the package's pubspec.

Change-Id: I51c2952003c83b74fb6f3344c93839fbd267a3ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145020
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2020-04-28 03:54:48 +00:00
Robert Nystrom d9bb487ca8 Treat the expect and async_helper packages as opted in to NNBD.
This should enable strong mode tests to be fully NNBD opted in. At the
same time, legacy tests when run with the experiment off should
hopefully be able to still consume these libraries because they don't
actually use any NNBD features.

To do this, I changed the script that generates the SDK repo's package
config to not put in a language version for any package whose pubspec
has no SDK version. According to language versioning, that means the
package should be considered to be at the "current" version of the SDK
running the code.

In NNBD, that's opted in. With the experiment off, that is (presumably)
"opted out" in the sense that NNBD doesn't exist.

In order to *not* opt in some of the other packages that currently
lack SDK constraints, I put those in and pinned them to "^2.7.0" which
was what the package config script used to implicitly fill in for them.

I see a bunch of other changes in the generated package config too. The
update script probably hasn't been run in a while.

Change-Id: I55193d42eac0696a6b0105546551efa45a1f3252
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144305
Auto-Submit: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Bob Nystrom <rnystrom@google.com>
2020-04-27 21:04:56 +00:00
Johnni Winther d690a0c7c4 [cfe] Handle nullability of typedefs
Closes #41496
Closes #41498
Closes #41499
Closes #41501
Closes #41505

Change-Id: I425b6137f9ea41d01c95332ef1f7d43ca7afb5a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143811
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-04-20 07:03:55 +00:00
Robert Nystrom 4b7ba5a72f Add a script to generate a package_config.json for the SDK.
Also include the generated output.

Change-Id: Ic2818f544972c737f69913122e366ea48375e950
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135795
Commit-Queue: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
Auto-Submit: Bob Nystrom <rnystrom@google.com>
2020-02-27 17:52:23 +00:00