Permalink
Browse files

(Flash) detect singular constraint type parameters in fix_overrides a…

…nd handle them (closes #2712)
  • Loading branch information...
1 parent e0b2ea0 commit d4af4af3e0b20c140e35fbe4ed5197a2504dbadf @Simn Simn committed Mar 6, 2014
Showing with 33 additions and 0 deletions.
  1. +8 −0 codegen.ml
  2. +25 −0 tests/unit/issues/Issue2712.hx
View
@@ -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
@@ -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));
+ }
+}

0 comments on commit d4af4af

Please sign in to comment.