-
-
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 splat expansions inside tuple and array literals #10429
Support splat expansions inside tuple and array literals #10429
Conversation
Instead of |
# | ||
# will end up calling `typeof(1, ::Enumerable.element_type({2, 3.5}), 4)`. | ||
# | ||
# NOTE: there should never be a need to call this method outside the standard library. |
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.
# NOTE: there should never be a need to call this method outside the standard library. | |
# WARNING: there should never be a need to call this method outside the standard library. |
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.
I don't think this should be a warning.
We could consider making this method nodoc, though. It's only internal API.
The PR currently doesn't allow non- |
I suppose this restriction is not really necessary. However, what type would implement a compatible |
For comparison @[Flags]
enum Foo
X
Y
Z
end
set = Set(Foo).new
set.concat(Foo::All) # => Set{X, Y, Z} |
accept exp | ||
{exp.type, @last} | ||
|
||
if node.elements.any?(Splat) |
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.
Great use of this variant of any?
! It actually reads really nice too :-)
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.
I love this new feature! ❤️
Implements #3718. Does not implement double splats and #3718 (comment) (
#to_array_splat
). The codegen portion forTuple
splats is copied directly from #10193's head (with the codegen optimization).Tuple and array literals have slightly different requirements on the splatted value's interface:
Very few array-like types implement#each
but do not includeEnumerable
, so the requirement onEnumerable
shouldn't be a pressing issue. (CSV
andRegex::MatchData
are notable exceptions in the standard library.)