Skip to content

Commit 4b8c3ee

Browse files
committed
error message with loc of repeated definition
1 parent 8db4e2f commit 4b8c3ee

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

jscomp/build_tests/super_errors/expected/repeated_def_extension_constr.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
3 │ type a
88
4 │
99

10-
Multiple definition of the type name a.
10+
Multiple definition of the type name a at line 1, characters 5-6.
1111
Names must be unique in a given structure or signature.

jscomp/build_tests/super_errors/expected/repeated_def_module_types.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
3 │ module type M = {}
88
4 │
99

10-
Multiple definition of the module type name M.
10+
Multiple definition of the module type name M at line 1, characters 12-13.
1111
Names must be unique in a given structure or signature.

jscomp/build_tests/super_errors/expected/repeated_def_modules.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
3 │ module M = {}
88
4 │
99

10-
Multiple definition of the module name M.
10+
Multiple definition of the module name M at line 1, characters 7-8.
1111
Names must be unique in a given structure or signature.

jscomp/build_tests/super_errors/expected/repeated_def_types.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
3 │ type a
88
4 │
99

10-
Multiple definition of the type name a.
10+
Multiple definition of the type name a at line 1, characters 5-6.
1111
Names must be unique in a given structure or signature.

jscomp/ml/typemod.ml

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type error =
3333
Longident.t * Path.t * Includemod.error list
3434
| With_changes_module_alias of Longident.t * Ident.t * Path.t
3535
| With_cannot_remove_constrained_type
36-
| Repeated_name of string * string
36+
| Repeated_name of string * string * Warnings.loc
3737
| Non_generalizable of type_expr
3838
| Non_generalizable_module of module_type
3939
| Interface_not_compiled of string
@@ -623,25 +623,26 @@ let check_recmod_typedecls env sdecls decls =
623623
module StringSet =
624624
Set.Make(struct type t = string let compare (x:t) y = String.compare x y end)
625625

626-
let check cl loc set_ref name =
627-
if StringSet.mem name !set_ref
628-
then raise(Error(loc, Env.empty, Repeated_name(cl, name)))
629-
else set_ref := StringSet.add name !set_ref
626+
let check cl loc tbl name =
627+
match Hashtbl.find_opt tbl name with
628+
| Some repeated_loc ->
629+
raise(Error(loc, Env.empty, Repeated_name(cl, name, repeated_loc)))
630+
| None -> Hashtbl.add tbl name loc
630631

631632
type names =
632633
{
633-
types: StringSet.t ref;
634-
modules: StringSet.t ref;
635-
modtypes: StringSet.t ref;
636-
typexts: StringSet.t ref;
634+
types: (string, Warnings.loc) Hashtbl.t;
635+
modules: (string, Warnings.loc) Hashtbl.t;
636+
modtypes: (string, Warnings.loc) Hashtbl.t;
637+
typexts: (string, Warnings.loc) Hashtbl.t;
637638
}
638639

639640
let new_names () =
640641
{
641-
types = ref StringSet.empty;
642-
modules = ref StringSet.empty;
643-
modtypes = ref StringSet.empty;
644-
typexts = ref StringSet.empty;
642+
types = (Hashtbl.create 10);
643+
modules = (Hashtbl.create 10);
644+
modtypes = (Hashtbl.create 10);
645+
typexts = (Hashtbl.create 10);
645646
}
646647

647648

@@ -1853,10 +1854,13 @@ let report_error ppf = function
18531854
"@[<v>Destructive substitutions are not supported for constrained @ \
18541855
types (other than when replacing a type constructor with @ \
18551856
a type constructor with the same arguments).@]"
1856-
| Repeated_name(kind, name) ->
1857+
| Repeated_name(kind, name, repeated_loc) ->
1858+
let start_line = repeated_loc.loc_start.pos_lnum in
1859+
let start_col = repeated_loc.loc_start.pos_cnum - repeated_loc.loc_start.pos_bol in
1860+
let end_col = repeated_loc.loc_end.pos_cnum - repeated_loc.loc_end.pos_bol in
18571861
fprintf ppf
1858-
"@[Multiple definition of the %s name %s.@ \
1859-
Names must be unique in a given structure or signature.@]" kind name
1862+
"@[Multiple definition of the %s name %s at line %d, characters %d-%d.@ \
1863+
Names must be unique in a given structure or signature.@]" kind name start_line start_col end_col
18601864
| Non_generalizable typ ->
18611865
fprintf ppf
18621866
"@[The type of this expression,@ %a,@ \

jscomp/ml/typemod.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type error =
6565
Longident.t * Path.t * Includemod.error list
6666
| With_changes_module_alias of Longident.t * Ident.t * Path.t
6767
| With_cannot_remove_constrained_type
68-
| Repeated_name of string * string
68+
| Repeated_name of string * string * Warnings.loc
6969
| Non_generalizable of type_expr
7070
| Non_generalizable_module of module_type
7171
| Interface_not_compiled of string

0 commit comments

Comments
 (0)