Skip to content
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

Clean up Super_error #6199

Merged
merged 11 commits into from
Apr 27, 2023
Merged

Clean up Super_error #6199

merged 11 commits into from
Apr 27, 2023

Conversation

mununki
Copy link
Member

@mununki mununki commented Apr 25, 2023

Fix #6202
Fix #5695

This PR enhances the error message for duplicate type definitions in ReScript by including the location of the previously declared definition. This improvement aims to provide better context for developers, making it easier to identify and resolve type conflicts in their code.

This PR incorporates the Super_error module into the regular modules and cleans up the Super_error module. It also includes adding location information of the already defined declaration in the error message for duplicated type definitions.

In this change, replace the SetString ref data structure with (string, Warnings.loc) Hashtbl.t for better handling of location information.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

Just one final thing to check, then ready to go.

| Repeated_name(kind, name, repeated_loc) ->
let start_line = repeated_loc.loc_start.pos_lnum in
let start_col = repeated_loc.loc_start.pos_cnum - repeated_loc.loc_start.pos_bol in
let end_col = repeated_loc.loc_end.pos_cnum - repeated_loc.loc_end.pos_bol in
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there some logic already to do this? The ocaml and vscode loc info's are different (zero-based vs one-based) so it's a bit tricky and best to keep all in the same place.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Look for the part that says: "we've found a bug for you".

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have added wider task: #6202
This PR fits well in that.

let start_line = repeated_loc.loc_start.pos_lnum in
let start_col = repeated_loc.loc_start.pos_cnum - repeated_loc.loc_start.pos_bol in
let end_col = repeated_loc.loc_end.pos_cnum - repeated_loc.loc_end.pos_bol in
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?

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

The locations are not quite right I think.

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?

@mununki mununki changed the title Include Location Information for Duplicate Type Definition Errors Clean up Super_error Apr 27, 2023
jscomp/ounit_tests/ounit_cmd_tests.ml Outdated Show resolved Hide resolved
ppf
(fun ppf () ->
fprintf ppf
"@[This expression's type contains type variables that can't be generalized:@,@{<error>%a@}@]"
Copy link
Member Author

Choose a reason for hiding this comment

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

The ounit test seemed to need to pass "can't be generalized," but the test case was written as "cannot be generalized." So, when it was moved to typemod.ml as is, it failed the test, and that's why it was moved to typemod.ml as "cannot be generalized."

When testing "This expression's type contains," it passes, so I think there is no problem.

@mununki
Copy link
Member Author

mununki commented Apr 27, 2023

Two of the ounit tests did not pass, and there seems to be a problem with the existing tests or I did not understand them well. So, I rewrote the tests, and I would like to request a review. @cristianoc

@cristianoc
Copy link
Collaborator

If the output of the tests changed slightly, you can update the expected result of tests. See jscomp/build_tests/super_errors/README.md.

Is this correct, that there was just a small difference in what has been printed? If so, it seems better to just update the expected result instead of changing the tests.

If I misunderstood: what tests were not working and why?

@mununki
Copy link
Member Author

mununki commented Apr 27, 2023

If the output of the tests changed slightly, you can update the expected result of tests. See jscomp/build_tests/super_errors/README.md.

Is this correct, that there was just a small difference in what has been printed? If so, it seems better to just update the expected result instead of changing the tests.

If I misunderstood: what tests were not working and why?

Two Ounit_cmd_tests tests cannot pass:

  1. "has type string" -> typecore.ml
    I couldn't figure out why "has type string" test was okay so far, the error message should be "has type: string". Another thing I couldn't figure out is that "has type: string" also fails to pass now.
  2. "cannot be generalized" -> typemod.ml
    Super_typemod would give us "can't be generalized" for Typemod.Non_generalizable error. But the test was written by "cannot be generalized". No clue why test result was okay so far.

@cristianoc
Copy link
Collaborator

If the output of the tests changed slightly, you can update the expected result of tests. See jscomp/build_tests/super_errors/README.md.
Is this correct, that there was just a small difference in what has been printed? If so, it seems better to just update the expected result instead of changing the tests.
If I misunderstood: what tests were not working and why?

Two Ounit_cmd_tests tests cannot pass:

  1. "has type string" -> typecore.ml
    I couldn't figure out why "has type string" test was okay so far, the error message should be "has type: string". Another thing I couldn't figure out is that "has type: string" also fails to pass now.
  2. "cannot be generalized" -> typemod.ml
    Super_typemod would give us "can't be generalized" for Typemod.Non_generalizable error. But the test was written by "cannot be generalized". No clue why test result was okay so far.

OK to move these to super-error tests? So we can check that they're working.

@mununki
Copy link
Member Author

mununki commented Apr 27, 2023

Cleaning up the Super_error doesn't make changes of test result in fixtures /jscomp/build_tests/super_errors by node ./jscomp/build_tests/super_errors/input.js update.
Ounit_cmd_tests are the problem we have now.

@cristianoc
Copy link
Collaborator

Cleaning up the Super_error doesn't make changes of test result in fixtures /jscomp/build_tests/super_errors by node ./jscomp/build_tests/super_errors/input.js update.

Ounit_cmd_tests are the problem we have now.

Yes thanks I have understood now. That's why I'm asking to move those tests out of ounit.

@mununki
Copy link
Member Author

mununki commented Apr 27, 2023

Yes thanks I have understood now. That's why I'm asking to move those tests out of ounit.

Got it, done 10ac8c0

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

This looks great.
Left a tiny comment.
Anything else to do? Looks like this can be merged.

jscomp/ml/lexer.mll Show resolved Hide resolved
jscomp/ounit_tests/ounit_cmd_tests.ml Outdated Show resolved Hide resolved
@@ -276,14 +276,14 @@ let rec y = A y;;
OUnit.assert_bool __LOC__
(Ext_string.contain_substring should_err.stderr "contravariant")
end;
__LOC__ >:: begin fun _ ->
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 delete instead of commenting out?

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -294,10 +292,6 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =

(******************************************************************************)


"-bs-super-errors", unit_lazy Super_main.setup,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps mention this as breaking change in the changelog.
I don't think there's any use for calling bsc directly, but just to be on the safe side.

Isn't there also something in bsconfig? Perhaps one could deprecate or remove that too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can add it to the changelog as a breaking change, but how do I deprecate it when I've already removed the super_error? There is a way to make it deprecated?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is low risk. Remove is OK. No need to deprecate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@mununki
Copy link
Member Author

mununki commented Apr 27, 2023

I have nothing left for this PR now.

@cristianoc cristianoc merged commit 63fd342 into master Apr 27, 2023
@cristianoc cristianoc deleted the error-msg-multiple-def branch April 27, 2023 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spring cleaning: super errors Multiple locations of duplicated definition for better user experience
2 participants