The CL to add why_not_promoted_test.dart and the CL to remove
NullSafetyUnderstandingFlag landed around the same time, so we failed
to notice the conflict between them. The fix is easy: since
NullSafetyUnderstandingFlag doesn't exist anymore (and isn't needed
anymore), we can just remove this use of it.
Fixes bot failures with the test
`pkg/analyzer/test/id_tests/why_not_promoted_test`.
Change-Id: Icec2d57d371229f103b42c5e25d49aab952adc1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182340
Auto-Submit: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
It's possible for an entry in `tools/experimental_features.yaml` to
lack an `expired` line, so we need to represent it as a `bool?`.
Avoids a crash when running `dart
pkg/analyzer/tool/experiments/generate.dart`.
Change-Id: I8734ccb9e6c5e43754b0ef870b08c304cc1470ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182300
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
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>
This saves a lot of plumbing work in the analyzer, because it allows
the individual resolver components to access flow analysis via the
resolver field rather than needing to maintain their own field. It
should be helpful in supporting the upcoming "why not promoted"
functionality (#38773), which will require flow analysis to be visible
to even more parts of the resolver.
Bug: https://github.com/dart-lang/sdk/issues/38773
Change-Id: Ibea0ec7e263461d6c512b3dad59f10622b2aac6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181661
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
The type of the `onError` parameter of Future<T>.catchError is just Function,
but the function can either have signature `FutureOr<T> Function(dynamic)` or
`FutureOr<T> Function(dynamic, StackTrace)`. This change adds checks for return
statements in a function literal passed to `onError`, and the return type of a
function-typed expression passed to `onError`.
We still need to check parameter types.
https://github.com/dart-lang/sdk/issues/35825
Change-Id: I806d9d30e595fb9d63ae669f3c30c428b60fdf4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180880
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
The analyzer has not been migrated, so this is based on manual
inspecation of the API about what can be `null` for now.
Note with the analyzer from master (running in nnbd by default) this
file contains many nullable to non-null assignments. However, we cannot
migrate this file to nnbd yet because of the language version it's used
in.
Closes: https://github.com/dart-lang/sdk/issues/44763
Change-Id: If0432341e7fefb973b0229bcc325eeefed84f7cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180821
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
The type of the `onError` parameter of Future<T>.catchError is just Function,
but the function can either have signature `FutureOr<T> Function(dynamic)` or
`FutureOr<T> Function(dynamic, StackTrace)`. This change adds checks for return
statements in a function literal passed to `onError`, and the return type of a
function-typed expression passed to `onError`.
We still need to check parameter types.
https://github.com/dart-lang/sdk/issues/35825
Change-Id: I3a1d1c444e298c5816fcd1d4bc537f7b87fa3da1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176221
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
The analyzer and CFE now report a warning on calls to
`Pointer<T extends NativeType>.elementAt()` and
`sizeOf<T extends NativeType>()` where `T` is a generic.
Adapted from https://dart-review.googlesource.com/c/sdk/+/178200 to
only deprecate but not error out on generic calls.
Does not roll forward `package:ffi` to a version with the `Allocator`
but keeps the generic `sizeOf` invocation. This causes extra warnings
in the pkg/front_end testcases.
Issue: https://github.com/dart-lang/sdk/issues/38721
TEST=tests/ffi/data_test.dart
TEST=tests/ffi/sizeof_test.dart
TEST=tests/ffi/structs_test.dart
TEST=tests/ffi/vmspecific_static_checks_test.dart
Change-Id: I8f41c4dc04fc44e7e6c540ba87a3f41604130fe9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/180560
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
We now track the following additional information:
- All local variable reads and read captures (previously we only
tracked writes)
- For any conditional expression (`?:`) or if-test, the variables
written in the "then" branch
- For any logical and expression (`&&`), the variables written in the
right hand side of the expression
Tracking this information will allow us to implement legacy type
promotion as part of _fe_analyzer_shared, using the same API as flow
anaylsis, which will in turn allow a lot of front end and analyzer
code to be removed and simplified.
Change-Id: I01aaf64cefb989a4450c8e6d3a8373c1ca2b6dec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179980
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>