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

Backport PR #1800 #73

Merged
merged 4 commits into from
Jul 29, 2024
Merged

Backport PR #1800 #73

merged 4 commits into from
Jul 29, 2024

Conversation

liam923
Copy link
Contributor

@liam923 liam923 commented Jul 26, 2024

Backport PR #1800 from upstream , which fixes a bug in destructing functions with optional arguments.

@goldfirere
Copy link
Contributor

I can confirm that this PR is a correct backport of the patch from upstream merlin. So that's good.

But I think there is a better way to do this: just fix Untypeast. The fix as written is fragile, in that it will do the wrong thing in the presence of ghost locations from ppxes.

I would think a better solution would be to record, in typedtree, whether an optional argument was actually passed or not. Maybe by editing arg_label, or maybe by using Omitted somehow.

That said, it's probably best just to merge this patch for now. I predict, though, that we'll get reports of new odd behavior soon.

@ncik-roberts
Copy link
Contributor

ncik-roberts commented Jul 26, 2024

Do you know if there's a reason why the code doesn't also look for whether the argument is None? That would help keep this heuristic from being broken by a ppx, I think.

@liam923
Copy link
Contributor Author

liam923 commented Jul 26, 2024

@goldfirere For what it's worth, Merlin destruct already does the wrong thing in the presence of ppxes. For example, destructing let%map x = y in z will produce match Let_syntax.map y ~f:(fun x -> x) with .... This preserves semantics, unlike the potential bad interaction you're talking about, but I would argue it is just as bad because users will still go back and modify the code produced by Merlin.

I do agree though that modifying the typedtree would be a nicer solution. An even nicer solution in my opinion would be recovering the original text typed by the user and using it instead, which would circumvent any ppx issues.

I think @ncik-roberts solution of checking whether the argument is None is a reasonable improvement on this backport. I'll do that.

src/analysis/destruct.ml Outdated Show resolved Hide resolved
@liam923
Copy link
Contributor Author

liam923 commented Jul 29, 2024

I'm going to hold off merging this until Nick's suggestion has filtered into upstream and then replace my changes in this PR with that. That way, we keep in sync with upstream.

@ncik-roberts
Copy link
Contributor

ocaml/merlin#1807 appears to have been merged into ocaml/merlin.

liam923 and others added 4 commits July 29, 2024 11:14
Signed-off-by: Liam Stevenson <lstevenson@janestreet.com>
Signed-off-by: Liam Stevenson <lstevenson@janestreet.com>
This reverts commit 3d539a9.

Signed-off-by: Liam Stevenson <lstevenson@janestreet.com>
Signed-off-by: Liam Stevenson <lstevenson@janestreet.com>
@liam923
Copy link
Contributor Author

liam923 commented Jul 29, 2024

ocaml/merlin#1807 appears to have been merged into ocaml/merlin.

I've brought in that change now.

@goldfirere
Copy link
Contributor

Looks good to merge

@liam923 liam923 merged commit 336b063 into main Jul 29, 2024
2 checks passed
@liam923 liam923 deleted the backport-1800 branch July 29, 2024 19:19
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.

4 participants