Browse Source

fixed missing error: "multitype type params must be known" (closes #10039)

Aleksandr Kuzmenko 4 năm trước cách đây
mục cha
commit
9d4dea7b45

+ 14 - 5
src/context/abstractCast.ml

@@ -166,8 +166,8 @@ let find_array_access ctx a tl e1 e2o p =
 let find_multitype_specialization com a pl p =
 let find_multitype_specialization com a pl p =
 	let uctx = default_unification_context in
 	let uctx = default_unification_context in
 	let m = mk_mono() in
 	let m = mk_mono() in
-	let tl = match Meta.get Meta.MultiType a.a_meta with
-		| _,[],_ -> pl
+	let tl,definitive_types = match Meta.get Meta.MultiType a.a_meta with
+		| _,[],_ -> pl,pl
 		| _,el,_ ->
 		| _,el,_ ->
 			let relevant = Hashtbl.create 0 in
 			let relevant = Hashtbl.create 0 in
 			List.iter (fun e ->
 			List.iter (fun e ->
@@ -181,9 +181,12 @@ let find_multitype_specialization com a pl p =
 				in
 				in
 				loop (fun t -> t) e
 				loop (fun t -> t) e
 			) el;
 			) el;
+			let definitive_types = ref [] in
 			let tl = List.map2 (fun (n,_) t ->
 			let tl = List.map2 (fun (n,_) t ->
 				try
 				try
-					(Hashtbl.find relevant n) t
+					let t = (Hashtbl.find relevant n) t in
+					definitive_types := t :: !definitive_types;
+					t
 				with Not_found ->
 				with Not_found ->
 					if not (has_mono t) then t
 					if not (has_mono t) then t
 					else t_dynamic
 					else t_dynamic
@@ -209,11 +212,17 @@ let find_multitype_specialization com a pl p =
 					ignore(loop t1)
 					ignore(loop t1)
 				| _ -> die "" __LOC__
 				| _ -> die "" __LOC__
 			end;
 			end;
-			tl
+			tl,!definitive_types
 	in
 	in
 	let _,cf =
 	let _,cf =
 		try
 		try
-			Abstract.find_to uctx m a tl
+			let t = Abstract.find_to uctx m a tl in
+			if List.exists (fun t -> has_mono t) definitive_types then begin
+				let at = apply_params a.a_params pl a.a_this in
+				let st = s_type (print_context()) at in
+				error ("Type parameters of multi type abstracts must be known (for " ^ st ^ ")") p
+			end;
+			t
 		with Not_found ->
 		with Not_found ->
 			let at = apply_params a.a_params pl a.a_this in
 			let at = apply_params a.a_params pl a.a_this in
 			let st = s_type (print_context()) at in
 			let st = s_type (print_context()) at in

+ 4 - 0
tests/misc/projects/Issue10039/Main.hx

@@ -0,0 +1,4 @@
+class Main {
+	public static function main():Void foo([]);
+	static function foo<T>(map:Map<T, Int>):Void for (k => v in map) {};
+}

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

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

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

@@ -0,0 +1 @@
+Main.hx:2: characters 41-43 : Type parameters of multi type abstracts must be known (for haxe.IMap<Unknown<0> : String, Int>)