Skip to content

Commit

Permalink
Improve extra field error range (HaxeFoundation#11335)
Browse files Browse the repository at this point in the history
* Improve extra field error range

* update range

* fail
  • Loading branch information
RblSb authored and 0b1kn00b committed Jan 25, 2024
1 parent befba6c commit dc97a82
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/misc/projects/Issue11334/Main.hx
Original file line number Diff line number Diff line change
@@ -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,
}
1 change: 1 addition & 0 deletions tests/misc/projects/Issue11334/compile-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--main Main
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue11334/compile-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue3192/compile1-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Main1.hx:3: characters 19-33 : { b : Int, a : Int } has extra field b
Main1.hx:3: characters 27-28 : { b : Int, a : Int } has extra field b

0 comments on commit dc97a82

Please sign in to comment.