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