Explorar el Código

added missing unification of multitype @:to functions with a_this, with a temp fix for HashMap (fixed issue #1564)

Simon Krajewski hace 12 años
padre
commit
b29f2d572a
Se han modificado 3 ficheros con 9 adiciones y 1 borrados
  1. 1 1
      std/Map.hx
  2. 6 0
      std/haxe/ds/HashMap.hx
  3. 2 0
      typeload.ml

+ 1 - 1
std/Map.hx

@@ -156,7 +156,7 @@ abstract Map< K, V > (IMap< K, V > ) {
 	}
 }
 
-private typedef IMap < K, V > = {
+typedef IMap < K, V > = {
 	public function get(k:K):Null<V>;
 	public function set(k:K, v:V):Void;
 	public function exists(k:K):Bool;

+ 6 - 0
std/haxe/ds/HashMap.hx

@@ -45,4 +45,10 @@ abstract HashMap<K:{ function hashCode():Int; }, V >({keys:IntMap<K>, values:Int
 	public inline function iterator() {
 		return this.values.iterator();
 	}
+	
+	// TODO: this is required because abstracts do not unify against structures even
+	// if they are structurally compatible
+	@:to function toIMap():Map.IMap<K,V> {
+		return untyped this;
+	}
 }

+ 2 - 0
typeload.ml

@@ -1484,6 +1484,8 @@ let init_class ctx c p context_init herits fields =
 					end else if Meta.has Meta.To f.cff_meta then begin
 						let ta = monomorphs a.a_types (monomorphs params a.a_this) in
 						(try unify_raise ctx t (tfun [ta] m) f.cff_pos with Error (Unify l,p) -> error (error_msg (Unify l)) p);
+						(* multitype @:to functions must unify with a_this *)
+						if Meta.has Meta.MultiType a.a_meta then delay ctx PFinal (fun () -> unify ctx m (monomorphs a.a_types a.a_this) f.cff_pos);
 						if not (Meta.has Meta.Impl cf.cf_meta) then cf.cf_meta <- (Meta.Impl,[],cf.cf_pos) :: cf.cf_meta;
 						a.a_to <- (follow m, Some cf) :: a.a_to
 					end else if Meta.has Meta.ArrayAccess f.cff_meta then begin