Skip to content

Commit ec197fb

Browse files
committed
Improve error handling
1 parent ab82248 commit ec197fb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/typing/typeload.ml

+10-5
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ let rec load_params ctx info params p =
303303
let is_rest = info.build_kind = BuildGenericBuild && (match info.build_params with [{ttp_name="Rest"}] -> true | _ -> false) in
304304
let is_java_rest = ctx.com.platform = Jvm && info.build_extern in
305305
let is_rest = is_rest || is_java_rest in
306-
let load_param t def =
306+
let load_param t ttp =
307307
match t with
308308
| TPExpr e ->
309309
let name = (match fst e with
@@ -319,9 +319,14 @@ let rec load_params ctx info params p =
319319
c.cl_kind <- KExpr e;
320320
TInst (c,[]),pos e
321321
| TPType (CTPath({ path = { tpackage = ["$"]; tname = "_hx_default" }}),p) ->
322-
(match def with
323-
| Some def -> def,p
324-
| None -> raise_typing_error "Cannot apply default type parameter on non-default type parameter" p
322+
(match ttp with
323+
| Some { ttp_default = Some def } -> def,p
324+
| Some ttp ->
325+
raise_typing_error (Printf.sprintf "Invalid default, type parameter %s has no default value" ttp.ttp_name) p
326+
| None when is_rest ->
327+
raise_typing_error "Cannot use default with rest type parameters" p
328+
| None ->
329+
raise_typing_error ("Too many type parameters for " ^ s_type_path info.build_path) p
325330
)
326331
| TPType t ->
327332
load_complex_type ctx true LoadNormal t,pos t
@@ -330,7 +335,7 @@ let rec load_params ctx info params p =
330335
let rec loop tl1 tl2 is_rest = match tl1,tl2 with
331336
| t :: tl1,ttp:: tl2 ->
332337
let name = ttp.ttp_name in
333-
let t,pt = load_param t ttp.ttp_default in
338+
let t,pt = load_param t (Some ttp) in
334339
let check_const c =
335340
let is_expression = (match t with TInst ({ cl_kind = KExpr _ },_) -> true | _ -> false) in
336341
let expects_expression = name = "Const" || Meta.has Meta.Const c.cl_meta in

0 commit comments

Comments
 (0)