ripper: Check if anonymous parameters defined [Bug #18828]
This commit is contained in:
parent
048f14221c
commit
1a70973f75
Notes:
git
2022-06-14 20:42:12 +09:00
24
parse.y
24
parse.y
@ -2856,14 +2856,13 @@ block_arg : tAMPER arg_value
|
|||||||
}
|
}
|
||||||
| tAMPER
|
| tAMPER
|
||||||
{
|
{
|
||||||
/*%%%*/
|
|
||||||
if (!local_id(p, ANON_BLOCK_ID)) {
|
if (!local_id(p, ANON_BLOCK_ID)) {
|
||||||
compile_error(p, "no anonymous block parameter");
|
compile_error(p, "no anonymous block parameter");
|
||||||
}
|
}
|
||||||
|
/*%%%*/
|
||||||
$$ = NEW_BLOCK_PASS(NEW_LVAR(ANON_BLOCK_ID, &@1), &@$);
|
$$ = NEW_BLOCK_PASS(NEW_LVAR(ANON_BLOCK_ID, &@1), &@$);
|
||||||
/*%
|
/*% %*/
|
||||||
$$ = Qnil;
|
/*% ripper: Qnil %*/
|
||||||
%*/
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -2894,10 +2893,10 @@ args : arg_value
|
|||||||
}
|
}
|
||||||
| tSTAR
|
| tSTAR
|
||||||
{
|
{
|
||||||
/*%%%*/
|
|
||||||
if (!local_id(p, ANON_REST_ID)) {
|
if (!local_id(p, ANON_REST_ID)) {
|
||||||
compile_error(p, "no anonymous rest parameter");
|
compile_error(p, "no anonymous rest parameter");
|
||||||
}
|
}
|
||||||
|
/*%%%*/
|
||||||
$$ = NEW_SPLAT(NEW_LVAR(ANON_REST_ID, &@1), &@$);
|
$$ = NEW_SPLAT(NEW_LVAR(ANON_REST_ID, &@1), &@$);
|
||||||
/*% %*/
|
/*% %*/
|
||||||
/*% ripper: args_add_star!(args_new!, Qnil) %*/
|
/*% ripper: args_add_star!(args_new!, Qnil) %*/
|
||||||
@ -2918,10 +2917,10 @@ args : arg_value
|
|||||||
}
|
}
|
||||||
| args ',' tSTAR
|
| args ',' tSTAR
|
||||||
{
|
{
|
||||||
/*%%%*/
|
|
||||||
if (!local_id(p, ANON_REST_ID)) {
|
if (!local_id(p, ANON_REST_ID)) {
|
||||||
compile_error(p, "no anonymous rest parameter");
|
compile_error(p, "no anonymous rest parameter");
|
||||||
}
|
}
|
||||||
|
/*%%%*/
|
||||||
$$ = rest_arg_append(p, $1, NEW_LVAR(ANON_REST_ID, &@3), &@$);
|
$$ = rest_arg_append(p, $1, NEW_LVAR(ANON_REST_ID, &@3), &@$);
|
||||||
/*% %*/
|
/*% %*/
|
||||||
/*% ripper: args_add_star!($1, Qnil) %*/
|
/*% ripper: args_add_star!($1, Qnil) %*/
|
||||||
@ -5489,8 +5488,8 @@ f_kwrest : kwrest_mark tIDENTIFIER
|
|||||||
}
|
}
|
||||||
| kwrest_mark
|
| kwrest_mark
|
||||||
{
|
{
|
||||||
|
arg_var(p, ANON_KEYWORD_REST_ID);
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
arg_var(p, shadowing_lvar(p, get_id(ANON_KEYWORD_REST_ID)));
|
|
||||||
/*% %*/
|
/*% %*/
|
||||||
/*% ripper: kwrest_param!(Qnil) %*/
|
/*% ripper: kwrest_param!(Qnil) %*/
|
||||||
}
|
}
|
||||||
@ -5564,8 +5563,8 @@ f_rest_arg : restarg_mark tIDENTIFIER
|
|||||||
}
|
}
|
||||||
| restarg_mark
|
| restarg_mark
|
||||||
{
|
{
|
||||||
|
arg_var(p, ANON_REST_ID);
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
arg_var(p, shadowing_lvar(p, get_id(ANON_REST_ID)));
|
|
||||||
/*% %*/
|
/*% %*/
|
||||||
/*% ripper: rest_param!(Qnil) %*/
|
/*% ripper: rest_param!(Qnil) %*/
|
||||||
}
|
}
|
||||||
@ -5585,11 +5584,10 @@ f_block_arg : blkarg_mark tIDENTIFIER
|
|||||||
}
|
}
|
||||||
| blkarg_mark
|
| blkarg_mark
|
||||||
{
|
{
|
||||||
|
arg_var(p, ANON_BLOCK_ID);
|
||||||
/*%%%*/
|
/*%%%*/
|
||||||
arg_var(p, shadowing_lvar(p, get_id(ANON_BLOCK_ID)));
|
/*% %*/
|
||||||
/*%
|
/*% ripper: blockarg!(Qnil) %*/
|
||||||
$$ = dispatch1(blockarg, Qnil);
|
|
||||||
%*/
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -5721,10 +5719,10 @@ assoc : arg_value tASSOC arg_value
|
|||||||
}
|
}
|
||||||
| tDSTAR
|
| tDSTAR
|
||||||
{
|
{
|
||||||
/*%%%*/
|
|
||||||
if (!local_id(p, ANON_KEYWORD_REST_ID)) {
|
if (!local_id(p, ANON_KEYWORD_REST_ID)) {
|
||||||
compile_error(p, "no anonymous keyword rest parameter");
|
compile_error(p, "no anonymous keyword rest parameter");
|
||||||
}
|
}
|
||||||
|
/*%%%*/
|
||||||
$$ = list_append(p, NEW_LIST(0, &@$),
|
$$ = list_append(p, NEW_LIST(0, &@$),
|
||||||
NEW_LVAR(ANON_KEYWORD_REST_ID, &@$));
|
NEW_LVAR(ANON_KEYWORD_REST_ID, &@$));
|
||||||
/*% %*/
|
/*% %*/
|
||||||
|
@ -155,6 +155,44 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_anonymous_block_forwarding
|
||||||
|
thru_args_add_block = false
|
||||||
|
parse('def b(&); c(&); end', :on_args_add_block) {thru_args_add_block = true}
|
||||||
|
assert_equal true, thru_args_add_block
|
||||||
|
assert_match "no anonymous block parameter", compile_error('def b; c(&); end')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_anonymous_rest_forwarding
|
||||||
|
[
|
||||||
|
'c(*)',
|
||||||
|
'c(*, *)',
|
||||||
|
].each do |code|
|
||||||
|
thru_args_add_star = false
|
||||||
|
src = "def b(*); #{code} end"
|
||||||
|
parse(src, :on_args_add_star) {thru_args_add_star = true}
|
||||||
|
assert_equal true, thru_args_add_star, src
|
||||||
|
|
||||||
|
src = "def b; #{code} end"
|
||||||
|
assert_match "no anonymous rest parameter", compile_error(src), src
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_anonymous_keyword_rest_forwarding
|
||||||
|
[
|
||||||
|
'c(**)',
|
||||||
|
'c(k: 1, **)',
|
||||||
|
'c(**, k: 1)',
|
||||||
|
].each do |code|
|
||||||
|
thru_assoc_splat = false
|
||||||
|
src = "def b(**); #{code} end"
|
||||||
|
parse(src, :on_assoc_splat) {thru_assoc_splat = true}
|
||||||
|
assert_equal true, thru_assoc_splat, src
|
||||||
|
|
||||||
|
src = "def b; #{code} end"
|
||||||
|
assert_match "no anonymous keyword rest parameter", compile_error(src), src
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_arg_paren
|
def test_arg_paren
|
||||||
# FIXME
|
# FIXME
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user