Browse Source

show proper error message when a class method has different number of arguments than required in implemented interface (closes #3417)

Dan Korostelev 11 years ago
parent
commit
1d850c5796

+ 7 - 0
tests/misc/projects/Issue3417/Main.hx

@@ -0,0 +1,7 @@
+interface I {
+    function f(a:Int):Void;
+}
+
+class C implements I {
+    public function f() {} // missing `a` argument
+}

+ 1 - 0
tests/misc/projects/Issue3417/compile-fail.hxml

@@ -0,0 +1 @@
+Main

+ 2 - 0
tests/misc/projects/Issue3417/compile-fail.hxml.stderr

@@ -0,0 +1,2 @@
+Main.hx:6: characters 11-26 : Field f has different type than in I
+Main.hx:6: characters 11-26 : Different number of function arguments

+ 3 - 1
typeload.ml

@@ -710,7 +710,9 @@ let valid_redefinition ctx f1 t1 f2 t2 =
 	match f1.cf_kind,f2.cf_kind with
 	| Method m1, Method m2 when not (m1 = MethDynamic) && not (m2 = MethDynamic) ->
 		begin match follow t1, follow t2 with
-		| TFun (args1,r1) , TFun (args2,r2) when List.length args1 = List.length args2 -> (try
+		| TFun (args1,r1) , TFun (args2,r2) -> (
+			if not (List.length args1 = List.length args2) then raise (Unify_error [Unify_custom "Different number of function arguments"]);
+			try
 				List.iter2 (fun (n,o1,a1) (_,o2,a2) ->
 					if o1 <> o2 then raise (Unify_error [Not_matching_optional n]);
 					(try valid a2 a1 with Unify_error _ -> raise (Unify_error [Cannot_unify(a1,a2)]))