diff --git a/src/context/abstractCast.ml b/src/context/abstractCast.ml index 38fb36d1854..5fb3e07ca16 100644 --- a/src/context/abstractCast.ml +++ b/src/context/abstractCast.ml @@ -23,7 +23,7 @@ let rec make_static_call ctx c cf a pl args t p = e | _ -> die "" __LOC__ end else - Typecore.make_static_call ctx c cf (apply_params a.a_params pl) args t p + make_static_abstract_call ctx a pl c cf args p and do_check_cast ctx uctx tleft eright p = let recurse cf f = diff --git a/src/context/typecore.ml b/src/context/typecore.ml index ef12371d70a..18755cbaa7b 100644 --- a/src/context/typecore.ml +++ b/src/context/typecore.ml @@ -234,6 +234,24 @@ let warning ?(depth=0) ctx w msg p = let make_call ctx e el t p = (!make_call_ref) ctx e el t p +let make_static_call_gen ctx c cf el map p = + let monos = Monomorph.spawn_constrained_monos map cf.cf_params in + let t = map (apply_params cf.cf_params monos cf.cf_type) in + match follow t with + | TFun(args,ret) -> + let ethis = Texpr.Builder.make_static_this c p in + let ef = mk (TField(ethis,FStatic(c,cf))) t p in + make_call ctx ef el ret p + | t -> + raise_typing_error (s_type (print_context()) t ^ " cannot be called") p + +let make_static_class_call ctx c cf el p = + make_static_call_gen ctx c cf el (fun t -> t) p + +let make_static_abstract_call ctx a tl c cf el p = + let map = apply_params a.a_params tl in + make_static_call_gen ctx c cf el map p + let type_expr ?(mode=MGet) ctx e with_type = (!type_expr_ref) ~mode ctx e with_type let unify_min ctx el = (!unify_min_ref) ctx el @@ -247,20 +265,6 @@ let spawn_monomorph' ctx p = let spawn_monomorph ctx p = TMono (spawn_monomorph' ctx p) -let make_static_this c p = - let ta = mk_anon ~fields:c.cl_statics (ref (ClassStatics c)) in - mk (TTypeExpr (TClassDecl c)) ta p - -let make_static_field_access c cf t p = - let ethis = make_static_this c p in - mk (TField (ethis,(FStatic (c,cf)))) t p - -let make_static_call ctx c cf map args t p = - let monos = List.map (fun _ -> spawn_monomorph ctx p) cf.cf_params in - let map t = map (apply_params cf.cf_params monos t) in - let ef = make_static_field_access c cf (map cf.cf_type) p in - make_call ctx ef args (map t) p - let raise_with_type_error ?(depth = 0) msg p = raise (WithTypeError (make_error ~depth (Custom msg) p)) diff --git a/src/core/texpr.ml b/src/core/texpr.ml index c983ce202b5..34febf7e45e 100644 --- a/src/core/texpr.ml +++ b/src/core/texpr.ml @@ -486,9 +486,9 @@ module Builder = struct in mk (TTypeExpr mt) t pos - let make_static_field c cf p = - let e_this = make_static_this c p in - mk (TField(e_this,FStatic(c,cf))) cf.cf_type p + let make_static_field_access c cf t p = + let ethis = make_static_this c p in + mk (TField (ethis,(FStatic (c,cf)))) t p let make_throw e p = mk (TThrow e) t_dynamic p diff --git a/src/filters/exceptions.ml b/src/filters/exceptions.ml index a9c97dfdea7..4db3d1c300e 100644 --- a/src/filters/exceptions.ml +++ b/src/filters/exceptions.ml @@ -36,13 +36,8 @@ let haxe_exception_static_call ctx method_name args p = try PMap.find method_name ctx.haxe_exception_class.cl_statics with Not_found -> raise_typing_error ("haxe.Exception has no field " ^ method_name) p in - let return_type = - match follow method_field.cf_type with - | TFun(_,t) -> t - | _ -> raise_typing_error ("haxe.Exception." ^ method_name ^ " is not a function and cannot be called") p - in add_dependency ctx.typer.curclass.cl_module ctx.haxe_exception_class.cl_module; - make_static_call ctx.typer ctx.haxe_exception_class method_field (fun t -> t) args return_type p + make_static_class_call ctx.typer ctx.haxe_exception_class method_field args p (** Generate `haxe_exception.method_name(args)` @@ -74,13 +69,8 @@ let std_is ctx e t p = try PMap.find "isOfType" std_cls.cl_statics with Not_found -> raise_typing_error ("Std has no field isOfType") p in - let return_type = - match follow isOfType_field.cf_type with - | TFun(_,t) -> t - | _ -> raise_typing_error ("Std.isOfType is not a function and cannot be called") p - in let type_expr = { eexpr = TTypeExpr(module_type_of_type t); etype = t; epos = p } in - make_static_call ctx.typer std_cls isOfType_field (fun t -> t) [e; type_expr] return_type p + make_static_class_call ctx.typer std_cls isOfType_field [e; type_expr] p (** Check if type path of `t` exists in `lst` @@ -619,15 +609,10 @@ let insert_save_stacks tctx = try PMap.find "saveStack" native_stack_trace_cls.cl_statics with Not_found -> raise_typing_error ("haxe.NativeStackTrace has no field saveStack") null_pos in - let return_type = - match follow method_field.cf_type with - | TFun(_,t) -> t - | _ -> raise_typing_error ("haxe.NativeStackTrace." ^ method_field.cf_name ^ " is not a function and cannot be called") null_pos - in let catch_local = mk (TLocal catch_var) catch_var.v_type catch_var.v_pos in begin add_dependency tctx.curclass.cl_module native_stack_trace_cls.cl_module; - make_static_call tctx native_stack_trace_cls method_field (fun t -> t) [catch_local] return_type catch_var.v_pos + make_static_class_call tctx native_stack_trace_cls method_field [catch_local] catch_var.v_pos end else mk (TBlock[]) tctx.t.tvoid catch_var.v_pos diff --git a/src/filters/filters.ml b/src/filters/filters.ml index e94d42b4378..6b92baf67d9 100644 --- a/src/filters/filters.ml +++ b/src/filters/filters.ml @@ -116,7 +116,7 @@ module LocalStatic = struct | TLocal v when has_var_flag v VStatic -> begin try let cf = find_local_static local_static_lut v in - Texpr.Builder.make_static_field c cf e.epos + Texpr.Builder.make_static_field_access c cf cf.cf_type e.epos with Not_found -> raise_typing_error (Printf.sprintf "Could not find local static %s (id %i)" v.v_name v.v_id) e.epos end diff --git a/src/generators/genjvm.ml b/src/generators/genjvm.ml index b3189657ca5..c8a86977704 100644 --- a/src/generators/genjvm.ml +++ b/src/generators/genjvm.ml @@ -2517,7 +2517,7 @@ class tclass_to_jvm gctx c = object(self) let jm = jc#spawn_field cf.cf_name jsig flags in let default e = let p = null_pos in - let efield = Texpr.Builder.make_static_field c cf p in + let efield = Texpr.Builder.make_static_field_access c cf cf.cf_type p in let eop = mk (TBinop(OpAssign,efield,e)) cf.cf_type p in begin match c.cl_init with | None -> c.cl_init <- Some eop diff --git a/src/optimization/inline.ml b/src/optimization/inline.ml index 4334510802e..c44e9ce6838 100644 --- a/src/optimization/inline.ml +++ b/src/optimization/inline.ml @@ -111,7 +111,7 @@ let api_inline ctx c field params p = let m = (try ctx.com.module_lut#find path with Not_found -> die "" __LOC__) in add_dependency ctx.m.curmod m; Option.get (ExtList.List.find_map (function - | TClassDecl cl when cl.cl_path = path -> Some (make_static_this cl p) + | TClassDecl cl when cl.cl_path = path -> Some (Texpr.Builder.make_static_this cl p) | _ -> None ) m.m_types) in @@ -171,7 +171,7 @@ let api_inline ctx c field params p = None) | (["js"],"Boot"),"__downcastCheck",[o; {eexpr = TTypeExpr (TClassDecl cls) } as t] when ctx.com.platform = Js -> if (has_class_flag cls CInterface) then - Some (Texpr.Builder.fcall (make_static_this c p) "__implements" [o;t] tbool p) + Some (Texpr.Builder.fcall (Texpr.Builder.make_static_this c p) "__implements" [o;t] tbool p) else Some (Texpr.Builder.fcall (eJsSyntax()) "instanceof" [o;t] tbool p) | (["cs" | "java"],"Lib"),("nativeArray"),[{ eexpr = TArrayDecl args } as edecl; _] @@ -927,7 +927,7 @@ and inline_rest_params ctx f params map_type p = in let array = mk (TArrayDecl params) (ctx.t.tarray t_params) p in (* haxe.Rest.of(array) *) - let e = make_static_call ctx c cf (apply_params a.a_params [t]) [array] (TAbstract(a,[t_params])) p in + let e = make_static_abstract_call ctx a [t] c cf [array] p in [e] | _ -> die ~p:v.v_pos "Unexpected rest arguments type" __LOC__ diff --git a/src/typing/fieldAccess.ml b/src/typing/fieldAccess.ml index 2f47ebda5d8..5d6381e9fdb 100644 --- a/src/typing/fieldAccess.ml +++ b/src/typing/fieldAccess.ml @@ -2,7 +2,7 @@ open Typecore open Type open Error -type field_host = +type field_access_mode = (* Get the plain expression with applied field type parameters. *) | FGet (* Does not apply field type parameters. *) diff --git a/src/typing/forLoop.ml b/src/typing/forLoop.ml index d42a8a7cde7..88fbf6b5834 100644 --- a/src/typing/forLoop.ml +++ b/src/typing/forLoop.ml @@ -139,7 +139,7 @@ module IterationKind = struct | TAbstract({a_impl = Some c} as a,tl) -> let cf_length = PMap.find "get_length" c.cl_statics in let get_length e p = - make_static_call ctx c cf_length (apply_params a.a_params tl) [e] ctx.com.basic.tint p + make_static_abstract_call ctx a tl c cf_length [e] p in (match follow cf_length.cf_type with | TFun(_,tr) -> @@ -155,7 +155,7 @@ module IterationKind = struct let todo = mk (TConst TNull) ctx.t.tint p in let cf,_,r,_ = AbstractCast.find_array_read_access_raise ctx a tl todo p in let get_next e_base e_index t p = - make_static_call ctx c cf (apply_params a.a_params tl) [e_base;e_index] r p + make_static_abstract_call ctx a tl c cf [e_base;e_index] p in IteratorCustom(get_next,get_length),e,r with Not_found -> diff --git a/src/typing/matcher/texprConverter.ml b/src/typing/matcher/texprConverter.ml index 8b234e6f9bd..4b01e5cfb2f 100644 --- a/src/typing/matcher/texprConverter.ml +++ b/src/typing/matcher/texprConverter.ml @@ -24,7 +24,7 @@ let constructor_to_texpr ctx con = | ConConst ct -> make_const_texpr ctx.com.basic ct p | ConArray i -> make_int ctx.com.basic i p | ConTypeExpr mt -> TyperBase.type_module_type ctx mt p - | ConStatic(c,cf) -> make_static_field c cf p + | ConStatic(c,cf) -> make_static_field_access c cf cf.cf_type p | ConFields _ -> raise_typing_error "Something went wrong" p let s_subject v_lookup s e = diff --git a/src/typing/operators.ml b/src/typing/operators.ml index 3c9d92f035d..423fe06a892 100644 --- a/src/typing/operators.ml +++ b/src/typing/operators.ml @@ -408,7 +408,6 @@ let make_binop ctx op e1 e2 is_assign_op with_type p = die "" __LOC__ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type p = - let map = apply_params a.a_params tl in let make op_cf cf e1 e2 tret needs_assign swapped = if cf.cf_expr = None && not (has_class_field_flag cf CfExtern) then begin if not (Meta.has Meta.NoExpr cf.cf_meta) then Common.display_error ctx.com "Recursive operator method" p; @@ -437,11 +436,11 @@ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type let vr = new value_reference ctx in let e2' = vr#as_var "lhs" e2 in let e1' = vr#as_var "rhs" e1 in - let e = make_static_call ctx c cf map [e1';e2'] tret p in + let e = make_static_abstract_call ctx a tl c cf [e1';e2'] p in let e = vr#to_texpr e in BinopResult.create_special e needs_assign end else - BinopResult.create_special (make_static_call ctx c cf map [e1;e2] tret p) needs_assign + BinopResult.create_special (make_static_abstract_call ctx a tl c cf [e1;e2] p) needs_assign in (* special case for == and !=: if the second type is a monomorph, assume that we want to unify it with the first type to preserve comparison semantics. *) @@ -467,6 +466,7 @@ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type let check e1 e2 swapped = let map_arguments () = let monos = Monomorph.spawn_constrained_monos (fun t -> t) cf.cf_params in + let map = apply_params a.a_params tl in let map t = map (apply_params cf.cf_params monos t) in let t1 = map t1 in let t2 = map t2 in diff --git a/src/typing/typer.ml b/src/typing/typer.ml index aced3ca13b0..ec6c2a45216 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -2015,7 +2015,7 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) = try PMap.find "isOfType" c.cl_statics with Not_found -> die "" __LOC__ in - Texpr.Builder.make_static_field c cf (mk_zero_range_pos p) + Texpr.Builder.make_static_field_access c cf cf.cf_type (mk_zero_range_pos p) | _ -> die "" __LOC__ in mk (TCall (e_Std_isOfType, [e; e_t])) ctx.com.basic.tbool p