[Bug #20423] Disallow anonymous block within argument forwarding
This commit is contained in:
parent
971b552735
commit
e36988450e
2
parse.y
2
parse.y
@ -4263,7 +4263,7 @@ block_arg : tAMPER arg_value
|
||||
}
|
||||
| tAMPER
|
||||
{
|
||||
forwarding_arg_check(p, idFWD_BLOCK, 0, "block");
|
||||
forwarding_arg_check(p, idFWD_BLOCK, idFWD_ALL, "block");
|
||||
$$ = NEW_BLOCK_PASS(NEW_LVAR(idFWD_BLOCK, &@1), &@$);
|
||||
/*% ripper: Qnil %*/
|
||||
}
|
||||
|
@ -13486,7 +13486,6 @@ parse_parameters(
|
||||
update_parameter_state(parser, &parser->current, &order);
|
||||
parser_lex(parser);
|
||||
|
||||
parser->current_scope->parameters |= PM_SCOPE_PARAMETERS_FORWARDING_BLOCK;
|
||||
parser->current_scope->parameters |= PM_SCOPE_PARAMETERS_FORWARDING_ALL;
|
||||
|
||||
pm_forwarding_parameter_node_t *param = pm_forwarding_parameter_node_create(parser, &parser->previous);
|
||||
|
@ -175,7 +175,7 @@ def f x:!a; end
|
||||
def foo x:%(xx); end
|
||||
|
||||
def foo(...)
|
||||
bar(&)
|
||||
bar(...)
|
||||
end
|
||||
|
||||
def foo(bar = (def baz(bar) = bar; 1)) = 2
|
||||
|
@ -1908,21 +1908,22 @@
|
||||
│ │ │ @ ForwardingParameterNode (location: (177,8)-(177,11))
|
||||
│ │ └── block: ∅
|
||||
│ ├── body:
|
||||
│ │ @ StatementsNode (location: (178,2)-(178,7))
|
||||
│ │ @ StatementsNode (location: (178,2)-(178,10))
|
||||
│ │ └── body: (length: 1)
|
||||
│ │ └── @ CallNode (location: (178,2)-(178,7))
|
||||
│ │ └── @ CallNode (location: (178,2)-(178,10))
|
||||
│ │ ├── flags: ignore_visibility
|
||||
│ │ ├── receiver: ∅
|
||||
│ │ ├── call_operator_loc: ∅
|
||||
│ │ ├── name: :bar
|
||||
│ │ ├── message_loc: (178,2)-(178,5) = "bar"
|
||||
│ │ ├── opening_loc: (178,5)-(178,6) = "("
|
||||
│ │ ├── arguments: ∅
|
||||
│ │ ├── closing_loc: (178,7)-(178,8) = ")"
|
||||
│ │ └── block:
|
||||
│ │ @ BlockArgumentNode (location: (178,6)-(178,7))
|
||||
│ │ ├── expression: ∅
|
||||
│ │ └── operator_loc: (178,6)-(178,7) = "&"
|
||||
│ │ ├── arguments:
|
||||
│ │ │ @ ArgumentsNode (location: (178,6)-(178,9))
|
||||
│ │ │ ├── flags: ∅
|
||||
│ │ │ └── arguments: (length: 1)
|
||||
│ │ │ └── @ ForwardingArgumentsNode (location: (178,6)-(178,9))
|
||||
│ │ ├── closing_loc: (178,9)-(178,10) = ")"
|
||||
│ │ └── block: ∅
|
||||
│ ├── locals: []
|
||||
│ ├── def_keyword_loc: (177,0)-(177,3) = "def"
|
||||
│ ├── operator_loc: ∅
|
||||
|
@ -1839,15 +1839,6 @@ end
|
||||
|
||||
o.bar { :ok }
|
||||
RUBY
|
||||
|
||||
# Test anonymous block forwarding from argument forwarding
|
||||
assert_prism_eval(<<~RUBY)
|
||||
o = Object.new
|
||||
def o.foo = yield
|
||||
def o.bar(...) = foo(&)
|
||||
|
||||
o.bar { :ok }
|
||||
RUBY
|
||||
end
|
||||
|
||||
def test_BlockLocalVariableNode
|
||||
|
@ -190,6 +190,7 @@ class TestSyntax < Test::Unit::TestCase
|
||||
assert_syntax_error("def f(...); g(0, *); end", /no anonymous rest parameter/)
|
||||
assert_syntax_error("def f(...); g(**); end", /no anonymous keyword rest parameter/)
|
||||
assert_syntax_error("def f(...); g(x: 1, **); end", /no anonymous keyword rest parameter/)
|
||||
assert_syntax_error("def f(...); g(&); end", /no anonymous block parameter/)
|
||||
end
|
||||
|
||||
def test_newline_in_block_parameters
|
||||
|
Loading…
x
Reference in New Issue
Block a user