Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug #18890] newline should be insignificant after pattern label #6087

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

Merged
merged 2 commits into from
Jul 5, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -7457,7 +7457,7 @@ parser_string_term(struct parser_params *p, int func)
}
if ((func & STR_FUNC_LABEL) && IS_LABEL_SUFFIX(0)) {
nextc(p);
SET_LEX_STATE(EXPR_BEG|EXPR_LABEL);
SET_LEX_STATE(EXPR_ARG|EXPR_LABELED);
return tLABEL_END;
}
SET_LEX_STATE(EXPR_END);
Expand Down
33 changes: 33 additions & 0 deletions test/ruby/test_parse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,39 @@ def test_escaped_space
assert_syntax_error('x = \ 42', /escaped space/)
end

def test_label
expected = {:foo => 1}

code = '{"foo": 1}'
assert_valid_syntax(code)
assert_equal(expected, eval(code))

code = '{foo: 1}'
assert_valid_syntax(code)
assert_equal(expected, eval(code))

class << (obj = Object.new)
attr_reader :arg
def set(arg)
@arg = arg
end
end

assert_valid_syntax(code = "#{<<~"do;"}\n#{<<~'end;'}")
do;
obj.set foo:
1
end;
assert_equal(expected, eval(code))

assert_valid_syntax(code = "#{<<~"do;"}\n#{<<~'end;'}")
do;
obj.set "foo":
1
end;
assert_equal(expected, eval(code))
end

=begin
def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}
Expand Down
15 changes: 15 additions & 0 deletions test/ruby/test_pattern_matching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,21 @@ def test_hash_pattern
end
end

[{a: 42}, {b: 42}].each do |i|
assert_block('newline should be insignificant after pattern label') do
case i
in a:
0
true
in "b":
0
true
else
false
end
end
end

assert_syntax_error(%q{
case _
in a:, a:
Expand Down