Browse Source

punion_el for texpr

Aleksandr Kuzmenko 4 years ago
parent
commit
9de891c90d

+ 1 - 2
src/codegen/gencommon/gencommon.ml

@@ -1016,9 +1016,8 @@ let wrap_rest_args gen callee_type params p =
 				| _ ->
 					match Abstract.follow_with_abstracts t with
 					| TInst ({ cl_path = _,"NativeArray" }, [t1]) ->
-						let pos = punion_el (List.map (fun e -> ((),e.epos)) params) in
 						let t1 = if Common.defined gen.gcon Define.EraseGenerics then t_dynamic else t1 in
-						[mk_nativearray_decl gen t1 params pos]
+						[mk_nativearray_decl gen t1 params (punion_el params)]
 					| _ ->
 						die ~p "Unexpected rest arguments type" __LOC__
 				)

+ 15 - 0
src/core/texpr.ml

@@ -818,3 +818,18 @@ let reduce_unsafe_casts ?(require_cast=false) e t =
 	| { eexpr = TCast _ } as result -> result
 	| result when require_cast -> { e with eexpr = TCast(result,None) }
 	| result -> result
+
+let punion_el el =
+	match el with
+	| [] -> null_pos
+	| { epos = p } :: el ->
+		let rec loop pfile pmin pmax el =
+			match el with
+			| [] ->
+				null_pos
+			| { epos = p } :: [] ->
+				{ pfile = pfile; pmin = min pmin p.pmin; pmax = max pmax p.pmax }
+			| { epos = p } :: el ->
+				loop pfile (min pmin p.pmin) (max pmax p.pmax) el
+		in
+		loop p.pfile p.pmin p.pmax el

+ 1 - 1
src/generators/genswf9.ml

@@ -1431,7 +1431,7 @@ and args_as_array ctx mandatory_args spread_arg =
 	| [] ->
 		spread_arg
 	| _ ->
-		let p = punion_el (List.map (fun e -> ((),e.epos)) mandatory_args) in
+		let p = punion_el mandatory_args in
 		let array = mk (TArrayDecl mandatory_args) (ctx.com.basic.tarray t_dynamic) p in
 		let concat = mk (TField (array,FDynamic "concat")) t_dynamic spread_arg.epos in
 		mk (TCall (concat,[spread_arg])) (ctx.com.basic.tarray t_dynamic) (punion p spread_arg.epos)

+ 1 - 1
src/optimization/inline.ml

@@ -902,7 +902,7 @@ and inline_rest_params ctx f params map_type p =
 						let cf =
 							try PMap.find "of" c.cl_statics
 							with Not_found -> die ~p:c.cl_name_pos "Can't find haxe.Rest.of function" __LOC__
-						and p = punion_el (List.map (fun e -> (),e.epos) params) in
+						and p = punion_el params in
 						(* [param1, param2, ...] *)
 						(* If we don't know the type (e.g. the rest argument is a field type parameter) then we need
 						   to find a common type via unify_min. *)

+ 1 - 1
src/typing/callUnification.ml

@@ -125,7 +125,7 @@ let rec unify_call_args ctx el args r callp inline force_inline in_overload =
 						| _ when ExtType.is_mono (follow arg_t) ->
 							(try
 								let el = type_rest mk_mono in
-								unify ctx (unify_min ctx el) arg_t (punion_el (List.map (fun e -> ((),e.epos)) el));
+								unify ctx (unify_min ctx el) arg_t (punion_el el);
 								el
 							with WithTypeError(ul,p) ->
 								arg_error ul name false p)