Browse Source

use abstract itself instead of underlying type to check variance (closes #3110)

Simon Krajewski 11 years ago
parent
commit
11d90f0227
3 changed files with 18 additions and 5 deletions
  1. 1 1
      tests/unit/MyAbstract.hx
  2. 12 0
      tests/unit/issues/Issue3110.hx
  3. 5 4
      type.ml

+ 1 - 1
tests/unit/MyAbstract.hx

@@ -181,7 +181,7 @@ abstract MyInt(Int) from Int to Int {
 	}
 	}
 }
 }
 
 
-abstract MyInt2(Int){
+abstract MyInt2(Int) from MyInt {
 	public inline function new(v) {
 	public inline function new(v) {
 		this = v;
 		this = v;
 	}
 	}

+ 12 - 0
tests/unit/issues/Issue3110.hx

@@ -0,0 +1,12 @@
+package unit.issues;
+
+private abstract MyOpaciteInt(Int) {}
+
+class Issue3110 extends Test {
+	function test() {
+		var o:List<MyOpaciteInt> = null;
+		t(unit.TestType.typeError({
+			var u:List<UInt> = o;
+		}));
+	}
+}

+ 5 - 4
type.ml

@@ -1548,11 +1548,12 @@ and unify_with_variance f t1 t2 =
 	| TAbstract(a1,tl1),TAbstract(a2,tl2) when a1 == a2 && Meta.has Meta.CoreType a1.a_meta ->
 	| TAbstract(a1,tl1),TAbstract(a2,tl2) when a1 == a2 && Meta.has Meta.CoreType a1.a_meta ->
 		List.iter2 f tl1 tl2
 		List.iter2 f tl1 tl2
 	| TAbstract(a1,pl1),TAbstract(a2,pl2) ->
 	| 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
-		if (Meta.has Meta.CoreType a1.a_meta) && (Meta.has Meta.CoreType a2.a_meta) then
+		if (Meta.has Meta.CoreType a1.a_meta) && (Meta.has Meta.CoreType a2.a_meta) then begin
+			let ta1 = apply_params a1.a_types pl1 a1.a_this in
+			let ta2 = apply_params a2.a_types pl2 a2.a_this in
 			type_eq EqStrict ta1 ta2;
 			type_eq EqStrict ta1 ta2;
-		if not (List.exists (allows_variance_to ta2) a1.a_to) && not (List.exists (allows_variance_to ta1) a2.a_from) then
+		end;
+		if not (List.exists (allows_variance_to t2) a1.a_to) && not (List.exists (allows_variance_to t1) a2.a_from) then
 			error [cannot_unify t1 t2]
 			error [cannot_unify t1 t2]
 	| TAbstract(a,pl),t ->
 	| TAbstract(a,pl),t ->
 		type_eq EqStrict (apply_params a.a_types pl a.a_this) t;
 		type_eq EqStrict (apply_params a.a_types pl a.a_this) t;