Browse Source

[typer] invert order of abstract from/to

see #3494
closes #7656
see #9694
Simon Krajewski 5 years ago
parent
commit
11836c8854

+ 2 - 0
src/typing/typeloadModule.ml

@@ -891,6 +891,8 @@ let init_module_type ctx context_init (decl,p) =
 				(match a.a_impl with Some c -> c.cl_extern <- true | None -> (* Hmmmm.... *) ())
 				(match a.a_impl with Some c -> c.cl_extern <- true | None -> (* Hmmmm.... *) ())
 			| AbPrivate -> ()
 			| AbPrivate -> ()
 		) d.d_flags;
 		) d.d_flags;
+		a.a_from <- List.rev a.a_from;
+		a.a_to <- List.rev a.a_to;
 		if not !is_type then begin
 		if not !is_type then begin
 			if Meta.has Meta.CoreType a.a_meta then
 			if Meta.has Meta.CoreType a.a_meta then
 				a.a_this <- TAbstract(a,List.map snd a.a_params)
 				a.a_this <- TAbstract(a,List.map snd a.a_params)

+ 3 - 3
std/js/lib/Promise.hx

@@ -93,16 +93,16 @@ extern class Promise<T> {
 		the specified callback function is executed. This provides a way for code to be run
 		the specified callback function is executed. This provides a way for code to be run
 		whether the promise was fulfilled successfully or rejected once the Promise has been dealt with.
 		whether the promise was fulfilled successfully or rejected once the Promise has been dealt with.
 	**/
 	**/
-	function finally(onFinally:()->Void):Promise<T>;
+	function finally(onFinally:() -> Void):Promise<T>;
 }
 }
 
 
 /**
 /**
 	Handler type for the Promise object.
 	Handler type for the Promise object.
 **/
 **/
 abstract PromiseHandler<T, TOut>(T->Dynamic) // T->Dynamic, so the compiler always knows the type of the argument and can infer it for then/catch callbacks
 abstract PromiseHandler<T, TOut>(T->Dynamic) // T->Dynamic, so the compiler always knows the type of the argument and can infer it for then/catch callbacks
-	from T->TOut // order is important, because Promise<TOut> return must have priority
-	from T->Thenable<TOut> // although the checking order seems to be reversed at the moment, see https://github.com/HaxeFoundation/haxe/issues/7656
 	from T->Promise<TOut> // support Promise explicitly as it doesn't work transitively through Thenable at the moment
 	from T->Promise<TOut> // support Promise explicitly as it doesn't work transitively through Thenable at the moment
+	from T->Thenable<TOut> // although the checking order seems to be reversed at the moment, see https://github.com/HaxeFoundation/haxe/issues/7656
+	from T->TOut // order is important, because Promise<TOut> return must have priority
 {}
 {}
 
 
 /**
 /**

+ 1 - 1
tests/unit/src/unit/issues/Issue3494.hx

@@ -9,7 +9,7 @@ private abstract E3<T1,T2>(Dynamic)
 from T1 from T2
 from T1 from T2
 to T1 to T2
 to T1 to T2
 {
 {
-	@:from inline static public function _from2<T1, T2, _T1:E3<T1,T2>, _T2:E3<T1,T2>>(e:E3<_T1,_T2>):E3<T1,T2> {
+	@:from inline static public function _from2<T1, T2, _T1:E3<T1,T2>, _T2:E3<T1,T2>>(e:E3<_T1,_T2>):E3<T2,T1> {
 		return untyped e;
 		return untyped e;
 	}
 	}
 }
 }

+ 20 - 0
tests/unit/src/unit/issues/Issue7656.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+private class C<T> {
+	public function new() {}
+}
+
+private abstract A<T>(Dynamic)
+	from C<T>
+	from T
+{}
+
+class Issue7656 extends unit.Test {
+
+	function test() {
+		var v = sf(new C<Int>());
+		HelperMacros.typedAs(v, (null : C<Int>));
+	}
+
+	static function sf<T>(v:A<T>):C<T> return null;
+}