浏览代码

detect when all overload attempts give the exact same error message

In this case there's something wrong with one of the arguments to begin with. Let's give the error as-is because it has nothing to do with overloads.
Simon Krajewski 9 年之前
父节点
当前提交
1cdd38cf97
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 12 6
      typer.ml

+ 12 - 6
typer.ml

@@ -821,12 +821,18 @@ let unify_field_call ctx fa el args ret p inline =
 	| _ ->
 		let candidates,failures = loop candidates in
 		let fail () =
-			display_error ctx "Could not find a suitable overload, reasons follow" p;
-			List.iter (fun (cf,err,p2) ->
-				display_error ctx ("Overload resolution failed for " ^ (s_type (print_context()) cf.cf_type)) p;
-				display_error ctx (error_msg err) p2;
-			) failures;
-			error "End of overload fail reasons" p
+			let failures = List.map (fun (cf,err,p) -> cf,error_msg err,p) failures in
+			begin match failures with
+			| (_,msg,p) :: failures when List.for_all (fun (_,msg2,_) -> msg = msg2) failures ->
+				error msg p
+			| _ ->
+				display_error ctx "Could not find a suitable overload, reasons follow" p;
+				List.iter (fun (cf,msg,p2) ->
+					display_error ctx ("Overload resolution failed for " ^ (s_type (print_context()) cf.cf_type)) p;
+					display_error ctx msg p2;
+				) failures;
+				error "End of overload fail reasons" p
+			end
 		in
 		if is_overload && ctx.com.config.pf_overload then begin match Codegen.Overloads.reduce_compatible candidates with
 			| [] -> fail()