Skip to content

Clean up Super_error #6199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

- Make "rescript format" work with node 10 again and set minimum required node version to 10 in package.json. https://github.com/rescript-lang/rescript-compiler/pull/6186

#### :nail_care: Polish

- Add location information to duplicate type definition error messages. https://github.com/rescript-lang/rescript-compiler/pull/6199

# 11.0.0-alpha.4

#### :rocket: Main New Feature
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

We've found a bug for you!
/.../fixtures/repeated_def_extension_constr.res:3:6

1 │ type a = ..
2 │
3 │ type a
4 │

Multiple definition of the type name a at line 1, characters 5-6.
Names must be unique in a given structure or signature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

We've found a bug for you!
/.../fixtures/repeated_def_module_types.res:3:13

1 │ module type M = {}
2 │
3 │ module type M = {}
4 │

Multiple definition of the module type name M at line 1, characters 12-13.
Names must be unique in a given structure or signature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

We've found a bug for you!
/.../fixtures/repeated_def_modules.res:3:8

1 │ module M = {}
2 │
3 │ module M = {}
4 │

Multiple definition of the module name M at line 1, characters 7-8.
Names must be unique in a given structure or signature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

We've found a bug for you!
/.../fixtures/repeated_def_types.res:3:6

1 │ type a
2 │
3 │ type a
4 │

Multiple definition of the type name a at line 1, characters 5-6.
Copy link
Collaborator

@cristianoc cristianoc Apr 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should say 1:6 for consistency.

I think this is using ocaml locations, from Location..
Instead it should be using super-errors locations. The super-error location treatment is use to output 3:6 above.
I think the printing here should use that location logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I get it about error handling including super_error.
I'm going to fix this with super_error then will take care of #6202

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this test output has non changed yet?

Names must be unique in a given structure or signature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type a = ..

type a
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module type M = {}

module type M = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module M = {}

module M = {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type a

type a
35 changes: 19 additions & 16 deletions jscomp/ml/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type error =
Longident.t * Path.t * Includemod.error list
| With_changes_module_alias of Longident.t * Ident.t * Path.t
| With_cannot_remove_constrained_type
| Repeated_name of string * string
| Repeated_name of string * string * Warnings.loc
| Non_generalizable of type_expr
| Non_generalizable_module of module_type
| Interface_not_compiled of string
Expand Down Expand Up @@ -623,25 +623,26 @@ let check_recmod_typedecls env sdecls decls =
module StringSet =
Set.Make(struct type t = string let compare (x:t) y = String.compare x y end)

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

type names =
{
types: StringSet.t ref;
modules: StringSet.t ref;
modtypes: StringSet.t ref;
typexts: StringSet.t ref;
types: (string, Warnings.loc) Hashtbl.t;
modules: (string, Warnings.loc) Hashtbl.t;
modtypes: (string, Warnings.loc) Hashtbl.t;
typexts: (string, Warnings.loc) Hashtbl.t;
}

let new_names () =
{
types = ref StringSet.empty;
modules = ref StringSet.empty;
modtypes = ref StringSet.empty;
typexts = ref StringSet.empty;
types = (Hashtbl.create 10);
modules = (Hashtbl.create 10);
modtypes = (Hashtbl.create 10);
typexts = (Hashtbl.create 10);
}


Expand Down Expand Up @@ -1853,10 +1854,12 @@ let report_error ppf = function
"@[<v>Destructive substitutions are not supported for constrained @ \
types (other than when replacing a type constructor with @ \
a type constructor with the same arguments).@]"
| Repeated_name(kind, name) ->
| Repeated_name(kind, name, repeated_loc) ->
let (_, start_line, start_char) = Location.get_pos_info repeated_loc.loc_start in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you check that these correspond to the locations printed normally (whether starting from 0 or 1) for other error messages?

let (_, _, end_char) = Location.get_pos_info repeated_loc.loc_end in
fprintf ppf
"@[Multiple definition of the %s name %s.@ \
Names must be unique in a given structure or signature.@]" kind name
"@[Multiple definition of the %s name %s at line %d, characters %d-%d.@ \
Names must be unique in a given structure or signature.@]" kind name start_line start_char end_char
| Non_generalizable typ ->
fprintf ppf
"@[The type of this expression,@ %a,@ \
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/typemod.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type error =
Longident.t * Path.t * Includemod.error list
| With_changes_module_alias of Longident.t * Ident.t * Path.t
| With_cannot_remove_constrained_type
| Repeated_name of string * string
| Repeated_name of string * string * Warnings.loc
| Non_generalizable of type_expr
| Non_generalizable_module of module_type
| Interface_not_compiled of string
Expand Down