Browse Source

[typer] delay unknown ident errors in overloads

closes #11372
Simon Krajewski 1 year ago
parent
commit
7fdac0a238

+ 23 - 13
src/typing/callUnification.ml

@@ -307,10 +307,16 @@ let unify_field_call ctx fa el_typed el p inline =
 		| t ->
 			raise_typing_error (s_type (print_context()) t ^ " cannot be called") p
 	in
-	let maybe_raise_unknown_ident err =
+	let unknown_ident_error = ref None in
+	let remember_unknown_ident_error =
+		fun err -> match !unknown_ident_error with
+			| None -> unknown_ident_error := Some err
+			| Some _ -> ()
+	in
+	let check_unknown_ident err =
 		let rec loop err =
 			match err.err_message with
-			| Call_error (Could_not_unify Unknown_ident _) | Unknown_ident _ -> raise_typing_error_ext err
+			| Call_error (Could_not_unify Unknown_ident _) | Unknown_ident _ -> remember_unknown_ident_error err
 			| _ -> List.iter loop err.err_sub
 		in
 		loop err
@@ -337,7 +343,7 @@ let unify_field_call ctx fa el_typed el p inline =
 						if constr != m.tm_down_constraints then m.tm_down_constraints <- constr;
 					) known_monos;
 					ctx.monomorphs.perfunction <- current_monos;
-					maybe_raise_unknown_ident err;
+					check_unknown_ident err;
 					let candidates,failures = loop candidates in
 					candidates,(cf,err,extract_delayed_display()) :: failures
 				end
@@ -384,17 +390,21 @@ let unify_field_call ctx fa el_typed el p inline =
 			| [_,err] ->
 				raise_typing_error_ext err
 			| _ ->
-				let sub = List.fold_left (fun acc (cf,err) ->
-					(make_error
-						~depth:1 (* pretty much optional here *)
-						~sub:[err]
-						(Custom ("Overload resolution failed for " ^ (s_type (print_context()) cf.cf_type)))
-						p
-					) :: acc
-				) [] failures in
+				match !unknown_ident_error with
+				| None ->
+					let sub = List.fold_left (fun acc (cf,err) ->
+						(make_error
+							~depth:1 (* pretty much optional here *)
+							~sub:[err]
+							(Custom ("Overload resolution failed for " ^ (s_type (print_context()) cf.cf_type)))
+							p
+						) :: acc
+					) [] failures in
 
-				display_error_ext ctx.com (make_error ~sub (Custom "Could not find a suitable overload, reasons follow") p);
-				raise_typing_error_ext (make_error ~depth:1 (Custom "End of overload failure reasons") p)
+					display_error_ext ctx.com (make_error ~sub (Custom "Could not find a suitable overload, reasons follow") p);
+					raise_typing_error_ext (make_error ~depth:1 (Custom "End of overload failure reasons") p)
+				| Some err ->
+					raise_typing_error_ext err
 			end
 		in
 		if overload_kind = OverloadProper then begin match Overloads.Resolution.reduce_compatible candidates with

+ 7 - 0
tests/misc/projects/Issue11372/Macro.hx

@@ -0,0 +1,7 @@
+@RuntimeMeta([42,0])
+class Macro {
+	public static function init() {
+		var m = haxe.rtti.Meta.getType(Macro);
+		if (m.RuntimeMeta[0][0] != 42) throw "runtime meta failure";
+	}
+}

+ 3 - 0
tests/misc/projects/Issue11372/MainBad.hx

@@ -0,0 +1,3 @@
+function main() {
+	ValuePrinter.printValue(ON);
+}

+ 3 - 0
tests/misc/projects/Issue11372/MainGood.hx

@@ -0,0 +1,3 @@
+function main() {
+	ValuePrinter.printValue(ONE);
+}

+ 11 - 0
tests/misc/projects/Issue11372/MyEnumAbstract.hx

@@ -0,0 +1,11 @@
+enum abstract MyEnumAbstract(Int) {
+	var ONE = 1;
+
+	@:to
+	private function toValue():String {
+		return switch (abstract) {
+			case ONE:
+				"One";
+		}
+	}
+}

+ 16 - 0
tests/misc/projects/Issue11372/ValuePrinter.hx

@@ -0,0 +1,16 @@
+overload extern inline function printValue(input:MyEnumAbstract) {
+	var value:String = input;
+	printValue(value);
+}
+
+overload extern inline function printValue(input:Int) {
+	// Do something.
+}
+
+overload extern inline function printValue(input:String) {
+	// Do something.
+}
+
+overload extern inline function printValue(input:Bool) {
+	// Do something.
+}

+ 2 - 0
tests/misc/projects/Issue11372/compile-bad-fail.hxml

@@ -0,0 +1,2 @@
+--main MainBad
+--interp

+ 2 - 0
tests/misc/projects/Issue11372/compile-bad-fail.hxml.stderr

@@ -0,0 +1,2 @@
+MainBad.hx:2: characters 26-28 : Unknown identifier : ON
+MainBad.hx:2: characters 26-28 : ... For function argument 'input'

+ 2 - 0
tests/misc/projects/Issue11372/compile-good.hxml

@@ -0,0 +1,2 @@
+--main MainGood
+--interp