Переглянути джерело

Fix checking type parameters of to/from types in abstracts (#8385)

* fix checking to/from  type parameters

* more tests
Aleksandr Kuzmenko 6 роки тому
батько
коміт
65a70b11e2

+ 1 - 2
src/typing/typeloadModule.ml

@@ -749,8 +749,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 				if !is_type then begin
 					let r = exc_protect ctx (fun r ->
 						r := lazy_processing (fun() -> t);
-						let at = monomorphs a.a_params a.a_this in
-						(try (if from then Type.unify t at else Type.unify at t) with Unify_error _ -> error "You can only declare from/to with compatible types" p);
+						(try (if from then Type.unify t a.a_this else Type.unify a.a_this t) with Unify_error _ -> error "You can only declare from/to with compatible types" p);
 						t
 					) "constraint" in
 					TLazy r

+ 10 - 0
tests/misc/projects/Issue8354/FailFrom.hx

@@ -0,0 +1,10 @@
+class FailFrom {
+	static function main() {}
+}
+
+class MyMap<K, V> {
+	var values: Array<V>;
+	public function iterator(): Iterator<V> return values.iterator();
+}
+
+abstract AbstractMap<K,V>(MyMap<K,V>) from MyMap<V,K> {}

+ 10 - 0
tests/misc/projects/Issue8354/FailTo.hx

@@ -0,0 +1,10 @@
+class FailTo {
+	static function main() {}
+}
+
+class MyMap<K, V> {
+	var values: Array<V>;
+	public function iterator(): Iterator<V> return values.iterator();
+}
+
+abstract AbstractMap<K,V>(MyMap<K,V>) to Iterable<K> {}

+ 10 - 0
tests/misc/projects/Issue8354/Success.hx

@@ -0,0 +1,10 @@
+class Success {
+	static function main() {}
+}
+
+class MyMap<K, V> {
+	var values: Array<V>;
+	public function iterator(): Iterator<V> return values.iterator();
+}
+
+abstract AbstractMap<K,V>(MyMap<K,V>) from MyMap<K,V> to Iterable<V> {}

+ 1 - 0
tests/misc/projects/Issue8354/compile.hxml

@@ -0,0 +1 @@
+-main Success

+ 1 - 0
tests/misc/projects/Issue8354/compile1-fail.hxml

@@ -0,0 +1 @@
+-main FailTo

+ 1 - 0
tests/misc/projects/Issue8354/compile1-fail.hxml.stderr

@@ -0,0 +1 @@
+FailTo.hx:10: characters 1-56 : You can only declare from/to with compatible types

+ 1 - 0
tests/misc/projects/Issue8354/compile2-fail.hxml

@@ -0,0 +1 @@
+-main FailFrom

+ 1 - 0
tests/misc/projects/Issue8354/compile2-fail.hxml.stderr

@@ -0,0 +1 @@
+FailFrom.hx:10: characters 1-57 : You can only declare from/to with compatible types