|
@@ -139,7 +139,10 @@ let get_struct_init_super_info ctx c p =
|
|
let args = (try get_method_args ctor with Not_found -> []) in
|
|
let args = (try get_method_args ctor with Not_found -> []) in
|
|
let tl,el =
|
|
let tl,el =
|
|
List.fold_left (fun (args,exprs) (v,value) ->
|
|
List.fold_left (fun (args,exprs) (v,value) ->
|
|
- let opt = match value with Some _ -> true | None -> false in
|
|
|
|
|
|
+ let opt = match value with
|
|
|
|
+ | Some _ -> true
|
|
|
|
+ | None -> Meta.has Meta.Optional v.v_meta
|
|
|
|
+ in
|
|
let t = if opt then ctx.t.tnull v.v_type else v.v_type in
|
|
let t = if opt then ctx.t.tnull v.v_type else v.v_type in
|
|
(v.v_name,opt,t) :: args,(mk (TLocal v) v.v_type p) :: exprs
|
|
(v.v_name,opt,t) :: args,(mk (TLocal v) v.v_type p) :: exprs
|
|
) ([],[]) args
|
|
) ([],[]) args
|
|
@@ -181,6 +184,8 @@ let ensure_struct_init_constructor ctx c ast_fields p =
|
|
let v = alloc_var VGenerated cf.cf_name t p in
|
|
let v = alloc_var VGenerated cf.cf_name t p in
|
|
let ef = mk (TField(ethis,FInstance(c,params,cf))) cf.cf_type p in
|
|
let ef = mk (TField(ethis,FInstance(c,params,cf))) cf.cf_type p in
|
|
let ev = mk (TLocal v) v.v_type p in
|
|
let ev = mk (TLocal v) v.v_type p in
|
|
|
|
+ if opt && not (Meta.has Meta.Optional v.v_meta) then
|
|
|
|
+ v.v_meta <- (Meta.Optional,[],null_pos) :: v.v_meta;
|
|
(* this.field = <constructor_argument> *)
|
|
(* this.field = <constructor_argument> *)
|
|
let assign_expr = mk (TBinop(OpAssign,ef,ev)) cf.cf_type p in
|
|
let assign_expr = mk (TBinop(OpAssign,ef,ev)) cf.cf_type p in
|
|
let e =
|
|
let e =
|