-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support auto-splatting in captured block literals #10251
Support auto-splatting in captured block literals #10251
Conversation
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.
Awesome!
FYI, This CI is complaining for real in this PR in spec/compiler/semantic/closure_spec.cr:385, although for some reason it didn't fail on all platforms 🤔 |
Ah this is because I forgot to change some expected |
It's still failing just on some platforms. The merge from master was done in an old commit. I am not sure if that's the reason. |
Resolves #7706.
In a case like
The compiler now rewrites the block into the following
ProcLiteral
:The conditions for auto-splatting are the same as non-captured blocks: the block must accept a single
Tuple
instance, there must be 2 or more block parameters, and none of these parameters must be a splat.When there are fewer block parameters than tuple elements, the whole tuple is still passed but the
__temp
assignments corresponding to the missing parameters will be gone.Tuple unpacking of individual block parameters is also possible. For example, given
The expanded
Proc
is more or less equivalent toInternally
(x, y)
is transformed into__arg0
by the parser;__temp_1
is injected in the semantic phase when the block is actually matched against the enclosing method.