Jelajahi Sumber

skip skip errors (closes #2232)

Simon Krajewski 9 tahun lalu
induk
melakukan
365c4b48ad

+ 8 - 0
tests/misc/projects/Issue2232/Main1.hx

@@ -0,0 +1,8 @@
+class Main1 {
+    static function main() {
+		var v : Float = 0;
+		foo(v,v);
+    }
+
+	static function foo(x=0,y=0) { }
+}

+ 8 - 0
tests/misc/projects/Issue2232/Main2.hx

@@ -0,0 +1,8 @@
+class Main1 {
+    static function main() {
+		var v : Float = 0;
+		foo(v);
+    }
+
+	static function foo(x=0,y:Float) { }
+}

+ 3 - 0
tests/misc/projects/Issue2232/compile1-fail.hxml

@@ -0,0 +1,3 @@
+-main Main1
+-swf swf.swf
+--no-output

+ 2 - 0
tests/misc/projects/Issue2232/compile1-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main1.hx:4: characters 6-7 : Float should be Int
+Main1.hx:4: characters 6-7 : For optional function argument 'x'

+ 3 - 0
tests/misc/projects/Issue2232/compile2-fail.hxml

@@ -0,0 +1,3 @@
+-main Main2
+-swf swf.swf
+--no-output

+ 1 - 0
tests/misc/projects/Issue2232/compile2-fail.hxml.stderr

@@ -0,0 +1 @@
+Main2.hx:4: characters 2-8 : Cannot skip non-nullable argument x

+ 6 - 1
typer.ml

@@ -679,9 +679,10 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 			null (ctx.t.tnull t) callp
 	in
 	let skipped = ref [] in
+	let invalid_skips = ref [] in
 	let skip name ul t =
 		if not ctx.com.config.pf_can_skip_non_nullable_argument && not (is_nullable t) then
-			call_error (Cannot_skip_non_nullable name) callp;
+			invalid_skips := name :: !invalid_skips;
 		skipped := (name,ul) :: !skipped;
 		default_value name t
 	in
@@ -692,6 +693,10 @@ let rec unify_call_args' ctx el args r callp inline force_inline =
 	in
 	let rec loop el args = match el,args with
 		| [],[] ->
+			begin match List.rev !invalid_skips with
+				| [] -> ()
+				| name :: _ -> call_error (Cannot_skip_non_nullable name) callp;
+			end;
 			[]
 		| _,[name,false,t] when (match follow t with TAbstract({a_path = ["haxe";"extern"],"Rest"},_) -> true | _ -> false) ->
 			begin match follow t with