-
Notifications
You must be signed in to change notification settings - Fork 39
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
Add regression tests for qualified type #201
Conversation
Not sure either, what do you think @vch9 ? |
for reference, the generated code:
|
Yes this is a bug, thank you for reporting it. I translated
Based on my last discovery, the bug is pretty much easy to fix. We can begin by having a function which create an identifier for a qualified type: let name_lg = function
| Lident s -> name s
| Ldot (lg, s) -> longident_to_str lg ^ "." ^ name s (* Q.t becomes Q.gen *)
| Lapply _ -> raise (Invalid_argument "We do not produce gen name for Lapply") Then we change the precedent creation of generator from let gen ~loc ?(env = TypeGen.empty) lg =
let (module A) = Ast_builder.make loc in
match lg with
| Lident s ->
Option.value ~default:(name s |> A.evar) @@ TypeGen.find_opt s env
| Ldot (lg, s) -> A.(pexp_construct (Located.mk @@ Ldot (lg, name s)) None)
| Lapply (_, _) -> raise (Invalid_argument "gen received an Lapply") to let gen ~loc ?(env = TypeGen.empty) lg =
let (module A) = Ast_builder.make loc in
let s = longident_to_str lg in
let name = name_lg lg in
Option.value ~default:(A.evar name) @@ TypeGen.find_opt s env Adding a regressing test is a good idea (I should already have done it tbh). What would be more convenient, put our trust in the compiler ? put regression tests on the generated code ?
it would not catch the difference between a Pexp_construct and a Pexp_ident. |
Thanks for finding the erroneous |
I also prefer your fix :) Maybe we could have a test such as module A = struct
type a = (int [@gen QCheck.Gen.pure 0])
[@@deriving qcheck]
module B = struct
type b = (int [@gen QCheck.Gen.pure 1])
[@@deriving qcheck]
end
end
type a = A.t
[@@deriving qcheck]
type b = A.B.t
[@@deriving qcheck] with a unit (or pbt?) to test |
Adding more tests is a good idea, you can push in the branch, but It also could go in another MR. This MR has a fix and a regresssion test. Is the falling test normal? |
Unfortunately I can't, I'm not a QCheck's maintainer. This will be done in a follow-up MR. |
I don't think anyone can push onto your branch, @bobot, it's from your fork :) |
Can't we on github allow modifications from maintainers? |
Maybe, but I've never understood how to push on such a branch 😅 |
The last time I did that I believe I just added the remote of the branch author. But except for the failing test the branch is done for me, and I don't understand why the test is failing. |
Rebase on master, #203 should fix the test. |
63e23e4
to
fac2c39
Compare
LGTM, thank you for the fix :) |
@c-cube If you also agree we could merge this |
let's go! |
Is there a release planned? |
I kind of lost context, but I think there were just a few PRs blocking 0.19, and @jmid is going through them like a hurricane 😁 |
Qualified type are currently concatenated into a unique identifier, so it becomes a constructor:
I added the test outside
test.ml
because string comparison doesn't show the difference (let gen = Q.gen
in both case). I tried to see if the bug was obvious but I haven't found anything.