Browse Source

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 years ago
parent
commit
1cdd38cf97
1 changed files with 12 additions and 6 deletions
  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 candidates,failures = loop candidates in
 		let fail () =
 		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
 		in
 		if is_overload && ctx.com.config.pf_overload then begin match Codegen.Overloads.reduce_compatible candidates with
 		if is_overload && ctx.com.config.pf_overload then begin match Codegen.Overloads.reduce_compatible candidates with
 			| [] -> fail()
 			| [] -> fail()