Przeglądaj źródła

changed texpr.punion_el

Aleksandr Kuzmenko 4 lat temu
rodzic
commit
4929fa4777

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

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

+ 18 - 12
src/core/texpr.ml

@@ -819,17 +819,23 @@ let reduce_unsafe_casts ?(require_cast=false) e t =
 	| result when require_cast -> { e with eexpr = TCast(result,None) }
 	| result -> result
 
-let punion_el el =
+(**
+	Returns a position spanning from the first expr to the last expr in `el`.
+	Returns `default_pos` if `el` is empty or values of `pfile` of the first and
+	the last positions are different.
+*)
+let punion_el default_pos 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
+	| [] -> default_pos
+	| [{ epos = p }] -> p
+	| { epos = first } :: { epos = last } :: el ->
+		let rec loop = function
+			| [] -> last
+			| [{ epos = last }] -> last
+			| _ :: el -> loop el
 		in
-		loop p.pfile p.pmin p.pmax el
+		let last = loop el in
+		if first.pfile <> last.pfile then
+			default_pos
+		else
+			punion first last

+ 3 - 3
src/generators/genswf9.ml

@@ -1426,12 +1426,12 @@ let rec gen_expr_content ctx retval e =
 		end
 	| TIdent s ->
 		abort ("Unbound variable " ^ s) e.epos
-and args_as_array ctx mandatory_args spread_arg =
+and args_as_array ctx mandatory_args spread_arg p =
 	match mandatory_args with
 	| [] ->
 		spread_arg
 	| _ ->
-		let p = punion_el mandatory_args in
+		let p = punion_el p 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)
@@ -1444,7 +1444,7 @@ and gen_call ctx retval e el r =
 		and t_array_dyn = ctx.com.basic.tarray t_dynamic in
 		let t = TFun (["thisArg",false,t_dynamic; "argArray",false,t_array_dyn],r) in
 		let apply = mk (TField (e,FDynamic "apply")) t e.epos in
-		gen_call ctx retval apply [null; args_as_array ctx (List.rev el_rev) rest] r
+		gen_call ctx retval apply [null; args_as_array ctx (List.rev el_rev) rest e.epos] r
 	(* normal call without `...rest` *)
 	| _ ->
 	match e.eexpr , el with

+ 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 params in
+						and p = punion_el p 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 el);
+								unify ctx (unify_min ctx el) arg_t (punion_el callp el);
 								el
 							with WithTypeError(ul,p) ->
 								arg_error ul name false p)