dart-sdk/tests/language
Paul Berry 907e705307 Flow analysis: use a more precise split point for refutable patterns.
Previously, the flow control logic for patterns didn't use the
`FlowModel.split` or `FlowModel.unsplit` methods at all. This meant
that if a control flow join point occurred in pattern logic, flow
analysis would consider the split point to be whatever split point was
established by the enclosing expression or statement. In the case of
an if-case statement, it would consider the split point to be at the
beginning of the scrutinee expression.

Split points are used by flow analysis for the sole purpose of
ensuring that joins propagate type promotions the same way in dead
code as they do in live code (so that users introducing temporary
`throw` expressions or `return` statements into their code do not have
to deal with nuisance compile errors in the (now dead) code that
follows. The consequence of flow analysis considering the split point
to be at the beginning of the scrutinee expression is that if the
scrutinee expression is proven to always throw, then joins that arise
from the pattern or guard may not behave consistently with how they
would have behaved otherwise. For example:

    int getInt(Object o) => ...;
    void consumeInt(int i) { ... }
    test(int? i) {
      if (
          // (1)
          getInt('foo')
          case
              // (2)
              int()
          // (3)
          when i == null) {
      } else {
        // (4)
        consumeInt(i);
      }
    }

In the above code, there is a join point at (4), joining control flows
from (a) the situation where the pattern `int()` failed to match, and
(b) the situation where `i == null` evaluated to `false` (and hence
`i` is promoted to non-nullable `int`). Since the return type of
`getInt` is `int`, it's impossible for the pattern `int()` to fail, so
at the join point, control flow path (a) is considered
unreacable. Therefore the promotion from control flow path (b) is
kept, and so the call to `consumeInt` is valid.

In order to decide whether to preserve promotions from one of the
control flow paths leading up to a join, flow analysis only considers
reachability relative to the corresponding split point. Prior to this
change, the split point in question occurred at (1), so if the
expression `getInt('foo')` had been replaced with `getInt(throw
UnimplementedError())`, flow analysis would have considered both
control flow paths (a) and (b) to be unreachable relative to the split
point, so it would not have preserved the promotion from (b), and
there would have been a compile time error in the (now dead) call to
`consumeInt`.

This change moves the split point from (1) to (2), so that changing
`getInt('foo')` to `getInt(throw UnimplementedError())` no longer
causes any change in type promotion behavior.

The implementation of this change is to add calls to `FlowModel.split`
and `FlowModel.unsplit` around all top-level patterns. At first glance
this might appear to affect the behavior of all patterns, but actually
the only user-visible effect is on patterns in if-case statements,
because:

- In switch statements and switch expressions, there is already a
  split point before each case.

- In irrefutable patterns, there is no user-visible effect, because
  irrefutable patterns cannot fail to match, and therefore don't do
  any control flow joins.

This change allows the split points for patterns to be determined by a
simple syntactic rule, which will facilitate some refactoring of split
points that I am currently working on.

Change-Id: I55573ba5c28b2f2e6bba8731f9e3b02613b6beb2
Bug: https://github.com/dart-lang/sdk/issues/53167
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/319381
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2023-08-11 17:09:49 +00:00
..
abstract Migrate "a" directory language tests off @compile-error. 2023-04-20 20:50:39 +00:00
accessor_conflict
argument [analyzer] NOT_ENOUGH_POSITIONAL_ARGUMENTS 2022-10-11 17:56:11 +00:00
assert [dart2wasm] Emit code for assert initializers. 2023-01-05 00:23:40 +00:00
assign [analyzer] Issue 37238: Multiple errors for type mismatch assignments. 2023-05-19 16:27:58 +00:00
async Update flatten_test to avoid run-time errors and type inference anomaly 2023-06-15 09:47:02 +00:00
async_nested
async_star [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
await [tests] Avoid small --optimization-counter-threshold in tests 2022-10-10 21:04:18 +00:00
bool Remove uses of : as default value separator in some tests/ directories. 2022-09-07 14:49:17 +00:00
call Clean up a number of 2.19 opt outs in language tests. 2023-03-17 16:17:50 +00:00
canonicalize Spelling tests language 2022-12-19 16:30:06 +00:00
cascade Remove nbsp 2022-10-17 08:18:49 +00:00
class Remove left-over patch declarations for List constructor. 2023-04-22 00:38:28 +00:00
class_modifiers Breaking changes for analyzer version 6.0.0 2023-06-16 16:31:27 +00:00
closure [dart2wasm] Fix instantiation closure equality 2023-03-08 15:42:26 +00:00
compile_time_constant [analyzer] Move all constructor error reporting to _InstanceCreationEvaluator.evaluate 2023-08-08 21:55:34 +00:00
const [analyzer] Move all constructor error reporting to _InstanceCreationEvaluator.evaluate 2023-08-08 21:55:34 +00:00
const_functions [analyzer] Refactor visitMethodInvocation in the const evaluator. 2023-06-30 18:32:27 +00:00
constants_2018 [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
constructor [analyzer] Initial refactor of _InstanceCreationEvaluator to return Constant value. 2023-07-25 19:23:02 +00:00
control_flow_collections Simplify asyncExpectThrows and enhance Expect.throws. 2022-01-06 17:06:47 +00:00
covariant Add language test to reproduce #53089. 2023-08-02 12:02:38 +00:00
covariant_override Clean up a number of 2.19 opt outs in language tests. 2023-03-17 16:17:50 +00:00
deferred Clean up a number of 2.19 opt outs in language tests. 2023-03-17 16:17:50 +00:00
double
double_literals
dynamic [dart2wasm] Fix invocation forwarder named argument adjustment 2023-01-10 13:37:33 +00:00
enum [flip-modifiers] opt out from class modifiers some failing front end language tests 2023-03-02 20:40:20 +00:00
exception Migrate "e" and "f" directory language tests off @compile-error. 2023-04-20 20:49:17 +00:00
export Migrate "e" and "f" directory language tests off @compile-error. 2023-04-20 20:49:17 +00:00
extension_methods Fix typos 2022-06-10 15:48:54 +00:00
external_abstract_fields
factory Migrate "e" and "f" directory language tests off @compile-error. 2023-04-20 20:49:17 +00:00
field Migrate "e" and "f" directory language tests off @compile-error. 2023-04-20 20:49:17 +00:00
final [analyzer] Initial refactor of _InstanceCreationEvaluator to return Constant value. 2023-07-25 19:23:02 +00:00
function Spelling tests language 2022-12-19 16:30:06 +00:00
function_subtype Spelling tests standalone 2023-01-23 12:55:22 +00:00
function_type Remove uses of : as default value separator in some tests/ directories. 2022-09-07 14:49:17 +00:00
generic Migrate "g" - "i" directory language tests off @compile-error. 2023-04-19 22:09:18 +00:00
generic_methods Fix tearoff of methods from promotable variables. 2023-04-03 19:39:59 +00:00
getter Migrate "g" - "i" directory language tests off @compile-error. 2023-04-19 22:09:18 +00:00
identifier [cfe] Remove extra conditions on await-for in non-async body check 2023-05-09 06:56:44 +00:00
identity
if
if_null Issue 48004. Report when null-aware operator is used on type. 2022-05-29 19:03:15 +00:00
implicit_creation [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
implicit_downcast_during
import Migrate "g" - "i" directory language tests off @compile-error. 2023-04-19 22:09:18 +00:00
inference Migrate "g" - "i" directory language tests off @compile-error. 2023-04-19 22:09:18 +00:00
inference_update_1 Retire experiment flags introduced in 2.18. 2022-12-15 13:18:50 +00:00
inference_update_2 Test some more corner cases of field promotion. 2023-07-17 18:06:16 +00:00
initializing_formal Migrate "g" - "i" directory language tests off @compile-error. 2023-04-19 22:09:18 +00:00
instance [cfe] Add UnresolvedKind for fine grained unresolved reporting 2021-08-25 09:51:54 +00:00
instantiate_to_bound master branch to main 2021-09-15 06:22:23 +00:00
interceptor
interface Remove left-over patch declarations for List constructor. 2023-04-22 00:38:28 +00:00
invalid_returns
is Issue 51323. Don't parse RecordLiteral(s) before language 3.0 2023-05-26 18:22:34 +00:00
label [parser] Add beforeSynthetic to SyntheticStringToken 2021-08-30 11:56:30 +00:00
lazy Spelling tests 2023-01-19 16:24:29 +00:00
least_upper_bound
library Spelling tests language 2022-12-19 16:30:06 +00:00
list [parser] More specific error messages when recovering new/const/Map/Set/List with said literals 2021-03-25 13:27:03 +00:00
loop Migrate "l" and "m" directory language tests off @compile-error. 2023-04-20 17:51:42 +00:00
main [cfe] Support injected members in export scope 2023-05-24 09:21:20 +00:00
malbounded Migrate "l" and "m" directory language tests off @compile-error. 2023-04-20 17:51:42 +00:00
malformed Migrate "l" and "m" directory language tests off @compile-error. 2023-04-20 17:51:42 +00:00
map [dart2js] Better const Maps and Sets 2023-06-20 23:44:08 +00:00
metadata Remove uses of : as default value separator in some tests/ directories. 2022-09-07 14:49:17 +00:00
method Breaking changes for analyzer version 6.0.0 2023-06-16 16:31:27 +00:00
mixin Migrate "l" and "m" directory language tests off @compile-error. 2023-04-20 17:51:42 +00:00
mixin_constructor_forwarding Set tests that have mixin errors as 2.19. 2023-03-01 15:03:39 +00:00
mixin_declaration Migrate "l" and "m" directory language tests off @compile-error. 2023-04-20 17:51:42 +00:00
mixin_legacy Migrate "l" and "m" directory language tests off @compile-error. 2023-04-20 17:51:42 +00:00
named_arguments_anywhere [analyzer] Initial refactor of _InstanceCreationEvaluator to return Constant value. 2023-07-25 19:23:02 +00:00
new [cfe] Add UnresolvedKind for fine grained unresolved reporting 2021-08-25 09:51:54 +00:00
nnbd Update language tests to prepare for enabling interface-update-2. 2023-07-19 17:31:18 +00:00
no_such_method Migrate "n" through "p" directory language tests off @compile-error. 2023-04-20 17:56:18 +00:00
nonfunction_type_aliases Issue 52272. Report DEPRECATED_MIXIN_FUNCTION in more places. 2023-05-05 20:02:28 +00:00
nosuchmethod_forwarding Remove uses of : as default value separator in some tests/ directories. 2022-09-07 14:49:17 +00:00
null [flip-modifiers] opt out from class modifiers some failing front end language tests 2023-03-02 20:40:20 +00:00
null_aware Flag additional code as unreachable due to types Null and Never. 2022-08-22 16:50:19 +00:00
number Breaking changes for analyzer version 6.0.0 2023-06-16 16:31:27 +00:00
operator Migrate "n" through "p" directory language tests off @compile-error. 2023-04-20 17:56:18 +00:00
optimize Migrate "n" through "p" directory language tests off @compile-error. 2023-04-20 17:56:18 +00:00
override
parameter Migrate "n" through "p" directory language tests off @compile-error. 2023-04-20 17:56:18 +00:00
part [cfe] Include import paths in error for unavailable dart: libraries 2022-11-08 14:54:17 +00:00
patterns Flow analysis: use a more precise split point for refutable patterns. 2023-08-11 17:09:49 +00:00
prefix [cfe] Add UnresolvedKind for fine grained unresolved reporting 2021-08-25 09:51:54 +00:00
private pre-emptively fix some tests for class modifiers flag flip 2023-03-01 20:11:25 +00:00
propagate
records [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
redirecting Remove uses of : as default value separator in some tests/ directories. 2022-09-07 14:49:17 +00:00
reg_exp
regress [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
resolution
return Migrate "r" directory language tests off @compile-error. 2023-04-19 23:35:16 +00:00
rewrite
scaling [vm] Increase supported range of TypeParameters to 16 bits. 2022-12-14 23:34:18 +00:00
script Migrate "s" directory language tests off @compile-error. 2023-04-20 17:59:44 +00:00
sealed_class Breaking changes for analyzer version 6.0.0 2023-06-16 16:31:27 +00:00
set_literals
setter Migrate "s" directory language tests off @compile-error. 2023-04-20 17:59:44 +00:00
spread_collections Front end: Fix follow-on error arising from ill-typed spread element. 2021-03-04 15:52:57 +00:00
stack_trace
static Migrate "s" directory language tests off @compile-error. 2023-04-20 17:59:44 +00:00
string [analyzer] Initial refactor of _InstanceCreationEvaluator to return Constant value. 2023-07-25 19:23:02 +00:00
subtyping_static [dart2wasm] Fix isSubtype case of type parameter vs FutureOr 2023-08-11 09:08:32 +00:00
super Migrate "s" directory language tests off @compile-error. 2023-04-20 17:59:44 +00:00
superinterface_variance Set tests that have mixin errors as 2.19. 2023-03-01 15:03:39 +00:00
switch [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
symbol
sync_star Test for yield* of Iterable with throwing get:iterator 2023-04-14 22:04:28 +00:00
syntax [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
this Remove uses of : as default value separator in some tests/ directories. 2022-09-07 14:49:17 +00:00
top_level Migrate "t" directory language tests off @compile-error. 2023-04-20 19:55:31 +00:00
type [analyzer] Move all constructor error reporting to _InstanceCreationEvaluator.evaluate 2023-08-08 21:55:34 +00:00
type_object Fix typos 2022-06-15 11:08:28 +00:00
type_promotion
type_variable Migrate "t" directory language tests off @compile-error. 2023-04-20 19:55:31 +00:00
typedef Migrate "t" directory language tests off @compile-error. 2023-04-20 19:55:31 +00:00
unsorted Update flatten_test to avoid run-time errors and type inference anomaly 2023-06-15 09:47:02 +00:00
value_class
variable Fix year and comma in header. 2023-02-08 17:45:40 +00:00
variance [cfe,analyzer] Share experimental flags for the parser 2022-11-17 11:32:01 +00:00
vm [test] Update language/vm/type_cast_vm_test for AOT 2023-05-19 19:48:38 +00:00
void Migrate "u" and "v" directory language tests off @compile-error. 2023-04-20 22:33:22 +00:00
why_not_promoted Rename some more incorrectly named tests. 2021-06-03 00:49:54 +00:00
await_type_error_test.dart
await_type_test.dart
dynamic_type_helper.dart
explicit_type_instantiation_parsing_test.dart Remove references to constructor-tearoff experiment. 2021-11-11 14:04:43 +00:00
language.status [test] Update language/vm/type_cast_vm_test for AOT 2023-05-19 19:48:38 +00:00
language_analyzer.status [tests] Cleanup test with absent deferred library 2022-11-03 17:06:42 +00:00
language_dart2js.status [dart2js, ddc] Skip flaky tests 2023-02-13 23:44:59 +00:00
language_dart2wasm.status Fix web_int_literals_test.dart. 2023-04-25 21:28:39 +00:00
language_dartdevc.status [ddc] Temporarily skip tests that timeout 2023-05-11 23:03:38 +00:00
language_kernel.status Fix web_int_literals_test.dart. 2023-04-25 21:28:39 +00:00
language_precompiled.status [tests] Fix expectations in language/async_star/async_star_await_for_test 2023-02-27 16:25:50 +00:00
language_spec_parser.status Spelling tests language 2022-12-19 16:30:06 +00:00
language_vm.status [tests] Fix expectations in language/async_star/async_star_await_for_test 2023-02-27 16:25:50 +00:00
library1.dart
library2.dart
library10.dart
library11.dart
library12.dart
record_literal_problems_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
record_literal_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
record_type_empty_problems_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
record_type_problems_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
record_type_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
static_type_helper.dart [test] Fix constructor tear off tests in language 2021-07-23 08:41:09 +00:00
static_weak_reference_error_test.dart [dart2js] Static weak references to method tearoffs 2023-03-02 20:04:19 +00:00
static_weak_reference_function_apply_test.dart [dart2js] Static weak references to method tearoffs 2023-03-02 20:04:19 +00:00
static_weak_reference_test.dart [dart2js] Static weak references to method tearoffs 2023-03-02 20:04:19 +00:00
syntax_helper.dart Additional language tests for parsing behaviors around type arguments. 2021-05-18 14:06:13 +00:00