Skip to content

Commit 69f9a1a

Browse files
Michael Thomasfacebook-github-bot
authored andcommitted
More special casing for solved tyvars
Summary: In legacy errors the reasons for tyvar solutions _replace_ the reason for the tyvar. In extended reasons we record the solution to ensure we don't destroy provenance. To recreate the legacy error messages we want to: 1) Propagate solutions through `Flow`s and use the solution reason when we find the corresponding tyvar 2) If a `Flow` doesn't contain a tyvar, use the outermost reason. This diff special cases the situation where we have a `Solved` reason wrapping a flow which doesn't contain a type variable Reviewed By: madgen Differential Revision: D63898873 fbshipit-source-id: fdeb515fdaa64fec728783d6a0ff7e2a92edf964
1 parent 4e816af commit 69f9a1a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

hphp/hack/src/typing/typing_reason.ml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,6 +2052,17 @@ let to_pos : type ph. ph t_ -> Pos_or_decl.t =
20522052
else
20532053
to_raw_pos r
20542054

2055+
let rec flow_contains_tyvar = function
2056+
| Flow
2057+
{
2058+
from = From_witness_locl (Type_variable_generics _ | Type_variable _);
2059+
_;
2060+
}
2061+
| From_witness_locl (Type_variable_generics _ | Type_variable _) ->
2062+
true
2063+
| Flow { into; _ } -> flow_contains_tyvar into
2064+
| _ -> false
2065+
20552066
(* Translate a reason to a (pos, string) list, suitable for error_l. This
20562067
* previously returned a string, however the need to return multiple lines with
20572068
* multiple locations meant that it needed to more than convert to a string *)
@@ -2078,8 +2089,9 @@ let rec to_string_help :
20782089
| Prj_one { part = r; _ } ->
20792090
to_string_help prefix solutions r
20802091
(* If we don't have a solution for a type variable use the origin of the flow *)
2081-
| Flow { from = r; _ } when Tvid.Map.is_empty solutions ->
2082-
to_string_help prefix solutions r
2092+
| Flow { from; _ }
2093+
when Tvid.Map.is_empty solutions || not (flow_contains_tyvar r) ->
2094+
to_string_help prefix solutions from
20832095
(* otherwise, follow the flow until we reach the type variable *)
20842096
| Flow { from; into; _ } ->
20852097
(match from with

0 commit comments

Comments
 (0)