Browse Source

check constraints of spawned monomorphs after typing a call (fixes #10198)

Aleksandr Kuzmenko 4 years ago
parent
commit
cb7d3f5f9e

+ 13 - 0
src/typing/callUnification.ml

@@ -300,6 +300,19 @@ let unify_field_call ctx fa el_typed el p inline =
 				let ef = mk (TField(fa.fa_on,FieldAccess.apply_fa cf fa.fa_host)) t fa.fa_pos in
 				let ef = mk (TField(fa.fa_on,FieldAccess.apply_fa cf fa.fa_host)) t fa.fa_pos in
 				!make_call_ref ctx ef el ret ~force_inline:inline p
 				!make_call_ref ctx ef el ret ~force_inline:inline p
 			in
 			in
+			delay ctx PCheckConstraint (fun() ->
+				List.iter (fun t ->
+					match t with
+					| TMono m ->
+						let kind = Monomorph.classify_constraints m in
+						(try
+							Monomorph.check_constraints kind t
+						with Unify_error el ->
+							List.iter (fun e -> display_error ctx (unify_error_msg (print_context()) e) p) el
+						)
+					| _ -> ()
+				) monos
+			);
 			make_field_call_candidate el ret monos tf cf (mk_call,extract_delayed_display())
 			make_field_call_candidate el ret monos tf cf (mk_call,extract_delayed_display())
 		| t ->
 		| t ->
 			error (s_type (print_context()) t ^ " cannot be called") p
 			error (s_type (print_context()) t ^ " cannot be called") p

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

@@ -0,0 +1,7 @@
+class Main {
+	static function main()
+		var b:Int = fn(fn('s'));
+
+	static public function fn<T, R:T>(v:R):T
+		return null;
+}

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

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

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

@@ -0,0 +1,2 @@
+Main.hx:3: characters 18-25 : Constraint check failure for fn.R
+Main.hx:3: characters 18-25 : Int should be String