Browse Source

fix redefinition variance for the non-Dynamic case

How did nobody notice this?
Simon Krajewski 9 years ago
parent
commit
59ff4ecd8a
2 changed files with 35 additions and 2 deletions
  1. 33 0
      tests/unit/src/unit/issues/Issue3361.hx
  2. 2 2
      typeload.ml

+ 33 - 0
tests/unit/src/unit/issues/Issue3361.hx

@@ -0,0 +1,33 @@
+package unit.issues;
+
+private interface I {
+    public var v(default, never):Float;
+}
+
+private class C implements I {
+    public var v:Int;
+    public function new() { }
+}
+
+private interface I2 {
+	public var v(never, default):Int;
+}
+
+private class C2 implements I2 {
+	public var v:Float;
+	public function new() { }
+}
+
+class Issue3361 extends Test {
+	function test() {
+		var c = new C();
+		var i:I = c;
+		c.v = 12;
+		feq(12., i.v);
+
+		var c2 = new C2();
+		var i2:I2 = c2;
+		i2.v = 12;
+		feq(12., c.v);
+	}
+}

+ 2 - 2
typeload.ml

@@ -766,10 +766,10 @@ let valid_redefinition ctx f1 t1 f2 t2 =
 		end
 	| _,(Var { v_write = AccNo | AccNever }) ->
 		(* write variance *)
-		valid t2 t1
+		valid t1 t2
 	| _,(Var { v_read = AccNo | AccNever }) ->
 		(* read variance *)
-		valid t1 t2
+		valid t2 t1
 	| _ , _ ->
 		(* in case args differs, or if an interface var *)
 		type_eq EqStrict t1 t2;