-
Notifications
You must be signed in to change notification settings - Fork 512
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
ruby27: Support forwarding arguments syntax #3420
Conversation
9de5aec
to
b1a2599
Compare
Rebased on master |
b1a2599
to
f34f667
Compare
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.
The parser and desugar changes look great. I think we'd like to omit the resolver & sig changes for now.
f34f667
to
87ef115
Compare
Removed the resolver part but left the test to show the current behaviour. As you can see in |
Sorry for not being clear. My suggestion was that we keep desugaring to |
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
This commit tracks upstream commit ruby/ruby@95f7992. Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
87ef115
to
588eca7
Compare
Oh sorry for the confusion! I added an error if you try to provide a signature for a method declared with argument forwarding syntax: sig { void } # error: Unsupported `sig` for argument forwarding syntax. Rewrite the method as `def A#foo(*args, **kwargs, &blk)` to use a signature
def foo(...); end It's less confusing that way 👍 |
args.emplace_back(node2TreeImpl(dctx, std::move(kwrest))); | ||
// add `&<fwd-block>` | ||
unique_ptr<parser::Node> block = make_unique<parser::Blockarg>(fargs->loc, core::Names::fwdBlock()); | ||
args.emplace_back(node2TreeImpl(dctx, std::move(block))); |
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.
nice i like these names!
Thanks so much for being patient through all the back and forth! |
Motivation
Ruby 2.7 introduced the argument forwarding syntax:
And if I'm following this documentation correctly, it would be comparable to...
This PR imports the whitequark tests, updates the parser and introduces desugaring/resolving support for the forwarding syntax.
Approach
During
parsing
we store...
calls as aFORWARD(ED)_ARG
node in the AST:During
desugar
the...
node are transformed into*args, **kwargs, &block
:During
resolve
, nothing change regarding local variables and arguments resolution:But if a signature if provided we check that it contains the right parameters:
Then rename the
args
to<args>
to match the desugared signature (and avoid someone using theargs
when it's not really declared:Test plan
See included automated tests.