Commit Graph

229 Commits

Author SHA1 Message Date
Paul Berry b0b1534f3e Make checkUnassigned easier to debug in flow analysis tests.
This change adds a stack trace so that if the check fails, the user
sees the stack trace of the call to `checkUnassigned` prior to the
stack trace from the process of visiting the mini-AST.  Usually teh
stack trace from the call to `checkUnassigned` is much more useful in
debugging, since it allows the user to see the location of the problem
relative to the code being analyzed.

Change-Id: I125b4059ec740850919798cfa66bf7e8c7490213
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217283
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-10-19 19:49:03 +00:00
Paul Berry e5e8f84927 Rework how final and late are represented in flow analysis tests.
The fields `isFinal` and `isLate` are moved to the `Var` class.  This
should allow greater flexibility when experimenting with possible
changes in promotion behavior for final and late variables.

Bug: https://github.com/dart-lang/language/issues/1721
Change-Id: I3a328566b4a55244ca76c41da6e362066118d283
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217261
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-10-19 18:18:52 +00:00
Sam Rawlins 228e1062ee Move front_end's libraries.json parser to _fe_analyzer_shared
Bug: https://github.com/dart-lang/sdk/issues/35081
Change-Id: Idd1c68a871ace37e45970e5452a59fd655445fd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216100
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2021-10-11 17:59:43 +00:00
Paul Berry b65a18f54f Add a flow analysis ID test of new constructor-tearoffs behaviors.
These behaviors were introduced during the fix for
https://github.com/dart-lang/language/issues/1785, and at the time
they were tested using both unit tests and language tests.  But it was
not possible to write ID tests for them, because ID tests don't
support turning on experimental language feature flags.

Now that the "constructor-tearoffs" feature has been turned on we can
test these behaviors using ID tests.

Change-Id: I6e1ccda4b5837ab61de80f15d2f31a82a90b4a22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212265
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-09-07 21:39:46 +00:00
Konstantin Shcheglov b12724b7c6 Issue 47026. Use simple subtype check for combining signatures.
Bug: https://github.com/dart-lang/sdk/issues/47026
Change-Id: Id6999e0eaab03ffa0caa63c97b708526d22a8d97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211605
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2021-08-30 16:38:39 +00:00
Paul Berry 1b18e8f5ac Flow analysis: account for initializers of implicitly typed variables.
Previously, initializers of implicitly typed variables did not
contribute to the SSA tracking performed by flow analysis (see
https://github.com/dart-lang/language/issues/1785).  This change fixes
the bug, however the fix is conditioned on the "constructor tearoffs"
language feature to avoid compatibility issues (we don't want someone
to publish a package taking advantage of the fix, without realizing
that it makes their package unusable on older SDKs).

TEST=standard trybots
Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: I1143440c7a9795b059e8f4b84e3f4125cd80732c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211306
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-08-27 15:01:15 +00:00
Paul Berry e1f0d03ec5 Flow analysis: rework analyzer/CFE handling of initialized variables.
Previously, the analyzer and CFE were responsible for two pieces of
logic that arguably should be in the shared flow analysis engine:

- Deciding whether or not it's necessary to tell flow analysis about
  initializer expressions.

- Deciding whether or not to promote the variable at the time of
  initialization (we do this when the variable is implicitly typed,
  and the initializer is a promoted type variable type).

It's better to just always tell flow analysis about the initializer
expression and let it decide what to do about it.

This paves the way for fixing
https://github.com/dart-lang/language/issues/1785 (which results from
initializer expressions sometimes being ignored when they shouldn't
be), by consolidating the broken logic into the flow_analysis library,
where it will be easy to unit test the fix.

Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: Iec832e92995eb4f8d0c1fbd4e9be6c897e0917b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211180
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-08-27 14:53:06 +00:00
Paul Berry d2b313227d Flow analysis: Pin down initialization behaviors before fixing #1785.
https://github.com/dart-lang/language/issues/1785 has a wide enough
impact that its fix will have to be bundled in with a language version
(i.e. future versions of Dart will have to reproduce the old buggy
behavior for code that's not opted in to the latest language version).
Therefore, we'll have to maintain tests of the behavior both before
and after the fix.  This CL is the first step in that process, adding
tests that validate the current (buggy) behavior.

Bug: https://github.com/dart-lang/language/issues/1785
Change-Id: I78f17999ac1cbc096a312ef977db24654e06a263
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210400
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-08-25 20:32:02 +00:00
Paul Berry 389740cff9 Flow analysis: Add ID test cases for #46937.
Bug: https://github.com/dart-lang/sdk/issues/46937
Change-Id: Ic1073a4514ab59468881b6b641bf179187103140
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211041
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-08-24 21:00:04 +00:00
Johnni Winther 7e20b1c2b1 [cfe] Move option parsing code to _fe_analyzer_shared
This is in preparation for using it for parsing .options files in tests.

Change-Id: I1ee750ab48de53c4af03d3ce5082a76328851e47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208581
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-08-03 18:29:25 +00:00
Lasse R.H. Nielsen 43cff26365 Add supertype to enum classes.
TEST= language/enum/enum_test

Change-Id: I83b7fd1c29103c3aa4dc7ad3e41141fb8c62339e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203564
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-06-25 14:08:16 +00:00
Brian Wilkerson 06638483e1 Improve the highlight range for conflicting_generic_interfaces
Change-Id: I4ec19c1ceba747f5f23f7c95462de323fe76ecf6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200240
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
2021-05-18 20:42:33 +00:00
Paul Berry e3443b9f53 Flow analysis: implement "why not promoted" for binary/unary operator target.
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: If464a54bdb63fc661db312df5dc10f108049286a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196240
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-22 12:21:46 +00:00
Paul Berry b6fbee21d9 Flow analysis: additional "why not promoted" test cases.
These test cases already work properly, but they weren't previously
covered by tests.

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I4fc6506230af203a361631afc542e0db08bd6f27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196106
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-04-21 13:38:20 +00:00
Konstantin Shcheglov 375e878c35 Update nullability for TypeParameterType in tryPromoteToType()
Change-Id: Ifc8c32e3540577437c6448fa943d8cbbfebf0b62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196105
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2021-04-20 23:02:08 +00:00
Paul Berry add079c222 Flow analysis: Fix test function name.
In a previous commit, I accidentally named these test functions
`test`.  Replace with a more descriptive name.

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I662b6003a893dbb05fea88000f39e4e56b0cb725
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196107
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-20 21:59:18 +00:00
Paul Berry 68bb946fc5 Change analyzer ID test offsets for prefixed identifiers.
The ID test offset for a prefixed identifier is now the offset of the
identifier after the `.`.  This makes the analyzer and CFE behaviors
match much more closely, which eliminates a lot of nuisance
differences in the ID test expectations.

Change-Id: Icef1b2bf56b79bcf584d1eb153bdafd575e6cabb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195483
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-04-16 13:07:01 +00:00
Paul Berry 0ccb2771a3 Analyzer: change extent for assignability errors with named arguments
Previously, if a type mismatch occurred on a named argument, e.g.:

    int.fromEnvironment('foo', defaultValue: 'BAD')

the error would be reported on the entire NamedExpression
(`defaultValue: 'BAD'` in this example).  Now, the error is just
reported on the expression (`'BAD'` in this example).  This makes the
analyzer behavior more self-consistent (since now assignability errors
are now consistently reported at the site of the expression that can't
be assigned).  It also makes the analyzer behavior more consistent
with the CFE.

This will make it possible, in a follow-up CL, to eliminate a lot of
the inconsistencies between analyzer and CFE in the "why not promoted"
ID tests.

Change-Id: I17db256959d730a22a5766f65d5c0736b627f244
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195489
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-15 21:38:37 +00:00
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 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
Paul Berry 2ee741692f Add "why not promoted" support for explicit extension overrides.
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: Iea9300cf2cae52355bfa5a71f773c8136da2c644
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195306
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-15 12:13:27 +00:00
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
Johnni Winther 9dff91e2a5 [cfe] Add id testing for inferred type arguments
Change-Id: If932af54e184fcd7bb19a6889edf459c660f0cdb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195020
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2021-04-13 09:10:38 +00:00
Paul Berry 4d06516832 Introduce a "mini IR" representation for use in _fe_analyzer_shared testing.
This is a simple string-based intermediate representation for Dart
code, similar to kernel but with a far simpler structure and a compact
string encoding, suitable for use in unit tests.

I've integrated this representation into mini_ast.dart in a
preliminary way, so it is created as a by-product of running flow
analysis tests.  But as yet there are no tests that validate the
correctness of the result.  I plan to refine the representation, and
test it fully, in follow-up CLs.

Change-Id: Idda527efd005d0199ff88861c9e074eb651d82f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193881
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-12 12:46:06 +00:00
Paul Berry adc3c04e7b Flow analysis tests: add context parameter to Expression visit methods.
This paves the way for generalizing the "mini AST" code so that it can
do full type analysis.

For the moment, the context parameter is always `unknownType`.  In
later CLs I will thread the appropriate context types through the
system.

Change-Id: I5d5e0d6644dba590234e363d1d5d0720bdb71d30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194660
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-04-12 12:46:06 +00:00
Paul Berry a463217f0a Flow analysis tests: move most visitor logic into a new class.
The new class, _MiniAstTypeAnalyzer, currently only handles the "mini
AST" representation we use for flow analysis tests.  In follow up CLs
I plan to extract a base class from it that will be general enough to
form the basis of a shared type analysis engine for the analyzer and
the CFE.

Change-Id: I180e1484aff1733146ccf73bcab5604e9f4ef2f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194620
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-11 15:03:44 +00:00
Paul Berry 1f43993294 Flow analysis tests: remove _TryStatement._bodyNode.
Now that we store the body of a try statement as a separate Statement
object, we can use it directly; it's not necessary to create a
synthetic node for it.  This is more similar to what the analyzer and
CFE do.

Change-Id: I7c9a62aa917e966f0dd176f90b72865a38addd65
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194545
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-09 03:42:01 +00:00
Paul Berry ad4faa0e86 Flow analysis: in tests, stop storing type of this. property gets.
This makes the flow analysis tests more similar to the anaylzer and
CFE implementations, which look up the type of a `this.` property get
at the time it is analyzed, rather than storing it in the AST node.

Change-Id: Idee2a9c3ba0acbd2752db511c1aabfdff075b363
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194544
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-04-09 03:42:01 +00:00
Paul Berry 0d64396707 Flow analysis: Rework visit methods in flow analysis tests.
Two changes:

- Eliminate the `_Visitable` class, which was no longer used.

- Stop passing flow analysis as an argument to the _visit methods;
  instead access it through the Harness class.  This paves the way for
  future changes that will generalize this code for testing things
  other than flow analysis.

Change-Id: I94e9208e9eec6f16c03160efa1f676e57d47a59f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194541
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-09 00:23:40 +00:00
Paul Berry 363da90385 Fix "why not promoted" functionality for compound indexed assignment.
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I40c6087a0db2c67106f9ce138b79a8a5769b37de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193834
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-04-07 11:39:12 +00:00
Paul Berry b13dea3e1e Reland "Flow analysis: track property get targets."
This is a reland of bc6cdf54fd

Original change's description:
> Flow analysis: track property get targets.
>
> These targets are needed for "why not promoted" error messages, and
> it's easier to have flow analysis keep track of them than to have the
> analyzer and CFE try to reconstruct them at the time of reporting the
> error.
>
> Bug: https://github.com/dart-lang/sdk/issues/44898
> Change-Id: Ia8ef4a7ce13cc30860e59b7369e6230d233e252d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193832
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: Ib5e6a0eafb381f3a9c8770c6c1c3e55581e44b01
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194105
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: William Hesse <whesse@google.com>
2021-04-07 11:39:12 +00:00
Paul Berry cf7587a160 Revert "Flow analysis: track property get targets."
This reverts commit bc6cdf54fd.

Reason for revert: Broke Golem benchmarks - https://golem.corp.goog/PerformanceChanges?repository=dart&revision=91561

Original change's description:
> Flow analysis: track property get targets.
>
> These targets are needed for "why not promoted" error messages, and
> it's easier to have flow analysis keep track of them than to have the
> analyzer and CFE try to reconstruct them at the time of reporting the
> error.
>
> Bug: https://github.com/dart-lang/sdk/issues/44898
> Change-Id: Ia8ef4a7ce13cc30860e59b7369e6230d233e252d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193832
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>

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

Change-Id: Ic2b66b1db621c0f4e4c5398acfe2ae61bd7625ca
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/44898
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194104
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-06 11:49:09 +00:00
Paul Berry bc6cdf54fd Flow analysis: track property get targets.
These targets are needed for "why not promoted" error messages, and
it's easier to have flow analysis keep track of them than to have the
analyzer and CFE try to reconstruct them at the time of reporting the
error.

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: Ia8ef4a7ce13cc30860e59b7369e6230d233e252d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193832
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-04-06 06:55:28 +00:00
Paul Berry 0873d4eb82 Flow analysis: remove branchTarget() construct from unit tests.
Flow analysis unit tests now support implicit branch targets, and use
`LabeledStatement` directly in the case where the branch target is
explicit.  This is more similar to how the language acutally behaves,
and paves the way for adding more sophisticated tests in the future.

Note that at the moment, there are no flow analysis tests where a
`continue` statement has a different target than the innermost loop,
so for now, the `continue_` function doesn't accept a target
parameter.  I plan to add this functionality in the future, at the
time that I add tests that require it.

Change-Id: I2591ee3322ea4adba3e32dc76a29f0b3956058e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194040
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-05 12:19:07 +00:00
Paul Berry 2cfd6e421a Flow analysis: Use blocks internally in mini_ast representation.
For convenience in creating tests, the public mini_ast methods for
creating constructs like loops, try/catch, etc. accept lists of
statements as an argument where technically the language would expect
a single statement.  This CL changes the internal representation so
that each of these statement lists is converted into a single
statement by wrapping it in a block.

This makes the mini_ast representation more closely match the
representation used internally by the analyzer and CFE.

Change-Id: If2bf8a1cde694206b91b57c5907806b1965d4d99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193880
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-04-03 15:28:36 +00:00
Paul Berry 72bc3134c5 Unify "why not promoted" representations for for-loops and other writes.
This CL changes the responsibility for doing flow analysis of the
implicit variable write in a `for-in` loop as follows: if the `for-in`
loop does not declare a variable, but it assigns to a local variable,
then the flow analysis client is responsible for calling `write` on
entry to the loop.

This in turn allows us to use a single code path to track "why not
promoted" information related to all possible local variable writes;
we no longer need as much special case logic to handle for-in loops.

To make the analyzer integration slightly cleaner, we change the
argument type of FlowAnalysis.write to Node rather than Expression, so
that the analyzer can pass in the ForEachParts object when analyzing a
for-in loop.

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I24b47be8eac2e276cd291a5b2f2e4444c911138f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193837
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-04-03 15:28:36 +00:00
Paul Berry 104e364b5c Flow analysis: in unit tests, look up property get types in harness.
This makes the flow analysis unit tests more similar to the behavior
of the analyzer and CFE, in that the types of various properties are a
property of the program being analyzed, not of the individual property
gets themselves.

Change-Id: I6ea164665093ee285325a64e80f3f52d7a63cf74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193836
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-04-02 17:38:42 +00:00
Paul Berry c25e74852c Add links to "why not promoted" error messages.
These links are not live yet, but they will be filled in with
documentation explaining subtleties of type promotion in more detail.

Bug: https://github.com/dart-lang/sdk/issues/44900
Change-Id: I3e1865597fc5c56495a8108c8a4de98cab0c3e4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193749
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
2021-04-01 16:42:12 +00:00
Paul Berry 10d531b5f9 Flow analysis: Minor fixes to "why not promoted" ID tests.
The ID tests for the "why not promoted" feature had some minor
unintentional errors in them.  This CL fixes them:

- The constructor tests in
  argument_type_not_assignable_nullability_error.dart tried to return
  null from functions whose return type didn't allow it.

- The compoundAssignmentRhs test in
  argument_type_not_assignable_nullability_error.dart tried to add an
  `int` to an `int?`.  The CFE considers this to be an error, but also
  reports a follow-on error because it thinks the type of the
  resulting expression is `num` (which is not assignable back to
  `int`).  To avoid the follow-on error, we use `num` for the type of
  the variable to which compound assignment is being applied.

- The forElementInMap test in
  for_in_loop_type_not_iterable_nullability_error.dart wasn't a proper
  map (it contained two `null` elements, rather than a single map
  entry `null: null`, which was what was intended).

There were also several tests for which we *don't* expect "why not
promoted" information; I added comments explaining why.

Change-Id: I91ddb88cb0f25f9b209df3eeb75d57d8270f877b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193561
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2021-03-31 15:20:28 +00:00
Paul Berry 72ffbaa7d7 Rework _fe_analyzer_shared mini-AST to use an L-value abstraction.
Rather than representing an assignment differently depending on what
kind of construct appears on its left hand side (as kernel does), we
represent all assignments as a single `_Write` type, and use an
`LValue` base class to represent the different kinds of constructs
that can appear on the left hand side.  This representation will be
easier to expand into supporting more of the Dart language as we
expand the testing we want to be able to do in _fe_analyzer_shared.

Change-Id: I87b811176b2ba132fb992414c277cf2c6b81e03c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193180
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-30 21:07:01 +00:00
Paul Berry 6c30a7d582 Flow analysis: implement "why not promoted" logic for index expressions.
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I52a0fa33dbeb4f6382dd8b3154ead25ca2065878
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193088
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-30 18:24:11 +00:00
Johnni Winther 13556d623f [cfe] Add DartType.toNonNull
Add helper on DartType to compute the `NonNull` of a type and use this
instead of `withDeclaredNullability(Nullability.nonNullable).

Includes a fix in the computation of NonNull of FutureOr.

TEST=existing

Change-Id: I3399cbf89c7d3f3e90f1315b01f40957e798a1b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193400
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2021-03-30 10:25:28 +00:00
Paul Berry a7b0f5108d Flow analysis: implement "why not promoted" logic for compound assignments.
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I57a2c62b8450c313887b516d6fe2ef85fdd0d92b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193084
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-26 00:29:24 +00:00
Paul Berry 52a1fb3de2 Flow analysis: refactor handling of try/catch/finally in unit tests.
We now use a single AST node to represent try/catch/finally rather
than separate try/catch and try/finally nodes.  This more closely
parallels the data structures used by the analyzer and CFE.

Change-Id: Ic4c1f1e4ac9e10ebf36afa4047c9c8b9ce151a1f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193093
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-26 00:16:54 +00:00
Paul Berry e32ddc132f Flow analysis: refactor handling of this in unit tests.
The type of `this` is now stored in the test harness rather than in
the individual `this` AST objects.  This more closely parallels how
`this` is handled in the analyzer and CFE.

Change-Id: I7c60aec8a14680beecca161ad25d681b82f79a2b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193092
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-03-26 00:16:54 +00:00
Paul Berry f7419efa93 Fix some mismatched variable names in a flow analysis test.
Change-Id: I69f9822f9fe0e935a40fac0fced2d1512c234a64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193089
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-03-26 00:16:54 +00:00
Paul Berry b59bca4dc9 Flow analysis: Move mini_ast implementation to a shared location.
This will make it possible to use the same "mini AST" representation
to test other shared FE/analyzer code.

Change-Id: I8140bf1770f3bfe0ca8a959ba2c41babcb7852bb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193000
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2021-03-25 17:55:34 +00:00
Paul Berry f161e228e4 Flow analysis: implement "why not promoted" logic for assignments.
This CL handles ordinary assignment expressions, variable declaration
initializers, and constructor field initializers.

Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: I06bae2c7d57213bd7769c931a03080d148af3dbe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192724
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-03-25 02:01:33 +00:00
Paul Berry 20d9c6eb3a Flow analysis: implement "why not promoted" logic for boolean conditions
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: Ia8f3a5ad2971dfb6baeefb0d2f9c6998af0d897e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192611
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-03-24 12:10:09 +00:00
Paul Berry eb37227666 Flow analysis: implement "why not promoted" logic for logical binary operators.
Bug: https://github.com/dart-lang/sdk/issues/44898
Change-Id: If03750edf6bdf13fc2677e0c09f49f70d0da744e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192608
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
2021-03-24 12:10:09 +00:00