瀏覽代碼

fail differently if we're applying bad type params

see #11776
Simon Krajewski 9 月之前
父節點
當前提交
1e94858816
共有 2 個文件被更改,包括 18 次插入4 次删除
  1. 2 1
      src/core/tFunctions.ml
  2. 16 3
      src/macro/macroApi.ml

+ 2 - 1
src/core/tFunctions.ml

@@ -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 =
@@ -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 =

+ 16 - 3
src/macro/macroApi.ml

@@ -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
@@ -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