Skip to content

Commit

Permalink
Tidy-up witness rendering
Browse files Browse the repository at this point in the history
Summary: Adds specific details for all flavors of `Pessimised_[...]` decl witnesses and remove rendering of the reason name in fallthrough cases

Reviewed By: mheiber

Differential Revision: D64824202

fbshipit-source-id: de607b5c532136b3c20fc88a9d1b025dab3b5c40
  • Loading branch information
Michael Thomas authored and facebook-github-bot committed Oct 25, 2024
1 parent 11aa333 commit 9a52ef1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
17 changes: 6 additions & 11 deletions hphp/hack/src/typing/typing_reason.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4039,25 +4039,23 @@ module Derivation = struct
| No_return pos ->
Explanation.Witness (Pos_or_decl.of_raw_pos pos, "declaration")
| Shape_literal pos ->
Explanation.Witness (Pos_or_decl.of_raw_pos pos, "shape literal")
Explanation.Witness (Pos_or_decl.of_raw_pos pos, "`shape` literal")
| Destructure pos ->
Explanation.Witness
(Pos_or_decl.of_raw_pos pos, "destructure expression")
| Join_point pos ->
Explanation.Witness (Pos_or_decl.of_raw_pos pos, "join point")
| _ ->
Explanation.Witness
( witness_locl_to_raw_pos witness,
Format.sprintf
"element (`%s`)"
(constructor_string_of_witness_locl witness) )
| _ -> Explanation.Witness (witness_locl_to_raw_pos witness, "element")

and explain_witness_decl witness =
match witness with
| Hint pos -> Explanation.Witness (pos, "hint")
| Witness_from_decl pos -> Explanation.Witness (pos, "declaration")
| Support_dynamic_type pos ->
Explanation.Witness (pos, "function or method declaration")
| Pessimised_inout pos -> Explanation.Witness (pos, "`inout` parameter")
| Pessimised_prop pos -> Explanation.Witness (pos, "property")
| Pessimised_this pos -> Explanation.Witness (pos, "`this` hint")
| Pessimised_return pos -> Explanation.Witness (pos, "return hint")
| Var_param_from_decl pos ->
Explanation.Witness (pos, "variadic parameter declaration")
Expand All @@ -4079,10 +4077,7 @@ module Derivation = struct
nm )
| _ ->
Explanation.Witness
( witness_decl_to_raw_pos witness,
Format.sprintf
"element (`%s`)"
(constructor_string_of_witness_decl witness) )
(witness_decl_to_raw_pos witness, Format.sprintf "declaration")

and explain_def (pos, reason) ~st ~cfg ~ctxt =
let (expl_reason, st) = explain_reason reason ~st ~cfg ~ctxt in
Expand Down
10 changes: 5 additions & 5 deletions hphp/hack/test/extended_reasons/bad_inout_lvalue9.php.exp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Here's why:

I started by checking this subtype relationship.

The subtype comes from this element (Rpessimised_inout)
The subtype comes from this inout parameter

File bad_inout_lvalue9.php, line 3, character 30 - line 3, character 31:

Expand All @@ -180,7 +180,7 @@ File bad_inout_lvalue9.php, line 6, character 11 - line 6, character 23:
6 | f(inout »tuple($x, $y)«);
7 | }

and flows into this element (Rpessimised_inout)
and flows into this inout parameter

File bad_inout_lvalue9.php, line 3, character 30 - line 3, character 31:

Expand Down Expand Up @@ -276,7 +276,7 @@ Here's why:

I started by checking this subtype relationship.

The subtype comes from this element (Rpessimised_inout)
The subtype comes from this inout parameter

File bad_inout_lvalue9.php, line 3, character 30 - line 3, character 31:

Expand All @@ -300,7 +300,7 @@ File bad_inout_lvalue9.php, line 6, character 11 - line 6, character 23:
6 | f(inout »tuple($x, $y)«);
7 | }

and flows into this element (Rpessimised_inout)
and flows into this inout parameter

File bad_inout_lvalue9.php, line 3, character 30 - line 3, character 31:

Expand All @@ -319,7 +319,7 @@ via an assignment

The subtype is a union type so next I checked the subtype constraint is satisfied for all its elements.

The subtype comes from this element (Rpessimised_inout)
The subtype comes from this inout parameter

File bad_inout_lvalue9.php, line 3, character 30 - line 3, character 31:

Expand Down

0 comments on commit 9a52ef1

Please sign in to comment.