2
0
Эх сурвалжийг харах

disallow Dynamic variance when redefining fields (closes #4378)

Let's see who complains!
Simon Krajewski 10 жил өмнө
parent
commit
4557c343af

+ 17 - 0
tests/misc/projects/Issue4378/Main.hx

@@ -0,0 +1,17 @@
+class Main implements I {
+
+	function new() { }
+
+	public function test(s:String) {
+		trace(s);
+	}
+
+	static function main() {
+		var m:I = new Main();
+		m.test(1);
+	}
+}
+
+interface I {
+	function test(s:Dynamic):Void;
+}

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

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

+ 3 - 0
tests/misc/projects/Issue4378/compile-fail.hxml.stderr

@@ -0,0 +1,3 @@
+Main.hx:5: lines 5-7 : Field test has different type than in I
+Main.hx:5: lines 5-7 : s : String -> Void should be s : Dynamic -> Void
+Main.hx:5: lines 5-7 : String should be Dynamic

+ 1 - 1
typeload.ml

@@ -713,7 +713,7 @@ let load_type_opt ?(opt=false) ctx p t =
 let valid_redefinition ctx f1 t1 f2 t2 =
 	let valid t1 t2 =
 		Type.unify t1 t2;
-		if is_null t1 <> is_null t2 then raise (Unify_error [Cannot_unify (t1,t2)]);
+		if is_null t1 <> is_null t2 || ((follow t1) == t_dynamic && (follow t2) != t_dynamic) then raise (Unify_error [Cannot_unify (t1,t2)]);
 	in
 	let t1, t2 = (match f1.cf_params, f2.cf_params with
 		| [], [] -> t1, t2