Commit Graph

61 Commits

Author SHA1 Message Date
Paul Berry 3397720738 Analyzer: Add id testing for inferred variable types
This parallels the test introduced in
https://dart-review.googlesource.com/c/sdk/+/195260, but it tests the
analyzer rather than the CFE.

Change-Id: I7751abfcad0e91bf903a5dae2136b80c6714ea35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195481
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-15 16:51:47 +00:00
Paul Berry 8af652ce3d Analyzer: update id testing for inferred type arguments to handle collection literals.
The ID tests for inferred type arguments now include tests for
collection literals, e.g.:

    /*<dynamic>*/ [];

The analyzer ID testing code needs to be updated to handle test cases
like these.

Fixes trybot failure with
pkg/analyzer/test/id_tests/inferred_type_arguments_test.

Bug: https://github.com/dart-lang/sdk/issues/45717
Change-Id: I338814acccf3e080bbf8cf167041c52d96ba19cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195482
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-15 14:23:47 +00:00
Paul Berry ed9def1467 Analyzer: Add id testing for inferred type arguments
This parallels the test introduced in
https://dart-review.googlesource.com/c/sdk/+/195020, but it tests the
analyzer rather than the CFE.

Change-Id: I5ea1b873561f159a0549acbfdf8c1e639b733435
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195420
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-15 12:16:17 +00:00
Konstantin Shcheglov 8120c43d85 Replace 'Expression.staticType!' with 'typeOrThrow'.
It is not a huge improvement, because it does not add static safety,
for this we would need to distinguish between unresolved and resolved
expressions, as separate types.

But it is still an improvement.

1. We get to know the node that was not resolved.
   Maybe not enough, in case if it was because of the enclosing
   now that this node was not resolved. But still something.

2. We group this use case into one place.

Change-Id: I2e8f029e8a5fcd8ccecdd1b6bc9d78ee9eaf12a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184103
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2021-02-10 17:19:27 +00:00
Paul Berry c5a79f9a15 Analyzer: stop using NullSafetyUnderstandingFlag in why_not_promoted_test.dart.
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>
2021-02-02 20:29:14 +00:00
Konstantin Shcheglov 4c6f5f7658 Remove NullSafetyUnderstandingFlag.
Bug: https://github.com/dart-lang/sdk/issues/40531

Change-Id: I197cfdf64c697a09bb9e0e3896f3ee5ac1967757
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168160
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2021-02-02 18:03:24 +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
Konstantin Shcheglov 9f986d2501 Migrate package:analyzer to null safety.
Change-Id: Iffe4370431587e46a141ddc72a86ceec29c163b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176486
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2021-02-01 18:56:04 +00:00
Paul Berry 4ee861b7d0 Flow analysis: Track additional assigned variables information.
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>
2021-01-21 19:48:22 +00:00
Paul Berry 88cd4739b8 Flow analysis: switch on inference based on local boolean variables.
The implementation was completed in previous CLs, but hidden behind a
flag.  This CL switches on the feature and adds integration tests.

Bug: https://github.com/dart-lang/language/issues/1274
Change-Id: I0e2d7ac96d3a6d68d33d49f1eab5c341c9167f6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175500
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-01-08 18:57:02 +00:00
Sam Rawlins 17b7d05e72 Analyzer: prepare for null safety in tests: casts and late variables
Change-Id: I37f3663b340952b79cef0e423caf81e5950b700b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175841
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-12-11 19:50:39 +00:00
Konstantin Shcheglov fbfc723de7 Use CompoundAssignmentExpression instead of LHS element/type.
This adds some technical debt in form of using writeOrReadElement in
clients, which can be paid incrementally by migrating these places to
handling assignment like expressions one by one. Doing it all in one
CL was too much. But now the underlaying AST resolution will be
sound.

In the next breaking change we will remove
setAssignmentBackwardCompatibility(), so stop setting elements/types
for assignment targets.

Change-Id: I11626876cfed25653edb0cc18544aba51cef5965
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165622
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-10-14 18:45:08 +00:00
Konstantin Shcheglov 3a59eafbe5 Include promotedBound into the TypeParameterType display string.
Change-Id: I7d34a041559875d34a66de4504b8df1b57497e55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/165684
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-10-02 18:42:21 +00:00
Konstantin Shcheglov 1c0a64ded5 Comments and renames in FlowAnalysisDataForTesting.
R=brianwilkerson@google.com

Change-Id: I75710e11b88bbed59e57bc1928f9e06bbd279c5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159520
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-08-20 17:14:29 +00:00
Konstantin Shcheglov 25edea3d8d Issue 43100. Verify local variable reads for null safety.
Bug: https://github.com/dart-lang/sdk/issues/43100
Change-Id: Ia8ece4de32f65d7912e534ce61936a45f2c768c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159382
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-08-20 15:50:50 +00:00
Konstantin Shcheglov fd4edad020 Update id tests constants/ to use getDisplayString().
R=brianwilkerson@google.com, devoncarew@google.com

Change-Id: If7d737ca3a31954e4d3c061d316548e8f54b0d10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157121
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-08-04 23:38:32 +00:00
Sam Rawlins c68fd58513 Use ///-style doc comments in analyzer/test
Bug: https://github.com/dart-lang/sdk/issues/33892
Change-Id: If61e07fda4d74b1e5171d22403b156855cd00596
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152701
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2020-06-26 18:45:05 +00:00
Konstantin Shcheglov d279cb47b5 Enforce sorting in analyzer/.
Change-Id: If7e76e442e64cd4991b80c3993e3da10bb3a19ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151462
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-06-17 05:04:30 +00:00
Konstantin Shcheglov 9b3f9db65a Switch InheritanceManager3 to computing ClassElement interfaces.
Change-Id: Id9148d1bf3fc369eeabe2b1acc7507c20986a3e8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146682
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2020-05-06 03:09:03 +00:00
Konstantin Shcheglov 4490e2f541 Deprecate VariableElement.constantValue, use computeConstantValue().
Bug: https://github.com/dart-lang/linter/issues/2073
Change-Id: I68d9c8eaf632c72c4634bb56f13af7ab603e3c5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144666
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-04-24 00:37:52 +00:00
Johnni Winther dc97454b63 [analyzer,cfe,dart2js] Add pretty printing to id testing
Adds support for pretty printing verbose annotations.
Adds support for force updating annotation texts useful for applying
the pretty printing to valid annotations.

Change-Id: I8fe9b6d2f8198bd5e160854053c8d964ef832a8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129710
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-04-14 13:24:09 +00:00
Sam Rawlins 2c420267b7 analyzer: Do not allow errors to be ignored inline. Fixes #27218
Change-Id: If37dabba3ec18a9f79f44c4ea38d6920a4013019
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140142
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
2020-04-10 17:16:24 +00:00
Johnni Winther d68f552e70 [analyzer,cfe] Handle (un)assigned state in try-statement
This handles (un)assigned state in try-statement that do not
complete normally. In this case we could create a variable model
for an unreachable state that would be both assigned and unassigned
leading to an assertion failure.

Closes #41284

Change-Id: Id4c7689bc7c614338af3542eb342c964696fca1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141981
Auto-Submit: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2020-04-01 15:46:15 +00:00
Konstantin Shcheglov a06325447d Use InheritanceManager3 directly in id_tests/inheritance_test
Change-Id: I2914b08f4c6b2b32f70001cd1445f5077e810a1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140761
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-03-24 15:29:23 +00:00
Johnni Winther 6c6144bb74 [cfe] Implement consolidated in ClassHierarchyBuilder
Closes #40414 and #40156



Change-Id: I066aa8ceef4f998230215fd9e9b446b2281cc3bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138294
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-03-13 08:16:49 +00:00
Konstantin Shcheglov ad4762343b Issue 39876. Report DEFINITELY_UNASSIGNED_LATE_LOCAL_VARIABLE.
Bug: https://github.com/dart-lang/sdk/issues/39876
Change-Id: I855579c47ab8f932bb3977eb44d0c17d0ce5987a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139034
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-03-12 15:41:07 +00:00
Konstantin Shcheglov 9a0c09ecb2 Track definitely unassigned variables.
Change-Id: Id610a133912605f9af63222f25408942420cbf1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138881
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-03-10 18:35:40 +00:00
Johnni Winther 101588f0f4 [cfe] Implement legacy top merge functionality
+ fix getter/setter type inference

Change-Id: I9a4bed2b6a53131cbc9946bac0a01a4b15a63a91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137922
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-03-03 12:19:09 +00:00
Devon Carew 9eeecae3e4 address a few static analysis nits
Change-Id: I461c71550e320ed9f520169bcdbd4083f58b3db3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137323
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Janice Collins <jcollins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2020-02-26 20:04:51 +00:00
Johnni Winther a9162bd599 [analyzer,cfe] Implement mixed inheritance id test for analyzer
Change-Id: Ie4ce09b83c2a96a5ad16c60d2924f18cd90a4089
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136633
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-02-24 13:28:26 +00:00
Johnni Winther 5829fc7829 [analyzer,cfe,dart2js] Add marker.options files to automate running id tests on all configurations
Change-Id: Ib5eb7f3967634721047f8dcc57b9e6c350b91a41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136226
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-02-21 08:34:26 +00:00
Konstantin Shcheglov 21e944f1bc Use promotedBound for TypeParameterType promotion.
Change-Id: I217a8b9140f60d4f6a9ffc052564388c24c1a7ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136100
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-02-18 17:11:44 +00:00
Konstantin Shcheglov 6f6797e745 Add NullSafetyUnderstandingFlag, update APIs to use it.
DartType.== implementations ignore nullability if the flag is not true.

TypeSystem APIs eliminate nullability from types before doing anything.

Internally analyzer continues using actual nullability for types.

Package nnbd_migration opted into NullSafetyUnderstandingFlag.

Bug: https://github.com/dart-lang/sdk/issues/40500
Change-Id: Ifeea28c01adf1dc59ed2da675b4a62c6334d529a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134865
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-02-07 21:38:06 +00:00
Konstantin Shcheglov 05dcf371e7 Remove 'withNullability' from TypeImpl.toString()
Bug: https://github.com/dart-lang/sdk/issues/40460
Change-Id: Icd967df0252a9fd7ff9941ca7158b7df0190c961
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134384
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2020-02-04 21:19:06 +00:00
Paul Berry 0399fcf6fa Flow analysis: fix shared tests to consider potential nullability instead of nullability.
No change in functionality.  Just changing the analyzer's
nullability_test.dart so that it generates the `nonNullable`
annotation for a promotion from type parameter `E` to `E&Object`.
This makes it consistent with the front end test runner behavior.

Change-Id: I9b74222257b432e361fbe46aa7d4d7070225a5e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133322
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-01-27 12:43:06 +00:00
Johnni Winther 64dae246db [dart2js] Use CFE constant evaluator for non-required constants
Change-Id: Id363332caf29e98307553ec048c2dea36c739d95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129701
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-01-08 08:21:59 +00:00
Johnni Winther e3a20bf361 [analyzer,cfe,dart2js] Support annotated code generation
Add support for generating annotations from actual data using
option -g

Change-Id: I88d9cdb62a38d579234b15097c9e9bb3d81ebe8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129708
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2020-01-03 13:57:39 +00:00
Sam Rawlins 5dfa750393 Convert all function parameters and typedefs to generic syntax
Change-Id: I18f8644ecbe61555b2929ed09d446733d33ec2a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128521
Commit-Queue: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-12-16 23:36:38 +00:00
Konstantin Shcheglov 364dd8936b Fix unnecessary_new in analyzer.
R=brianwilkerson@google.com

Change-Id: I70f80baa3da4b14c0a52c1f28da16a9ad26d7dda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127424
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2019-12-06 01:11:30 +00:00
Konstantin Shcheglov 273ca5858b Deprecate AnalysisContext.typeProvider/typeSystem
Change-Id: I5235aa38bcde93618a10b88da9ad6a8c3e5dc29c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126141
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2019-11-25 22:00:47 +00:00
Paul Berry c4b6df5009 Move ID testing infrastructure into _fe_analyzer_shared.
Change-Id: I9f2692dbe750f3c31f8c86e86fe732f34e166517
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123860
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-11-01 12:39:00 +00:00
Paul Berry a0ee662b7b Move shared analyzer/FE integration test data into shared package.
This moves the five test suites for flow analysis along with the
constants test suite.

Note that a few files have formatting errors.  I'll fix those in a
follow-up CL.

Change-Id: Ie9bba74c7d91e49ac6c9d3c64a96be007b6a94c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123680
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2019-10-31 15:02:03 +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
Paul Berry 12532e327f Analyzer ID test fix: annotate methods properly.
This avoids the need to special case test expectations for CFE in
pkg/front_end/test/flow_analysis/reachability/data/never_return_type.dart.

Change-Id: Ib754a76c96e73c8183b5ff10a2e7d2908e653a31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/123420
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-10-29 14:58:14 +00:00
Paul Berry 0167f91012 Flow analysis: introduce ID tests for AssignedVariables.
This should make it easier to verify that the CFE implementation is
correct.

Note that this effort encountered a few bugs in the analyzer
implementation, which are marked with TODOs.  I will fix them in
follow-up CLs.

Change-Id: Ic164a1cf214b5730f848b17db2838c29d25b00d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122850
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-10-25 13:44:05 +00:00
Paul Berry b700114b1c Flow analysis: clarify the names of testing data structures.
These data structures are only used for testing (and are not even
created in normal production use).  Add "ForTesting" to their names so
that we are less likely to use them by accident.

Change-Id: Ic719d66089a692362957e257c9bbb2f632bfd174
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122980
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-10-25 09:42:24 +00:00
Paul Berry 96952c2a8f Flow analysis: fix printing of types in type promotion tests.
Previously, we were using `DartType.toString` to check test
expectations, but `DartType.toString` currently doesn't show
nullabilities.  This isn't currently a problem because at the moment
all the type promotion tests use non-nullable types, but I will soon
be adding type promotion tests that use nullable types.

This CL fixes the problem by using `TypeImpl.toString` and passing in
`true` for the optional argument `withNullability`.

Change-Id: I6a2c6057c27c9205657143aa56088cc30a6510d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122822
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2019-10-24 19:56:37 +00:00
Paul Berry 5837c65b6e Flow analysis: test unreachability for constructor initializers.
This was already working, it just needed some updates to the test
infrastructure so we could test it properly.

Change-Id: Ie838fb50cf90aabd19c6e0c637df546ddcda16d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122584
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-10-23 15:50:10 +00:00
Paul Berry 8e23f76ac7 Flow analysis: properly handle promotion of type parameters.
When promoting a type parameter, we need to create an intersection
type (e.g. "T & int").  Such a type is represented in the analyzer and
the front end as a type parameter type pointing to the same type
variable, but with a different bound.

Change-Id: I1655f9242d913ca958c279cc80c3f6329f6b396d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122581
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-10-23 15:50:10 +00:00
Paul Berry 06a8577de2 Flow analysis: recursively annotate unreachable nodes in test
Previously, in the flow analysis reachability tests, we only annotated
a node as unreachable if it wasn't "covered" by a parent node that was
already marked as unreachable.  This made the tests more compact, but
it meant that the testing was less complete, because it meant that we
weren't verifying that the nodes inside of unreachable nodes were also
unreachable.

This CL changes the tests so that we mark every unreachable node as
unreachable, with one small exception: for an expression statement, we
don't mark the expression; we just mark the statement as unreachable,
and we have an assertion in the data extractor to verify that the
expression's reachability matches that of the statement.

Change-Id: I92454c72e9704b34e2dbafb9f5f19a8ee31f8f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122583
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2019-10-23 15:50:10 +00:00