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

+ ruby31.y: Allow value omission in Hash literals #818

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/parser/ruby31.y
Expand Up @@ -3098,6 +3098,11 @@ f_opt_paren_args: f_paren_args
{
result = @builder.pair_keyword(val[0], val[1])
}
| tLABEL
{
value = @builder.call_method(nil, nil, val[0])
result = @builder.pair_keyword(val[0], value)
}
| tSTRING_BEG string_contents tLABEL_END arg_value
{
result = @builder.pair_quoted(val[0], val[1], val[2], val[3])
Expand Down
16 changes: 16 additions & 0 deletions test/test_parser.rb
Expand Up @@ -10054,6 +10054,22 @@ def test_private_endless_method_command_syntax
SINCE_3_1)
end

def test_value_omission
assert_parses(
s(:hash,
s(:pair, s(:sym, :a), s(:send, nil, :a)),
s(:pair, s(:sym, :b), s(:send, nil, :b))),
%q{{a:, b:}},
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a source_maps argument that has to be passed explicitly (%q{}).
Also, could you please add source maps checks for both key and value?

%q{^ begin
| ^ end
| ^ operator (pair)
| ~ expression (pair.sym)
| ~~ expression (pair.send)
| ~~ expression (pair)
|~~~~~~~~ expression},
SINCE_3_1)
end

def test_rasgn_line_continuation
assert_diagnoses(
[:error, :unexpected_token, { :token => 'tASSOC' }],
Expand Down