From dc97a826504f4db2197037d19c12a12edd665a9c Mon Sep 17 00:00:00 2001 From: RblSb Date: Wed, 18 Oct 2023 22:22:04 +0300 Subject: [PATCH] Improve extra field error range (#11335) * Improve extra field error range * update range * fail --- src/typing/typer.ml | 9 +++++++-- tests/misc/projects/Issue11334/Main.hx | 19 +++++++++++++++++++ .../projects/Issue11334/compile-fail.hxml | 1 + .../Issue11334/compile-fail.hxml.stderr | 2 ++ .../Issue3192/compile1-fail.hxml.stderr | 2 +- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/misc/projects/Issue11334/Main.hx create mode 100644 tests/misc/projects/Issue11334/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11334/compile-fail.hxml.stderr diff --git a/src/typing/typer.ml b/src/typing/typer.ml index 0a71bbb9b20..6250fd4e216 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -811,7 +811,7 @@ and type_object_decl ctx fl with_type p = (try type_eq EqStrict e.etype t; e with Unify_error _ -> mk (TCast (e,None)) t e.epos) with Not_found -> if is_valid then - extra_fields := n :: !extra_fields; + extra_fields := (n,pn) :: !extra_fields; type_expr ctx e WithType.value in if is_valid then begin @@ -830,7 +830,12 @@ and type_object_decl ctx fl with_type p = | depth -> raise_or_display ctx [Unify_custom ("Object requires fields: " ^ (String.concat ", " depth))] p); (match !extra_fields with | [] -> () - | _ -> raise_or_display ctx (List.map (fun n -> has_extra_field t n) !extra_fields) p); + | _ -> + List.iter (fun (n,pn) -> + let err = has_extra_field t n in + raise_or_display ctx [err] pn + ) !extra_fields + ); end; t, fl in diff --git a/tests/misc/projects/Issue11334/Main.hx b/tests/misc/projects/Issue11334/Main.hx new file mode 100644 index 00000000000..f7aeba8d81d --- /dev/null +++ b/tests/misc/projects/Issue11334/Main.hx @@ -0,0 +1,19 @@ +class Main { + static function main() { + final foo:Foo = { + a: () -> { + trace(123); + }, + b: () -> { + trace(123); + }, + c: 123, + d: 123, + } + } +} + +typedef Foo = { + a:() -> Void, + c:Int, +} diff --git a/tests/misc/projects/Issue11334/compile-fail.hxml b/tests/misc/projects/Issue11334/compile-fail.hxml new file mode 100644 index 00000000000..fab0aeecc3d --- /dev/null +++ b/tests/misc/projects/Issue11334/compile-fail.hxml @@ -0,0 +1 @@ +--main Main \ No newline at end of file diff --git a/tests/misc/projects/Issue11334/compile-fail.hxml.stderr b/tests/misc/projects/Issue11334/compile-fail.hxml.stderr new file mode 100644 index 00000000000..fabbffbf963 --- /dev/null +++ b/tests/misc/projects/Issue11334/compile-fail.hxml.stderr @@ -0,0 +1,2 @@ +Main.hx:11: characters 4-5 : { d : Int, c : Int, b : () -> Void, a : () -> Void } has extra field d +Main.hx:7: characters 4-5 : { d : Int, c : Int, b : () -> Void, a : () -> Void } has extra field b diff --git a/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr b/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr index 722e2d25f74..d6978e36903 100644 --- a/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr +++ b/tests/misc/projects/Issue3192/compile1-fail.hxml.stderr @@ -1 +1 @@ -Main1.hx:3: characters 19-33 : { b : Int, a : Int } has extra field b \ No newline at end of file +Main1.hx:3: characters 27-28 : { b : Int, a : Int } has extra field b