-
Notifications
You must be signed in to change notification settings - Fork 29
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 import of signatures with mutually recursive types #35
Conversation
Import of signatures with mutually recursive types was broken. If a signature with mutually recursive types was defined in `a.ml`: ``` module type S = sig type t = A of u and u = B of t end ``` then the compilation of the following compilation unit `b.ml` fails: ``` module type S = [%import: (module A.S)] ``` The reason is that the following pattern matching branch was broken in two ways: ``` | (Sig_type (_, _, Trec_first) | _) :: _ when trec <> [] -> ``` (1) `_` is a catch all, so it matches in particular `Sig_type` with rec_flag other than Trec_first, i.e. the left hand side branch of pattern disjunction is useless; (2) trec should be appended to the result in the final case of the empty list (tsig = []).
Should a test-case be added? |
Ideally, yes. |
This is a very nice catch, but I would like the new code to be more readable than your proposal. Before reading your patch, I had no idea that
|
Requested by Emilio Jesús Gallego Arias: ocaml-ppx#35 (comment)
Suggested by Gabriel Scherer: ocaml-ppx#35 (comment)
@ejgallego Test-case added, thanks! @gasche Thanks for your suggestion! Indeed, it could be better written: I was misguided by the idea of making as little change as possible. I did not follow your suggestion of two mutually recursive functions as I did not know how not to repeat the call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your new implementation is fine, thanks!
CHANGES: * Fix import of signatures with mutually recursive types (Thierry Martinez ocaml-ppx/ppx_import#35, review and tweaks by Gabriel Scherer)
Import of signatures with mutually recursive types was broken.
If a signature with mutually recursive types was defined in
a.ml
:then the compilation of the following compilation unit
b.ml
fails:The reason is that the following pattern matching branch was broken in
two ways:
_
is a catch all, so it matches in particularSig_type
withrec_flag
other thanTrec_first
, i.e. the left hand side branchof pattern disjunction is useless;
trec
should be appended to the result in the final case of theempty list (
tsig = []
).