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

Fix issue 503 #504

Merged
merged 9 commits into from
Jul 1, 2024
Merged

Fix issue 503 #504

merged 9 commits into from
Jul 1, 2024

Conversation

jchavarri
Copy link
Contributor

@jchavarri jchavarri commented Jun 30, 2024

Fixes #503.

In the first commit, notice the difference in the ending location of the Pexp_fun with the labelled bar.

In 5.1:

((pos_fname file.ml) (pos_lnum 1) (pos_bol 0) (pos_cnum 30)))

In 5.2:

((pos_fname file.ml) (pos_lnum 1) (pos_bol 0) (pos_cnum 18)))

The second commit updates Migrate_502_501 so that the ranges of locations of Pexp_fun stay consistent with the behavior in 5.1.

Signed-off-by: Javier Chavarri <[email protected]>
@jchavarri jchavarri changed the title Add reproduction test for issue 503 Fix issue 503 Jun 30, 2024
Signed-off-by: Javier Chavarri <[email protected]>
Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to report and fix this bug!

If I understand it correctly you should apply the same change to the Pexp_newtype node below as well!

The tests for the 501<->502 migrations are pretty unreadable in their current state unfortunately and I'd rather avoid adding more of those. I suggest you instead take an approach closer to how we test the ocaml.ppx.context migration (see the driver.ml, dune and run.t files). The idea is that you'd move both your tests to their own folder and write a custom no-op (as in, no actual transformaion) driver that run specific migrations and could here, display the location of specific bits of the AST, such as the Pexp_fun with the bar argument on the standard output.

I'm happy to help with the refactoring of those tests if needed so please let me know!

Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
@jchavarri
Copy link
Contributor Author

Hi @NathanReb thanks for the quick review :)

I applied the following changes:

  • In b8e1170, I reverted the fix and added a small exe that checks the locations integrity for the given AST nodes
  • In 6cc652c, I re-applied the fix and can see how the tests errors are gone

I also removed the previous location tests.

Please lmk if something like this is what you had in mind.

Signed-off-by: Javier Chavarri <[email protected]>
Signed-off-by: Javier Chavarri <[email protected]>
Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

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

This is exactly what I had in mind, thanks for taking the time to refactor it and add the changelog entry!

@NathanReb NathanReb merged commit 44583fc into ocaml-ppx:main Jul 1, 2024
5 of 6 checks passed
@jchavarri jchavarri deleted the add-test-for-503 branch July 1, 2024 15:24
NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Jul 22, 2024
- Fix a bug where `Code_path.main_module_name` would not properly remove
  extensions from the filename and therefore return an invalid module name.
  (ocaml-ppx/ppxlib#512, @NathanReb)

- Add `-unused-type-warnings` flag to the driver to allow users to disable
  only the generation of warning 34 silencing structure items when using
  `[@@deriving ...]` on type declarations. (ocaml-ppx/ppxlib#511, @mbarbin, @NathanReb)

- Make `-unused-code-warnings` flag to the driver also controls the generation
  of warning 34 silencing structure items when using `[@@deriving ...]` on type
  declarations. (ocaml-ppx/ppxlib#510, @mbarbin, @NathanReb)

- Driver: Add `-unused-code-warnings=force` command-line flag argument. (ocaml-ppx/ppxlib#490, @mbarbin)

- new functions `Ast_builder.{e,p}list_tail` that take an extra tail
  expression/pattern argument parameter compared to `Ast_builder.{e,p}list`, so
  they can build ASTs like `a :: b :: c` instead of only `[ a; b ]`.
  (ocaml-ppx/ppxlib#498, ocaml-ppx/ppxlib#502, @v-gb, @NathanReb)

- Fix `Longident.parse` so it also handles indexing operators such as
  `.!()`, `.%(;..)<-`, or `Vec.(.%())` (ocaml-ppx/ppxlib#494, @Octachron)

- Add a `special_function'` variant which directly takes a `Longident.t`
  argument to avoid the issue that `Longident.t` cover distinct syntaxic classes
  which cannot be easily parsed by a common parser (ocaml-ppx/ppxlib#496, @Octachron).

- Keep location ranges consistent when migrating `Pexp_function` nodes from 5.2+
  to older versions (ocaml-ppx/ppxlib#504, @jchavarri)

- Fix `-locations-check` behaviour so it is no longer required to pass `-check`
  as well to enable location checks. (ocaml-ppx/ppxlib#506, @NathanReb)

Signed-off-by: Nathan Rebours <[email protected]>
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
- Fix a bug where `Code_path.main_module_name` would not properly remove
  extensions from the filename and therefore return an invalid module name.
  (ocaml-ppx/ppxlib#512, @NathanReb)

- Add `-unused-type-warnings` flag to the driver to allow users to disable
  only the generation of warning 34 silencing structure items when using
  `[@@deriving ...]` on type declarations. (ocaml-ppx/ppxlib#511, @mbarbin, @NathanReb)

- Make `-unused-code-warnings` flag to the driver also controls the generation
  of warning 34 silencing structure items when using `[@@deriving ...]` on type
  declarations. (ocaml-ppx/ppxlib#510, @mbarbin, @NathanReb)

- Driver: Add `-unused-code-warnings=force` command-line flag argument. (ocaml-ppx/ppxlib#490, @mbarbin)

- new functions `Ast_builder.{e,p}list_tail` that take an extra tail
  expression/pattern argument parameter compared to `Ast_builder.{e,p}list`, so
  they can build ASTs like `a :: b :: c` instead of only `[ a; b ]`.
  (ocaml-ppx/ppxlib#498, ocaml-ppx/ppxlib#502, @v-gb, @NathanReb)

- Fix `Longident.parse` so it also handles indexing operators such as
  `.!()`, `.%(;..)<-`, or `Vec.(.%())` (ocaml-ppx/ppxlib#494, @Octachron)

- Add a `special_function'` variant which directly takes a `Longident.t`
  argument to avoid the issue that `Longident.t` cover distinct syntaxic classes
  which cannot be easily parsed by a common parser (ocaml-ppx/ppxlib#496, @Octachron).

- Keep location ranges consistent when migrating `Pexp_function` nodes from 5.2+
  to older versions (ocaml-ppx/ppxlib#504, @jchavarri)

- Fix `-locations-check` behaviour so it is no longer required to pass `-check`
  as well to enable location checks. (ocaml-ppx/ppxlib#506, @NathanReb)

Signed-off-by: Nathan Rebours <[email protected]>
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.

Badly formed locations for Pexp_fun after 5.2 leads to Merlin confusion
2 participants