Browse Source

revert

The changed code here has some issues but this wasn't the solution...
Simon Krajewski 1 year ago
parent
commit
27eaca2803

+ 2 - 2
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
-		make_static_abstract_call ctx a pl c cf args p
+		Typecore.make_static_call ctx c cf (apply_params a.a_params pl) args t p
 
 and do_check_cast ctx uctx tleft eright p =
 	let recurse cf f =
@@ -49,7 +49,7 @@ and do_check_cast ctx uctx tleft eright p =
 		else match a.a_impl with
 			| Some c -> recurse cf (fun () ->
 				let ret = make_static_call ctx c cf a tl [eright] tleft p in
-				{ ret with eexpr = TMeta( (Meta.ImplicitCast,[],ret.epos), ret); etype = tleft }
+				{ ret with eexpr = TMeta( (Meta.ImplicitCast,[],ret.epos), ret) }
 			)
 			| None -> die "" __LOC__
 	in

+ 14 - 18
src/context/typecore.ml

@@ -234,24 +234,6 @@ 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
@@ -265,6 +247,20 @@ 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))
 

+ 3 - 3
src/core/texpr.ml

@@ -486,9 +486,9 @@ module Builder = struct
 		in
 		mk (TTypeExpr mt) t pos
 
-	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_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_throw e p =
 		mk (TThrow e) t_dynamic p

+ 18 - 3
src/filters/exceptions.ml

@@ -36,8 +36,13 @@ 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_class_call ctx.typer ctx.haxe_exception_class method_field args p
+	make_static_call ctx.typer ctx.haxe_exception_class method_field (fun t -> t) args return_type p
 
 (**
 	Generate `haxe_exception.method_name(args)`
@@ -69,8 +74,13 @@ 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_class_call ctx.typer std_cls isOfType_field [e; type_expr] p
+	make_static_call ctx.typer std_cls isOfType_field (fun t -> t) [e; type_expr] return_type p
 
 (**
 	Check if type path of `t` exists in `lst`
@@ -609,10 +619,15 @@ 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_class_call tctx native_stack_trace_cls method_field [catch_local] catch_var.v_pos
+					make_static_call tctx native_stack_trace_cls method_field (fun t -> t) [catch_local] return_type catch_var.v_pos
 				end
 			else
 				mk (TBlock[]) tctx.t.tvoid catch_var.v_pos

+ 1 - 1
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_access c cf cf.cf_type e.epos
+					Texpr.Builder.make_static_field c cf 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

+ 1 - 1
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_access c cf cf.cf_type p in
+			let efield = Texpr.Builder.make_static_field c cf 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

+ 3 - 3
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 (Texpr.Builder.make_static_this cl p)
+			| TClassDecl cl when cl.cl_path = path -> Some (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 (Texpr.Builder.make_static_this c p) "__implements" [o;t] tbool p)
+			Some (Texpr.Builder.fcall (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_abstract_call ctx a [t] c cf [array] p in
+						let e = make_static_call ctx c cf (apply_params a.a_params [t]) [array] (TAbstract(a,[t_params])) p in
 						[e]
 					| _ ->
 						die ~p:v.v_pos "Unexpected rest arguments type" __LOC__

+ 1 - 1
src/typing/fieldAccess.ml

@@ -2,7 +2,7 @@ open Typecore
 open Type
 open Error
 
-type field_access_mode =
+type field_host =
 	(* Get the plain expression with applied field type parameters. *)
 	| FGet
 	(* Does not apply field type parameters. *)

+ 2 - 2
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_abstract_call ctx a tl c cf_length [e] p
+				make_static_call ctx c cf_length (apply_params a.a_params tl) [e] ctx.com.basic.tint 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_abstract_call ctx a tl c cf [e_base;e_index] p
+					make_static_call ctx c cf (apply_params a.a_params tl) [e_base;e_index] r p
 				in
 				IteratorCustom(get_next,get_length),e,r
 			with Not_found ->

+ 1 - 1
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_access c cf cf.cf_type p
+	| ConStatic(c,cf) -> make_static_field c cf p
 	| ConFields _ -> raise_typing_error "Something went wrong" p
 
 let s_subject v_lookup s e =

+ 3 - 3
src/typing/operators.ml

@@ -408,6 +408,7 @@ 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;
@@ -436,11 +437,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_abstract_call ctx a tl c cf [e1';e2'] p in
+			let e = make_static_call ctx c cf map [e1';e2'] tret p in
 			let e = vr#to_texpr e in
 			BinopResult.create_special e needs_assign
 		end else
-			BinopResult.create_special (make_static_abstract_call ctx a tl c cf [e1;e2] p) needs_assign
+			BinopResult.create_special (make_static_call ctx c cf map [e1;e2] tret 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. *)
@@ -466,7 +467,6 @@ 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

+ 1 - 1
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_access c cf cf.cf_type (mk_zero_range_pos p)
+					Texpr.Builder.make_static_field c cf (mk_zero_range_pos p)
 				| _ -> die "" __LOC__
 			in
 			mk (TCall (e_Std_isOfType, [e; e_t])) ctx.com.basic.tbool p