Skip to content

Commit c0e56cd

Browse files
committed
Implement default type param skipping
1 parent 22fa51d commit c0e56cd

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/syntax/grammar.ml

+2
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ and parse_complex_type_inner allow_named s = match%parser s with
710710
in
711711
let p = punion p1 p2 in
712712
CTPath (make_ptp (mk_type_path ~params:[TPType hint] (["haxe"],"Rest")) p),p
713+
| [ (Kwd Default,p) ] ->
714+
CTPath (make_ptp (mk_type_path (["$"],"_hx_default")) p),p
713715
| [ dollar_ident as n ] ->
714716
(match%parser s with
715717
| [ (DblDot,_); parse_complex_type as t ] when allow_named->

src/typing/typeload.ml

+11-6
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ 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 =
307-
match t with
308-
| TPExpr e ->
306+
let load_param t def =
307+
match (t, def) with
308+
| TPExpr e, _ ->
309309
let name = (match fst e with
310310
| EConst (String(s,_)) -> "S" ^ s
311311
| EConst (Int (_,_) as c) -> "I" ^ s_constant c
@@ -318,14 +318,18 @@ let rec load_params ctx info params p =
318318
let c = mk_class ctx.m.curmod ([],name) p (pos e) in
319319
c.cl_kind <- KExpr e;
320320
TInst (c,[]),pos e
321-
| TPType t ->
321+
| TPType (CTPath({ path = { tpackage = ["$"]; tname = "_hx_default" }}),p), None ->
322+
raise_typing_error "Cannot apply default type parameter on non-default type parameter" p
323+
| TPType (CTPath({ path = { tpackage = ["$"]; tname = "_hx_default" }}),p), Some def ->
324+
def,p
325+
| TPType t, _ ->
322326
load_complex_type ctx true LoadNormal t,pos t
323327
in
324328
let checks = DynArray.create () in
325329
let rec loop tl1 tl2 is_rest = match tl1,tl2 with
326330
| t :: tl1,ttp:: tl2 ->
327331
let name = ttp.ttp_name in
328-
let t,pt = load_param t in
332+
let t,pt = load_param t ttp.ttp_default in
329333
let check_const c =
330334
let is_expression = (match t with TInst ({ cl_kind = KExpr _ },_) -> true | _ -> false) in
331335
let expects_expression = name = "Const" || Meta.has Meta.Const c.cl_meta in
@@ -364,7 +368,7 @@ let rec load_params ctx info params p =
364368
t :: loop [] tl is_rest
365369
end
366370
| t :: tl,[] ->
367-
let t,pt = load_param t in
371+
let t,pt = load_param t None in
368372
if is_rest then
369373
t :: loop tl [] true
370374
else if ignore_error ctx.com then
@@ -443,6 +447,7 @@ and load_complex_type' ctx allow_display mode (t,p) =
443447
match t with
444448
| CTParent t -> load_complex_type ctx allow_display mode t
445449
| CTPath { path = {tpackage = ["$"]; tname = "_hx_mono" }} -> spawn_monomorph ctx p
450+
| CTPath { path = {tpackage = ["$"]; tname = "_hx_default" }} -> raise_typing_error "Invalid type : default" p
446451
| CTPath ptp -> load_instance ~allow_display ctx ptp ParamNormal mode
447452
| CTOptional _ -> raise_typing_error "Optional type not allowed here" p
448453
| CTNamed _ -> raise_typing_error "Named type not allowed here" p

0 commit comments

Comments
 (0)