Jelajahi Sumber

[typer] make ambiguous overload errors nicer

Simon Krajewski 5 tahun lalu
induk
melakukan
d3d4334c42
2 mengubah file dengan 17 tambahan dan 1 penghapusan
  1. 10 0
      src/context/typecore.ml
  2. 7 1
      src/typing/calls.ml

+ 10 - 0
src/context/typecore.ml

@@ -549,6 +549,16 @@ let make_field_call_candidate args t cf data = {
 	fc_data = data;
 }
 
+let s_field_call_candidate fcc =
+	let pctx = print_context() in
+	let se = s_expr_pretty false "" false (s_type pctx) in
+	let sl_args = List.map (fun (e,_) -> se e) fcc.fc_args in
+	Printer.s_record_fields "" [
+		"fc_args",String.concat ", " sl_args;
+		"fc_type",s_type pctx fcc.fc_type;
+		"fc_field",Printf.sprintf "%s: %s" fcc.fc_field.cf_name (s_type pctx fcc.fc_field.cf_type)
+	]
+
 (* -------------- debug functions to activate when debugging typer passes ------------------------------- *)
 (*/*
 

+ 7 - 1
src/typing/calls.ml

@@ -378,7 +378,13 @@ let unify_field_call ctx fa el_typed el p inline =
 			| [fcc] ->
 				maybe_check_access fcc.fc_field;
 				fcc
-			| _ -> error "Ambiguous overload" p
+			| fcc :: l ->
+				display_error ctx "Ambiguous overload, candidates follow" p;
+				let st = s_type (print_context()) in
+				List.iter (fun fcc ->
+					display_error ctx (Printf.sprintf "... %s" (st fcc.fc_type)) fcc.fc_field.cf_name_pos;
+				) (fcc :: l);
+				fcc
 		end else begin match List.rev candidates with
 			| [] -> fail()
 			| fcc :: _ -> fcc