ソースを参照

flip Constructible unification direction (closes #6290)

Simon Krajewski 8 年 前
コミット
dea65b6944
2 ファイル変更35 行追加1 行削除
  1. 1 1
      src/typing/type.ml
  2. 34 0
      tests/unit/src/unit/issues/Issue6290.hx

+ 1 - 1
src/typing/type.ml

@@ -1977,7 +1977,7 @@ let rec unify a b =
 				| _ ->
 					let _,t,cf = class_field c tl "new" in
 					if not cf.cf_public then error [invalid_visibility "new"];
-					begin try unify t1 t
+					begin try unify t t1
 					with Unify_error l -> error (cannot_unify a b :: l) end
 			end
 		with Not_found ->

+ 34 - 0
tests/unit/src/unit/issues/Issue6290.hx

@@ -0,0 +1,34 @@
+package unit.issues;
+
+private class Parent {
+	public function new() {}
+}
+
+private class Child extends Parent {}
+
+private class TakeParent {
+	public function new(parent:Parent) {}
+}
+
+private class TakeChild extends TakeParent {
+	public function new(child:Child) {
+		if (!Std.is(child, Child)) throw 'wtf?';
+		super(child);
+	}
+}
+
+class Issue6290 extends unit.Test {
+	@:generic static function get<Arg, Cls:haxe.Constraints.Constructible<Arg->Void>>(a:Arg, c:Class<Cls>) {
+		return new Cls(a);
+	}
+
+	function test() {
+		var parent = new Parent(),
+		    child = new Child();
+
+		get(parent, TakeParent);
+		get(child, TakeChild);
+		t(unit.HelperMacros.typeError(get(parent, TakeChild)));
+		get(child, TakeParent);
+	}
+}