Skip to content

Commit e9352e9

Browse files
SamChou19815meta-codesync[bot]
authored andcommitted
[flow] Do not negate refinements for match cases
Summary: D85388235 will already do similar filtering based on the exhaustiveness checking system, so we don't need the negative refinements anymore. Changelog: [internal] Reviewed By: gkz Differential Revision: D85961519 fbshipit-source-id: 7c2106084fb0fb0c2bd12127cde9b7f4acd458da
1 parent c40d177 commit e9352e9

2 files changed

Lines changed: 8 additions & 15 deletions

File tree

src/analysis/env_builder/__tests__/env_builder_refinement_test.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7490,7 +7490,7 @@ let%expect_test "match_object_pattern" =
74907490
[%expect {|
74917491
[
74927492
(2, 1) to (2, 6) => {
7493-
{refinement = Or (Not (And (object, Not (Null))), Not (SentinelR type)); writes = {refinement = Or (Or (Not (And (object, Not (Null))), Not (SentinelR type)), Not (PropExistsR (value))); writes = (2, 1) to (2, 6): (`<match_root>`)}}
7493+
(2, 1) to (2, 6): (`<match_root>`)
74947494
};
74957495
(2, 8) to (2, 9) => {
74967496
Global x
@@ -7502,7 +7502,7 @@ let%expect_test "match_object_pattern" =
75027502
(3, 29) to (3, 30): (`a`)
75037503
};
75047504
(4, 2) to (4, 2) => {
7505-
{refinement = And (And (object, Not (Null)), SentinelR type); writes = {refinement = Or (Or (Not (And (object, Not (Null))), Not (SentinelR type)), Not (PropExistsR (value))); writes = (2, 1) to (2, 6): (`<match_root>`)}}
7505+
{refinement = And (And (object, Not (Null)), SentinelR type); writes = (2, 1) to (2, 6): (`<match_root>`)}
75067506
}]
75077507
|}]
75087508

@@ -7517,7 +7517,7 @@ let%expect_test "match_array_pattern" =
75177517
[%expect {|
75187518
[
75197519
(2, 1) to (2, 6) => {
7520-
{refinement = Or (Not (And (isArray, array length === 1)), Not (SentinelR 0)); writes = {refinement = Or (Not (And (isArray, array length === 2)), Not (SentinelR 0)); writes = (2, 1) to (2, 6): (`<match_root>`)}}
7520+
(2, 1) to (2, 6): (`<match_root>`)
75217521
};
75227522
(2, 8) to (2, 9) => {
75237523
Global x
@@ -7529,7 +7529,7 @@ let%expect_test "match_array_pattern" =
75297529
(3, 29) to (3, 30): (`a`)
75307530
};
75317531
(4, 2) to (4, 2) => {
7532-
{refinement = And (And (isArray, array length === 1), SentinelR 0); writes = {refinement = Or (Not (And (isArray, array length === 2)), Not (SentinelR 0)); writes = (2, 1) to (2, 6): (`<match_root>`)}}
7532+
{refinement = And (And (isArray, array length === 1), SentinelR 0); writes = (2, 1) to (2, 6): (`<match_root>`)}
75337533
}]
75347534
|}]
75357535

@@ -7543,7 +7543,7 @@ let%expect_test "match_instance_pattern" =
75437543
[%expect {|
75447544
[
75457545
(2, 1) to (2, 6) => {
7546-
{refinement = Or (Not (instanceof), Not (SentinelR b)); writes = {refinement = Or (Not (instanceof), Not (SentinelR a)); writes = (2, 1) to (2, 6): (`<match_root>`)}}
7546+
(2, 1) to (2, 6): (`<match_root>`)
75477547
};
75487548
(2, 8) to (2, 9) => {
75497549
Global x
@@ -7558,7 +7558,7 @@ let%expect_test "match_instance_pattern" =
75587558
(3, 22) to (3, 23): (`b`)
75597559
};
75607560
(4, 2) to (4, 2) => {
7561-
{refinement = And (instanceof, SentinelR b); writes = {refinement = Or (Not (instanceof), Not (SentinelR a)); writes = (2, 1) to (2, 6): (`<match_root>`)}}
7561+
{refinement = And (instanceof, SentinelR b); writes = (2, 1) to (2, 6): (`<match_root>`)}
75627562
};
75637563
(4, 2) to (4, 5) => {
75647564
Global Foo

src/analysis/env_builder/name_resolver.ml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
30343034
let env0 = this#env_snapshot in
30353035
let lexical_hoist = new lexical_hoister ~flowmin_compatibility:false ~enable_enums in
30363036
let bindings = lexical_hoist#eval lexical_hoist#match_pattern pattern in
3037-
let (completion_state, test_refinements) =
3037+
let completion_state =
30383038
this#with_bindings ~lexical:true case_loc bindings (fun _ ->
30393039
this#push_refinement_scope empty_refinements;
30403040
let arg =
@@ -3043,7 +3043,6 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
30433043
)
30443044
in
30453045
this#visit_match_pattern ~arg pattern;
3046-
let test_refinements = this#peek_new_refinements () in
30473046
(match this#get_val_of_expression arg with
30483047
| Some refined_value ->
30493048
let values =
@@ -3067,19 +3066,13 @@ module Make (Context : C) (FlowAPIUtils : F with type cx = Context.t) :
30673066
ignore @@ on_case_body body
30683067
)
30693068
in
3070-
(completion_state, test_refinements)
3069+
completion_state
30713070
)
30723071
in
30733072
let body_env_no_refinements = this#env_snapshot_without_latest_refinements in
30743073
let body_env_with_refinements = this#env_snapshot in
30753074
this#pop_refinement_scope ();
30763075
this#reset_env env0;
3077-
if Option.is_none guard then (
3078-
(* If there is a guard, it's possible the case didn't match
3079-
because of it, not because the pattern didn't match. *)
3080-
this#push_refinement_scope test_refinements;
3081-
this#negate_new_refinements ()
3082-
);
30833076
(body_env_no_refinements, body_env_with_refinements, completion_state)
30843077

30853078
method private visit_match_pattern ~arg root_pattern =

0 commit comments

Comments
 (0)