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 2695: local open + let bindings #2716

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

SanderSpies
Copy link
Contributor

@SanderSpies SanderSpies commented Apr 24, 2023

Solves #2695.

Makes it possible to use:

 let y = Promise.Ops.(
  let* x = Js.Promise.resolve(42);
  Js.Promise.resolve(x * 2);
);

Printing isn't perfect, but good enough for now.

@SanderSpies SanderSpies changed the title Fix 2695 Fix 2695: local open + let bindings Apr 24, 2023
@SanderSpies SanderSpies marked this pull request as ready for review April 24, 2023 18:49
Copy link
Member

@anmonteiro anmonteiro 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, thanks!

@@ -6442,7 +6442,12 @@ let printer = object(self:'self)
(atom (".")))
(self#formatNonSequencyExpression e))
else
Some (makeLetSequence (self#letList x))
Some
Copy link
Member

Choose a reason for hiding this comment

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

this looks exactly like the then branch.

I'm surprised this doesn't break let open Foo; bar; for example?

Perhaps the letop case should be added to isSeriesOfOpensFollowedByNonSequencyExpression, then we'd get printing for free?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, not exactly the same. The first branch results into extra braces:

-      let* x = Js.Promise.resolve(42);
-      Js.Promise.resolve(x * 2);
+      {
+        let* x = Js.Promise.resolve(42);
+        Js.Promise.resolve(x * 2);
+      }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did make a small change to avoid code duplication

Copy link
Member

Choose a reason for hiding this comment

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

I don't see how this is correct yet. I might be missing something.

Aren't we replacing ALL open calls with Foo.( ... )?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anmonteiro

Not exactly, but the solution wasn't perfect (it didn't work for nested local open modules). I've tried to improve on it with help of an extra attribute set by the parser.

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.

None yet

2 participants