Browse Source

(Flash) detect singular constraint type parameters in fix_overrides and handle them (closes #2712)

Simon Krajewski 11 years ago
parent
commit
d4af4af3e0
2 changed files with 33 additions and 0 deletions
  1. 8 0
      codegen.ml
  2. 25 0
      tests/unit/issues/Issue2712.hx

+ 8 - 0
codegen.ml

@@ -1106,6 +1106,14 @@ let fix_override com c f fd =
 			let nargs = List.map2 (fun ((v,ct) as cur) (_,_,t2) ->
 				try
 					type_eq EqStrict (monomorphs c.cl_types (monomorphs f.cf_params v.v_type)) t2;
+					(* Flash generates type parameters with a single constraint as that constraint type, so we
+					   have to detect this case and change the variable (issue #2712). *)
+					begin match follow v.v_type with
+						| TInst({cl_kind = KTypeParameter [tc]} as cp,_) when com.platform = Flash ->
+							if List.mem_assoc (snd cp.cl_path) c.cl_types then raise (Unify_error [])
+						| _ ->
+							()
+					end;
 					cur
 				with Unify_error _ ->
 					let v2 = alloc_var (prefix ^ v.v_name) t2 in

+ 25 - 0
tests/unit/issues/Issue2712.hx

@@ -0,0 +1,25 @@
+package unit.issues;
+import unit.Test;
+
+class Item implements Heapable {}
+
+interface Collection<T> {
+    function contains(x:T):Bool;
+}
+
+interface Heapable {}
+
+class Heap<T:(Heapable)> implements Collection<T> {
+    public function new() {}
+
+    public function contains(x:T):Bool {
+        return true;
+    }
+}
+
+class Issue2712 extends Test {
+	function test() {
+		var h = new Heap<Item>();
+		eq(true, h.contains(null));
+	}
+}