소스 검색

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()