ソースを参照

[typer] only apply mono restrictions to @:multiType for now

see #10565
Simon Krajewski 3 年 前
コミット
74c13003e8
2 ファイル変更42 行追加1 行削除
  1. 1 1
      src/core/tUnification.ml
  2. 41 0
      tests/unit/src/unit/issues/Issue10565.hx

+ 1 - 1
src/core/tUnification.ml

@@ -1012,7 +1012,7 @@ and unifies_to_field uctx a b ab tl (t,cf) =
 			let unify_func = get_abstract_unify_func uctx EqStrict in
 			let athis = map ab.a_this in
 			(* we cannot allow implicit casts when the this type is not completely known yet *)
-			if has_mono athis then raise (Unify_error []);
+			if Meta.has Meta.MultiType ab.a_meta && has_mono athis then raise (Unify_error []);
 			with_variance uctx (type_eq {uctx with equality_kind = EqStrict}) athis (map ta);
 			unify_func (map t) b;
 		| _ -> die "" __LOC__)

+ 41 - 0
tests/unit/src/unit/issues/Issue10565.hx

@@ -6,9 +6,50 @@ private abstract MapProxy<K, V>(Dynamic) {
 	}
 }
 
+private class Foo {}
+private abstract ReactTypeOf<T:{}>(Foo) to Foo {}
+
+@:forward
+private abstract ReactContext<T>(IReactContext<T>) from IReactContext<T> to IReactContext<T> {
+	public function new() {
+		this = new Context();
+	}
+
+	@:to
+	public function toReactType<T1:{children:T->String}>():ReactTypeOf<T1> {
+		return cast this;
+	}
+}
+
+private interface IReactContext<T> {
+	var Consumer:ReactContext<T>;
+}
+
+private class Context<T> implements IReactContext<T> {
+	public var Consumer = null;
+
+	public function new() {}
+}
+
+private typedef Bar = {
+	children:{foo:String}->String
+}
+
 class Issue10565 extends Test {
 	function test() {
 		var m:MapProxy<String, Int> = new Map();
 		utest.Assert.pass();
 	}
+
+	public static var Consumer:ReactTypeOf<Bar>;
+
+	function testReactMess() {
+		var context = createContext();
+		Consumer = context.Consumer;
+		utest.Assert.pass();
+	}
+
+	public static function createContext<TContext>():ReactContext<TContext> {
+		return new ReactContext();
+	}
 }