Browse Source

allow abstract variance when checking constraints (closes #3781)

Simon Krajewski 10 years ago
parent
commit
e0bd2b0b14
2 changed files with 28 additions and 1 deletions
  1. 22 0
      tests/unit/src/unit/issues/Issue3781.hx
  2. 6 1
      type.ml

+ 22 - 0
tests/unit/src/unit/issues/Issue3781.hx

@@ -0,0 +1,22 @@
+package unit.issues;
+
+private enum E {
+	E1<T:String>(v:T);
+}
+
+private abstract Ab(String) to String {
+	public function new() {
+		this = "foo";
+	}
+}
+
+class Issue3781 extends Test {
+
+	function test() {
+		call(new Ab());
+	}
+
+	static function call<T:Ab>(v:T) {
+        E1(v);
+    }
+}

+ 6 - 1
type.ml

@@ -1523,7 +1523,12 @@ let rec unify a b =
 				loop cs (List.map (apply_params c.cl_params tl) tls)
 			) c.cl_implements
 			|| (match c.cl_kind with
-			| KTypeParameter pl -> List.exists (fun t -> match follow t with TInst (cs,tls) -> loop cs (List.map (apply_params c.cl_params tl) tls) | _ -> false) pl
+			| KTypeParameter pl -> List.exists (fun t ->
+				match follow t with
+				| TInst (cs,tls) -> loop cs (List.map (apply_params c.cl_params tl) tls)
+				| TAbstract(aa,tl) -> List.exists (unify_to aa tl b) aa.a_to
+				| _ -> false
+			) pl
 			| _ -> false)
 		in
 		if not (loop c1 tl1) then error [cannot_unify a b]