[Feature #19370] Blocks without anonymous parameters should not affect

This commit is contained in:
Nobuyoshi Nakada 2023-12-25 15:38:12 +09:00
Родитель 6e13cde457
Коммит 596db9c1f4
2 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -15070,13 +15070,13 @@ forwarding_arg_check(struct parser_params *p, ID arg, ID all, const char *var)
args = p->lvtbl->args;
while (vars && !DVARS_TERMINAL_P(vars->prev)) {
conflict |= (vtable_included(args, arg) && !(all && vtable_included(args, all)));
vars = vars->prev;
args = args->prev;
conflict |= (vtable_included(args, arg) && !(all && vtable_included(args, all)));
}
bool found = false;
if (vars && vars->prev == DVARS_INHERIT) {
if (vars && vars->prev == DVARS_INHERIT && !found) {
found = (rb_local_defined(arg, p->parent_iseq) &&
!(all && rb_local_defined(all, p->parent_iseq)));
}

Просмотреть файл

@ -77,6 +77,7 @@ class TestSyntax < Test::Unit::TestCase
def test_anonymous_block_forwarding
assert_syntax_error("def b; c(&); end", /no anonymous block parameter/)
assert_syntax_error("def b(&) ->(&) {c(&)} end", /anonymous block parameter is also used/)
assert_valid_syntax("def b(&) ->() {c(&)} end")
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
begin;
def b(&); c(&) end
@ -147,6 +148,9 @@ class TestSyntax < Test::Unit::TestCase
assert_syntax_error("def b(*) ->(*) {c(*)} end", /anonymous rest parameter is also used/)
assert_syntax_error("def b(a, *) ->(*) {c(1, *)} end", /anonymous rest parameter is also used/)
assert_syntax_error("def b(*) ->(a, *) {c(*)} end", /anonymous rest parameter is also used/)
assert_valid_syntax("def b(*) ->() {c(*)} end")
assert_valid_syntax("def b(a, *) ->() {c(1, *)} end")
assert_valid_syntax("def b(*) ->(a) {c(*)} end")
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
begin;
def b(*); c(*) end
@ -163,6 +167,9 @@ class TestSyntax < Test::Unit::TestCase
assert_syntax_error("def b(**) ->(**) {c(**)} end", /anonymous keyword rest parameter is also used/)
assert_syntax_error("def b(k:, **) ->(**) {c(k: 1, **)} end", /anonymous keyword rest parameter is also used/)
assert_syntax_error("def b(**) ->(k:, **) {c(**)} end", /anonymous keyword rest parameter is also used/)
assert_valid_syntax("def b(**) ->() {c(**)} end")
assert_valid_syntax("def b(k:, **) ->() {c(k: 1, **)} end")
assert_valid_syntax("def b(**) ->(k:) {c(**)} end")
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
begin;
def b(**); c(**) end