Commit Graph

11 Commits

Author SHA1 Message Date
Johnni Winther 47acb386d7 [cfe] Add id testing for inferred variable types
* including inferred parameter/return types for local functions
* added testing for inferred type arguments on literals and bounded variables

Change-Id: I02bceef3f5a41af7794cc63769cf4959321700d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195260
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-04-15 05:06:56 +00:00
Konstantin Shcheglov 5cd5a9f55d Exclude _fe_analyzer_shared/test/inference/inferred_type_arguments/data/ from analysis.
Change-Id: Ic909a11f29e577f7f4ee39fa52ea5fbd7ecf15b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195184
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2021-04-13 23:46:28 +00:00
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
Paul Berry 96d3efcf48 Exclude pkg/_fe_analyzer_shared/test/constants/data_2 from analysis.
This directory contains test data that isn't expected to analyze
cleanly.

Change-Id: I130db36badad76655546de7acf8f4382c54433e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168720
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-21 19:03:34 +00:00
Konstantin Shcheglov 22d08d8e26 Exclude _fe_analyzer_shared/test/constants/data
R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I9fd93402a84137106d8c3c0172ed91a5ae7e75f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143241
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-04-13 17:47:32 +00:00
Brian Wilkerson a8840d621a Exclude recently added test data
Change-Id: I56d775a89df9120c011d2964ef550a0d661d0a5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139027
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-03-11 00:16:08 +00:00
Konstantin Shcheglov a64f6b81da Exclude test/inheritance/data/ from analysis.
R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I60d142ecb6bb89b847f9e841d378a5fcff69507a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125280
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-11-14 17:33:07 +00:00
Konstantin Shcheglov 489591068b Revert "Exclude flow_analysis/data directories from analysis."
This reverts commit a00376349a.

Reason for revert: Paul already landed similar change.

Original change's description:
> Exclude flow_analysis/data directories from analysis.
> 
> Change-Id: I2bde938cf6fd14c65fdf281e4164c32884fff695
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123760
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>

TBR=paulberry@google.com,scheglov@google.com,johnniwinther@google.com

Change-Id: I244f3c3b16f6432d1957f971854525c04db41b8d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123687
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-10-31 18:22:08 +00:00
Konstantin Shcheglov a00376349a Exclude flow_analysis/data directories from analysis.
Change-Id: I2bde938cf6fd14c65fdf281e4164c32884fff695
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123760
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-10-31 18:14:07 +00:00
Paul Berry 7c6d212e66 Exclude shared integration test suites from analysis.
When I moved these tests from front_end to _fe_analyzer_shared, I
forgot to move the corresponding entries in analysis_options to
exclude them from analysis, causing spurious analyzer errors in
_fe_analyzer_shared.

Change-Id: Ibd651cd893be262f388758d9b09bbf1423967021
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123742
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-10-31 17:13:53 +00:00
Paul Berry 499815842c Create a package to hold code shared between front_end and analyzer.
Previously such shared code was in the front_end package, but that
created problems because there is a lot of code in front_end that
isn't intended to be shared with the analyzer (including, notably, the
dependency on kernel).

This CL just moves over the flow_analysis logic to the new shared
package.  Follow-up CLs will move over other shared logic and tests.
The end goal is that the analyzer package will no longer have a
dependency on front_end.

Change-Id: I5642d6565204422d79808ca47648462db85e442a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123624
Reviewed-by: Jens Johansen <jensj@google.com>
2019-10-31 13:05:53 +00:00