From 1142dbcf5ef36e440ade858a511f9a7af6b855d3 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 16 Sep 2014 23:19:19 +0200 Subject: [PATCH] fix haxe.PosInfos regression (closes #3348) --- tests/unit/issues/Issue3348.hx | 31 +++++++++++++++++++++++++++++++ typer.ml | 12 ++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 tests/unit/issues/Issue3348.hx diff --git a/tests/unit/issues/Issue3348.hx b/tests/unit/issues/Issue3348.hx new file mode 100644 index 00000000000..e0290d79f10 --- /dev/null +++ b/tests/unit/issues/Issue3348.hx @@ -0,0 +1,31 @@ +package unit.issues; + +class Issue3348 extends Test { + + function test() { + eq("unit.issues.Issue3348,Issue3348.hx,6,test", getPos1()); + eq("unit.issues.Issue3348,Issue3348.hx,7,test", getPos2()); + eq("unit.issues.Issue3348,Issue3348.hx,8,test", getPos3("ok")); + eq("unit.issues.Issue3348,Issue3348.hx,9,test", getPos4(1)); + } + + static function getPosString(p:haxe.PosInfos) { + return [p.className, p.fileName, Std.string(p.lineNumber), p.methodName].join(","); + } + + static function getPos1(?p:haxe.PosInfos) { + return getPosString(p); + } + + static function getPos2(?s:String, ?p:haxe.PosInfos) { + return getPosString(p); + } + + static function getPos3(s:String, ?p:haxe.PosInfos) { + return getPosString(p); + } + + static function getPos4(?s:String, ?i:Int, ?p:haxe.PosInfos) { + return getPosString(p); + } +} \ No newline at end of file diff --git a/typer.ml b/typer.ml index 30d38d8a1aa..61c7147df02 100644 --- a/typer.ml +++ b/typer.ml @@ -676,11 +676,13 @@ let rec unify_call_args' ctx el args r p inline force_inline = let err = Stack (Unify ul,Custom ("For " ^ (if opt then "optional " else "") ^ "function argument '" ^ name ^ "'")) in call_error (Could_not_unify err) p in + let mk_pos_infos t = + let infos = mk_infos ctx p [] in + type_expr ctx infos (WithType t) + in let rec default_value name t = if is_pos_infos t then - let infos = mk_infos ctx p [] in - let e = type_expr ctx infos (WithType t) in - e + mk_pos_infos t else null (ctx.t.tnull t) p in @@ -711,7 +713,9 @@ let rec unify_call_args' ctx el args r p inline force_inline = call_error Not_enough_arguments p | [],(name,true,t) :: args -> begin match loop [] args with - | [] when not (inline && (ctx.g.doinline || force_inline)) && not ctx.com.config.pf_pad_nulls -> [] + | [] when not (inline && (ctx.g.doinline || force_inline)) && not ctx.com.config.pf_pad_nulls -> + if is_pos_infos t then [mk_pos_infos t,true] + else [] | args -> let e_def = default_value name t in (e_def,true) :: args