Răsfoiți Sursa

properly recurse when dealing with abstract variance (closes #3063)

Simon Krajewski 11 ani în urmă
părinte
comite
34262130d8
2 a modificat fișierele cu 31 adăugiri și 4 ștergeri
  1. 25 0
      tests/unit/issues/Issue3063.hx
  2. 6 4
      type.ml

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

@@ -0,0 +1,25 @@
+package unit.issues;
+
+@:enum
+private abstract AString(String) to String {
+    var CTOR1 = "foo";
+}
+
+@:enum
+private abstract AInt(Int) to Int {
+    var CTOR2 = 12;
+}
+
+class Issue3063 extends Test {
+	function test() {
+		var a = new Map();
+		a.set(CTOR1, 1);
+		eq(1, a.get(CTOR1));
+		t(Std.is(a, haxe.ds.StringMap));
+
+		var b = new Map();
+		b.set(CTOR2, 1);
+		eq(1, b.get(CTOR2));
+		t(Std.is(b, haxe.ds.IntMap));
+	}
+}

+ 6 - 4
type.ml

@@ -1535,16 +1535,18 @@ and unify_to_field ab tl b ?(allow_transitive_cast=true) (t,cfo) =
 	r
 	end
 
-and unify_with_variance t1 t2 =
+and unify_with_variance f t1 t2 =
 	let allows_variance_to t (tf,cfo) = match cfo with
 		| None -> type_iseq tf t
 		| Some _ -> false
 	in
 	match follow t1,follow t2 with
 	| TInst(c1,tl1),TInst(c2,tl2) when c1 == c2 ->
-		List.iter2 unify_with_variance tl1 tl2
+		List.iter2 f tl1 tl2
 	| TEnum(en1,tl1),TEnum(en2,tl2) when en1 == en2 ->
-		List.iter2 unify_with_variance tl1 tl2
+		List.iter2 f tl1 tl2
+	| TAbstract(a1,tl1),TAbstract(a2,tl2) when a1 == a2 && Meta.has Meta.CoreType a1.a_meta ->
+		List.iter2 f tl1 tl2
 	| TAbstract(a1,pl1),TAbstract(a2,pl2) ->
 		let ta1 = apply_params a1.a_types pl1 a1.a_this in
 		let ta2 = apply_params a2.a_types pl2 a2.a_this in
@@ -1574,7 +1576,7 @@ and with_variance f t1 t2 =
 	try
 		f t1 t2
 	with Unify_error l -> try
-		unify_with_variance t1 t2
+		unify_with_variance (with_variance f) t1 t2
 	with Unify_error _ ->
 		raise (Unify_error l)