Browse Source

propagate constraints when binding mono to mono (fixes #10198)

Aleksandr Kuzmenko 4 years ago
parent
commit
46f7d872c9

+ 3 - 0
src/core/tUnification.ml

@@ -165,6 +165,9 @@ module Monomorph = struct
 			if m != m2 then begin match m2.tm_type with
 			| None ->
 				List.iter (fun constr -> m2.tm_constraints <- constr :: m2.tm_constraints) m.tm_constraints;
+				(* If the monomorph we're binding to has other yet unbound monomorphs, constrain them to our target type (issue #9640) .*)
+				let mono_constraints,_ = classify_constraints' m in
+				List.iter (fun m3 -> constrain_to_type m3 None t) mono_constraints;
 				do_bind m t;
 			| Some t ->
 				bind m t

+ 11 - 0
tests/misc/projects/Issue10198/Main.hx

@@ -0,0 +1,11 @@
+class Main {
+	static public function fn1<T1,R1:T1>(v:R1):T1
+		return null;
+
+	static public function fn2<T2,R2:T2>(v:R2):T2
+		return null;
+
+	static function main() {
+		var b:Int = fn1(fn2('s'));
+	}
+}

+ 1 - 0
tests/misc/projects/Issue10198/compile-fail.hxml

@@ -0,0 +1 @@
+--main Main

+ 1 - 0
tests/misc/projects/Issue10198/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:9: characters 3-29 : Int should be String