Ver código fonte

make sure all arguments to `trace` are stringified (closes #4712)

Simon Krajewski 9 anos atrás
pai
commit
623a24f309

+ 12 - 0
tests/misc/projects/Issue4712/Main.hx

@@ -0,0 +1,12 @@
+class Main {
+    static function main() {
+		haxe.Log.trace = function(s,?p) {
+			Sys.stderr().writeString("" + s + " " + p.customParams[0]);
+		}
+		var n:UInt = -4;
+		if ( n > 0 )
+			trace("positive", n);
+		else
+			trace("negative", n);
+    }
+}

+ 2 - 0
tests/misc/projects/Issue4712/compile.hxml

@@ -0,0 +1,2 @@
+-main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue4712/compile.hxml.stderr

@@ -0,0 +1 @@
+positive 4294967292

+ 3 - 3
typer.ml

@@ -4021,7 +4021,8 @@ and type_call ctx e el (with_type:with_type) p =
 		if Common.defined ctx.com Define.NoTraces then
 			null ctx.t.tvoid p
 		else
-		let params = (match el with [] -> [] | _ -> ["customParams",(EArrayDecl el , p)]) in
+		let mk_to_string_meta e = EMeta((Meta.ToString,[],pos e),e),pos e in
+		let params = (match el with [] -> [] | _ -> ["customParams",(EArrayDecl (List.map mk_to_string_meta el) , p)]) in
 		let infos = mk_infos ctx p params in
 		if (platform ctx.com Js || platform ctx.com Python) && el = [] && has_dce ctx.com then
 			let e = type_expr ctx e Value in
@@ -4035,8 +4036,7 @@ and type_call ctx e el (with_type:with_type) p =
 			let v_trace = alloc_unbound_var "`trace" t_dynamic in
 			mk (TCall (mk (TLocal v_trace) t_dynamic p,[e;infos])) ctx.t.tvoid p
 		else
-			let me = Meta.ToString,[],pos e in
-			type_expr ctx (ECall ((EField ((EField ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[(EMeta (me,e),pos e);infos]),p) NoValue
+			type_expr ctx (ECall ((EField ((EField ((EConst (Ident "haxe"),p),"Log"),p),"trace"),p),[mk_to_string_meta e;infos]),p) NoValue
 	| (EConst(Ident "callback"),p1),args ->
 		let ecb = try Some (type_ident_raise ctx "callback" p1 MCall) with Not_found -> None in
 		(match ecb with