dart-sdk/tests/language/patterns
Paul Berry b026068313 Flow analysis: fix handling of list pattern type promotion.
When analyzing the type test implied by a pattern, flow analysis uses
three variables to control promotion behavior:

- `matchFailsIfWrongType`, which indicates whether flow analysis needs
  to account for the possible control flow path resulting from the
  type test failing. (This is `false` for cast patterns, because in
  the case where a cast pattern fails, an exception is thrown).

- `matchMayFailEvenIfCorrectType`, which indicates whether flow
  analysis needs to account for the possible control flow path
  resulting from the type test succeeding, but some other check
  causing the match to fail. (This is `true` for most list patterns,
  because the list pattern will fail to match if the list has the
  wrong length).

  (Note that `matchMayFailEvenIfCorrectType` doesn't account for the
  fact that a pattern match might fail due to failure in a subpattern
  match; this is automatically handled by the fact that flow analysis
  walks through the complete pattern in the order in which it
  executes.)

- `coversMatchedType`, which indicates whether the type test is
  guaranteed to succeed due to a subtype relationship between the
  matched value type and the type being tested (e.g. a `num x` pattern
  is guaranteed to succeed if the matched value type is `int`).

In the case where `matchFailsIfWrongType` is `true`,
`matchMayFailEvenIfCorrectType` is `true`, and `coversMatchedType` is
`false`, flow analysis must account for the fact that there are two
ways that the pattern match might fail: the type test might fail, or
the type test might succeed but then the pattern match might fail for
some other reason.

Before this change, this was done incorrectly, and flow analysis only
accounted for the possibility of the type test failing.

Fixes #55543.

Bug: https://github.com/dart-lang/sdk/issues/55543
Change-Id: I86603ec5f940402313f32177212b7960878db97f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364942
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2024-05-01 17:12:00 +00:00
..
exhaustiveness [cfe] Don't emit warnings on null-aware access on non-nullable 2024-03-20 14:04:29 +00:00
flow_analysis Flow analysis: fix handling of list pattern type promotion. 2024-05-01 17:12:00 +00:00
call_tear_off_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
call_tear_off_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
cast_from_dynamic_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
declared_variable_in_pattern_assignment_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
empty_switch_expression_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
for_in_nullable_error_test.dart Fix missing analyzer error when pattern for-in iterable is nullable. 2024-01-24 22:23:09 +00:00
guard_capture_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
guard_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
guard_scope_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
identifier_when_not_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
implicit_instantiation_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
implicit_instantiation_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
int_to_double_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
int_to_double_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
invalid_const_pattern_binary_test.dart [analyzer] Refactor visitPrefixExpression, visitNamedExpression, and visitParenthesizedExpression. 2023-06-22 20:48:48 +00:00
invalid_const_pattern_test.dart [analyzer] Refactor visitPrefixExpression, visitNamedExpression, and visitParenthesizedExpression. 2023-06-22 20:48:48 +00:00
invalid_inside_unary_pattern_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
invalid_inside_unary_pattern_parentheses_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
issue52202_error_test.dart Update CFE expectation for error test. 2023-05-01 21:27:12 +00:00
issue52409_test.dart Issue 52409. Reading a Never typed getter makes the flow unreachable. 2023-05-17 03:28:07 +00:00
issue54559_test.dart [cfe] Move hoisted variables after variable caches 2024-01-16 09:09:29 +00:00
issue_52439.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
keyword_in_pattern_variable_declaration_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
non_interface_object_pattern_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
nullable_object_pattern_error_test.dart Test object pattern behavior with nullable and potentially nullable types. 2023-05-02 18:01:53 +00:00
nullable_object_pattern_test.dart Test object pattern behavior with nullable and potentially nullable types. 2023-05-02 18:01:53 +00:00
object_pattern_inference_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
pattern_variable_constant_scope_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
primitive_switch_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
record_type_object_pattern_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
relational_pattern_expression_precedence_error_test.dart [cfe] Don't emit warnings on null-aware access on non-nullable 2024-03-20 14:04:29 +00:00
relational_pattern_expression_precedence_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
schema_test.dart Fix pattern context type schema for cast patterns. 2024-01-31 17:23:20 +00:00
shared_case_variable_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
shared_case_variable_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
switch_case_scope_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
switch_case_scope_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
switch_expression_using_statement_syntax_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
switch_trivial_exhaustiveness_error_test.dart [cfe] Don't emit warnings on null-aware access on non-nullable 2024-03-20 14:04:29 +00:00
type_question_before_when_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
var_keyword_in_typed_variable_pattern_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
var_keyword_in_typed_wildcard_pattern_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
version_2_29_changes_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
version_2_29_changes_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
version_2_32_changes_error_test.dart [cfe] Error on variable use before declaration, not on declaration 2023-10-03 10:51:15 +00:00
wildcard_in_matching_context_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
wildcard_in_pattern_assignment_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
wildcard_in_pattern_assignment_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
wildcard_in_pattern_variable_declaration_error_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00
wildcard_in_pattern_variable_declaration_test.dart [tests] Remove obsolete Dart 3.0 experiments from language tests 2023-06-15 08:26:27 +00:00