Skip to content

Commit

Permalink
fail differently if we're applying bad type params
Browse files Browse the repository at this point in the history
see #11776
  • Loading branch information
Simn committed Oct 15, 2024
1 parent 5c19536 commit 1e94858
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/core/tFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ let dynamify_monos t =
loop t

exception ApplyParamsRecursion
exception ApplyParamsMismatch

(* substitute parameters with other types *)
let apply_params ?stack cparams params t =
Expand All @@ -442,7 +443,7 @@ let apply_params ?stack cparams params t =
match l1, l2 with
| [] , [] -> []
| ttp :: l1 , t2 :: l2 -> (ttp.ttp_class,t2) :: loop l1 l2
| _ -> die "" __LOC__
| _ -> raise ApplyParamsMismatch
in
let subst = loop cparams params in
let rec loop t =
Expand Down
19 changes: 16 additions & 3 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2266,8 +2266,10 @@ let macro_api ccom get_api =
let t = decode_type (field v "t") in
let default = None in (* we don't care here *)
let c = match t with
| TInst(c,_) -> c
| _ -> die "" __LOC__
| TInst(({cl_kind = KTypeParameter _} as c),_) ->
c
| _ ->
(get_api()).exc_string (Printf.sprintf "Unexpected type where type parameter was expected: %s" (s_type_kind t))
in
mk_type_param c TPHType default None
) (decode_array tpl) in
Expand All @@ -2281,7 +2283,18 @@ let macro_api ccom get_api =
end
| _ -> Type.map map t
in
encode_type (apply_params tpl tl (map (decode_type t)))
let t = (map (decode_type t)) in
let t = try
apply_params tpl tl t
with ApplyParamsMismatch ->
let msg = Printf.sprintf "Could not apply type parameters to %s:\n\tparams: %s\n\ttypes: %s"
(s_type_kind t)
(String.concat ", " (List.map (s_type_param s_type_kind) tpl))
(String.concat ", " (List.map s_type_kind tl))
in
(get_api()).exc_string msg
in
encode_type t
);
"include_file", vfun2 (fun file position ->
let file = decode_string file in
Expand Down

0 comments on commit 1e94858

Please sign in to comment.