Browse Source

[abstracts] fix some inconsistency in variance unification (#9743)

Dmitrii Maganov 5 years ago
parent
commit
f66c43f453
2 changed files with 11 additions and 5 deletions
  1. 5 5
      src/core/tUnification.ml
  2. 6 0
      tests/unit/src/unit/issues/Issue9721.hx

+ 5 - 5
src/core/tUnification.ml

@@ -967,8 +967,8 @@ and unify_with_variance uctx f t1 t2 =
 			| t -> get_underlying_type t)
 			| t -> get_underlying_type t)
 		| t -> t
 		| t -> t
 	in
 	in
-	let compare_underlying equality_kind =
-		type_eq {uctx with equality_kind = equality_kind} (get_underlying_type t1) (get_underlying_type t2)
+	let compare_underlying () =
+		type_eq {uctx with equality_kind = EqBothDynamic} (get_underlying_type t1) (get_underlying_type t2)
 	in
 	in
 	let unifies_abstract uctx a b ab tl ats =
 	let unifies_abstract uctx a b ab tl ats =
 		try
 		try
@@ -995,13 +995,13 @@ and unify_with_variance uctx f t1 t2 =
 	| TAbstract(a1,tl1),TAbstract(a2,tl2) ->
 	| TAbstract(a1,tl1),TAbstract(a2,tl2) ->
 		if not (unifies_abstract uctx t1 t2 a1 tl1 a1.a_to)
 		if not (unifies_abstract uctx t1 t2 a1 tl1 a1.a_to)
 		&& not (unifies_abstract uctx t1 t2 a2 tl2 a2.a_from) then fail();
 		&& not (unifies_abstract uctx t1 t2 a2 tl2 a2.a_from) then fail();
-		compare_underlying EqStrict;
+		compare_underlying();
 	| TAbstract(ab,tl),_ ->
 	| TAbstract(ab,tl),_ ->
 		if not (unifies_abstract uctx t1 t2 ab tl ab.a_to) then fail();
 		if not (unifies_abstract uctx t1 t2 ab tl ab.a_to) then fail();
-		compare_underlying EqBothDynamic;
+		compare_underlying();
 	| _,TAbstract(ab,tl) ->
 	| _,TAbstract(ab,tl) ->
 		if not (unifies_abstract uctx t1 t2 ab tl ab.a_from) then fail();
 		if not (unifies_abstract uctx t1 t2 ab tl ab.a_from) then fail();
-		compare_underlying EqBothDynamic;
+		compare_underlying();
 	| TAnon(a1),TAnon(a2) ->
 	| TAnon(a1),TAnon(a2) ->
 		rec_stack_default unify_stack (t1,t2) (fast_eq_pair (t1,t2)) (fun() -> unify_anons uctx t1 t2 a1 a2) ()
 		rec_stack_default unify_stack (t1,t2) (fast_eq_pair (t1,t2)) (fun() -> unify_anons uctx t1 t2 a1 a2) ()
 	| TFun(al1,r1),TFun(al2,r2) when List.length al1 = List.length al2 ->
 	| TFun(al1,r1),TFun(al2,r2) when List.length al1 = List.length al2 ->

+ 6 - 0
tests/unit/src/unit/issues/Issue9721.hx

@@ -1,4 +1,5 @@
 package unit.issues;
 package unit.issues;
+import haxe.extern.EitherType;
 
 
 class Issue9721 extends Test {
 class Issue9721 extends Test {
 	function test() {
 	function test() {
@@ -36,6 +37,11 @@ class Issue9721 extends Test {
 
 
     ((null: {x: Int -> Void}): {x: Foo<Int> -> Void});
     ((null: {x: Int -> Void}): {x: Foo<Int> -> Void});
     t(unit.HelperMacros.typeError(((null: {x: Int -> Void}): {x: Foo<Float> -> Void})));
     t(unit.HelperMacros.typeError(((null: {x: Int -> Void}): {x: Foo<Float> -> Void})));
+
+    ((null: {x: EitherType<Int,String>}): {x: String});
+    ((null: {x: EitherType<Int,String>}): {x: Int});
+    ((null: {x: String}): {x: EitherType<Int,String>});
+    ((null: {x: Int}): {x: EitherType<Int,String>});
   }
   }
 }
 }