зеркало из https://github.com/github/ruby.git
[ruby/prism] Check a token after targets more strictly
(https://github.com/ruby/prism/pull/1878) Fix https://github.com/ruby/prism/pull/1832 https://github.com/ruby/prism/commit/060bcc81a8
This commit is contained in:
Родитель
5299b4a362
Коммит
b6b31f673d
|
@ -10692,8 +10692,12 @@ static pm_node_t *
|
||||||
parse_target_validate(pm_parser_t *parser, pm_node_t *target) {
|
parse_target_validate(pm_parser_t *parser, pm_node_t *target) {
|
||||||
pm_node_t *result = parse_target(parser, target);
|
pm_node_t *result = parse_target(parser, target);
|
||||||
|
|
||||||
// Ensure that we have either an = or a ) after the targets.
|
// Ensure that we have one of an =, an 'in' in for indexes, and a ')' in parens after the targets.
|
||||||
if (!match3(parser, PM_TOKEN_EQUAL, PM_TOKEN_PARENTHESIS_RIGHT, PM_TOKEN_KEYWORD_IN)) {
|
if (
|
||||||
|
!match1(parser, PM_TOKEN_EQUAL) &&
|
||||||
|
!(context_p(parser, PM_CONTEXT_FOR_INDEX) && match1(parser, PM_TOKEN_KEYWORD_IN)) &&
|
||||||
|
!(context_p(parser, PM_CONTEXT_PARENS) && match1(parser, PM_TOKEN_PARENTHESIS_RIGHT))
|
||||||
|
) {
|
||||||
pm_parser_err_node(parser, result, PM_ERR_WRITE_TARGET_UNEXPECTED);
|
pm_parser_err_node(parser, result, PM_ERR_WRITE_TARGET_UNEXPECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13746,7 +13750,9 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
|
||||||
// Otherwise, we're going to parse the first statement in the list
|
// Otherwise, we're going to parse the first statement in the list
|
||||||
// of statements within the parentheses.
|
// of statements within the parentheses.
|
||||||
pm_accepts_block_stack_push(parser, true);
|
pm_accepts_block_stack_push(parser, true);
|
||||||
|
context_push(parser, PM_CONTEXT_PARENS);
|
||||||
pm_node_t *statement = parse_expression(parser, PM_BINDING_POWER_STATEMENT, PM_ERR_CANNOT_PARSE_EXPRESSION);
|
pm_node_t *statement = parse_expression(parser, PM_BINDING_POWER_STATEMENT, PM_ERR_CANNOT_PARSE_EXPRESSION);
|
||||||
|
context_pop(parser);
|
||||||
|
|
||||||
// Determine if this statement is followed by a terminator. In the
|
// Determine if this statement is followed by a terminator. In the
|
||||||
// case of a single statement, this is fine. But in the case of
|
// case of a single statement, this is fine. But in the case of
|
||||||
|
|
|
@ -1225,6 +1225,11 @@ module Prism
|
||||||
assert_error_messages "Foo::foo,", error_messages
|
assert_error_messages "Foo::foo,", error_messages
|
||||||
assert_error_messages "foo[foo],", error_messages
|
assert_error_messages "foo[foo],", error_messages
|
||||||
assert_error_messages "(foo, bar)", error_messages
|
assert_error_messages "(foo, bar)", error_messages
|
||||||
|
assert_error_messages "foo((foo, bar))", error_messages
|
||||||
|
assert_error_messages "foo((*))", error_messages
|
||||||
|
assert_error_messages "foo(((foo, bar), *))", error_messages
|
||||||
|
assert_error_messages "(foo, bar) + 1", error_messages
|
||||||
|
assert_error_messages "(foo, bar) in baz", error_messages
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_call_with_block_and_write
|
def test_call_with_block_and_write
|
||||||
|
|
Загрузка…
Ссылка в новой задаче