|
@@ -590,6 +590,38 @@ let type_type_params ctx path get_params p (n,flags) =
|
|
|
delay ctx (fun () -> ignore(!r()));
|
|
|
n, TLazy r
|
|
|
|
|
|
+let type_function_params ctx fd fname fmeta p =
|
|
|
+ let params = ref [] in
|
|
|
+ params := List.map (fun (n,flags) ->
|
|
|
+ (match flags with
|
|
|
+ | [] -> ()
|
|
|
+ | _ ->
|
|
|
+ (** look if the type is contained into arguments **)
|
|
|
+ let rec lookup_type t =
|
|
|
+ match t with
|
|
|
+ | CTPath { tpackage = []; tname = n2 } when n = n2 -> true
|
|
|
+ | CTPath p -> List.exists lookup_tparam p.tparams
|
|
|
+ | CTFunction (cl,r) -> List.exists lookup_type (r::cl)
|
|
|
+ | CTExtend (_,fl) | CTAnonymous fl -> List.exists lookup_cfield fl
|
|
|
+ | CTOptional t | CTParent t -> lookup_type t
|
|
|
+ and lookup_cfield f =
|
|
|
+ match f.cff_kind with
|
|
|
+ | FVar (None,_) -> false
|
|
|
+ | FProp (_,_,t,_) | FVar (Some t,_) -> lookup_type t
|
|
|
+ | FFun f -> lookup_fun f
|
|
|
+ and lookup_fun f =
|
|
|
+ List.exists (fun (_,_,t,_) -> match t with None -> false | Some t -> lookup_type t) f.f_args ||
|
|
|
+ List.exists (fun (_,tl) -> List.exists lookup_type tl) f.f_params ||
|
|
|
+ (match f.f_type with None -> false | Some t -> lookup_type t)
|
|
|
+ and lookup_tparam = function
|
|
|
+ | TPType t -> lookup_type t
|
|
|
+ | TPExpr _ -> false
|
|
|
+ in
|
|
|
+ if lookup_fun { fd with f_type = None; f_params = [] } && not (has_meta ":allowConstraint" fmeta) then error "This notation is not allowed because it can't be checked" p);
|
|
|
+ type_type_params ctx ([],fname) (fun() -> !params) p (n,flags)
|
|
|
+ ) fd.f_params;
|
|
|
+ !params
|
|
|
+
|
|
|
let type_function ctx args ret fmode f p =
|
|
|
let locals = save_locals ctx in
|
|
|
let fargs = List.map (fun (n,c,t) ->
|
|
@@ -980,36 +1012,7 @@ let init_class ctx c p herits fields =
|
|
|
let delay = bind_var ctx cf e stat inline in
|
|
|
f, false, cf, delay
|
|
|
| FFun fd ->
|
|
|
- let params = ref [] in
|
|
|
- params := List.map (fun (n,flags) ->
|
|
|
- (match flags with
|
|
|
- | [] -> ()
|
|
|
- | _ ->
|
|
|
- (** look if the type is contained into arguments **)
|
|
|
- let rec lookup_type t =
|
|
|
- match t with
|
|
|
- | CTPath { tpackage = []; tname = n2 } when n = n2 -> true
|
|
|
- | CTPath p -> List.exists lookup_tparam p.tparams
|
|
|
- | CTFunction (cl,r) -> List.exists lookup_type (r::cl)
|
|
|
- | CTExtend (_,fl) | CTAnonymous fl -> List.exists lookup_cfield fl
|
|
|
- | CTOptional t | CTParent t -> lookup_type t
|
|
|
- and lookup_cfield f =
|
|
|
- match f.cff_kind with
|
|
|
- | FVar (None,_) -> false
|
|
|
- | FProp (_,_,t,_) | FVar (Some t,_) -> lookup_type t
|
|
|
- | FFun f -> lookup_fun f
|
|
|
- and lookup_fun f =
|
|
|
- List.exists (fun (_,_,t,_) -> match t with None -> false | Some t -> lookup_type t) f.f_args ||
|
|
|
- List.exists (fun (_,tl) -> List.exists lookup_type tl) f.f_params ||
|
|
|
- (match f.f_type with None -> false | Some t -> lookup_type t)
|
|
|
- and lookup_tparam = function
|
|
|
- | TPType t -> lookup_type t
|
|
|
- | TPExpr _ -> false
|
|
|
- in
|
|
|
- if lookup_fun { fd with f_type = None; f_params = [] } && not (has_meta ":allowConstraint" f.cff_meta) then error "This notation is not allowed because it can't be checked" p);
|
|
|
- type_type_params ctx ([],name) (fun() -> !params) p (n,flags)
|
|
|
- ) fd.f_params;
|
|
|
- let params = !params in
|
|
|
+ let params = type_function_params ctx fd f.cff_name f.cff_meta p in
|
|
|
if inline && c.cl_interface then error "You can't declare inline methods in interfaces" p;
|
|
|
let is_macro = (is_macro && stat) || has_meta ":macro" f.cff_meta in
|
|
|
let f, stat, fd = if not is_macro || stat then
|