8000 [Feature #19370] Blocks without anonymous parameters should not affect · ruby/ruby@596db9c · GitHub
[go: up one dir, main page]

Skip to content

Commit 596db9c

Browse files
committed
[Feature #19370] Blocks without anonymous parameters should not affect
1 parent 6e13cde commit 596db9c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

parse.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15070,13 +15070,13 @@ forwarding_arg_check(struct parser_params *p, ID arg, ID all, const char *var)
1507015070
args = p->lvtbl->args;
1507115071

1507215072
while (vars && !DVARS_TERMINAL_P(vars->prev)) {
15073+
conflict |= (vtable_included(args, arg) && !(all && vtable_included(args, all)));
1507315074
vars = vars->prev;
1507415075
args = args->prev;
15075-
conflict |= (vtable_included(args, arg) && !(all && vtable_included(args, all)));
1507615076
}
1507715077

1507815078
bool found = false;
15079-
if (vars && vars->prev == DVARS_INHERIT) {
15079+
if (vars && vars->prev == DVARS_INHERIT && !found) {
1508015080
found = (rb_local_defined(arg, p->parent_iseq) &&
1508115081
!(all && rb_local_defined(all, p->parent_iseq)));
1508215082
}

test/ruby/test_syntax.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def test_script_lines_encoding
7777
def test_anonymous_block_forwarding
7878
assert_syntax_error("def b; c(&); end", /no anonymous block parameter/)
7979
assert_syntax_error("def b(&) ->(&) {c(&)} end", /anonymous block parameter is also used/)
80+
assert_valid_syntax("def b(&) ->() {c(&)} end")
8081
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
8182
begin;
8283
def b(&); c(&) end
@@ -147,6 +148,9 @@ def test_anonymous_rest_forwarding
147148
assert_syntax_error("def b(*) ->(*) {c(*)} end", /anonymous rest parameter is also used/)
148149
assert_syntax_error("def b(a, *) ->(*) {c(1, *)} end", /anonymous rest parameter is also used/)
149150
assert_syntax_error("def b(*) ->(a, *) {c(*)} end", /anonymous rest parameter is also used/)
151+
assert_valid_syntax("def b(*) ->() {c(*)} end")
152+
assert_valid_syntax("def b(a, *) ->() {c(1, *)} end")
153+
assert_valid_syntax("def b(*) ->(a) {c(*)} end")
150154
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
151155
begin;
152156
def b(*); c(*) end
@@ -163,6 +167,9 @@ def test_anonymous_keyword_rest_forwarding
163167
assert_syntax_error("def b(**) ->(**) {c(**)} end", /anonymous keyword rest parameter is also used/)
164168
assert_syntax_error("def b(k:, **) ->(**) {c(k: 1, **)} end", /anonymous keyword rest parameter is also used/)
165169
assert_syntax_error("def b(**) ->(k:, **) {c(**)} end", /anonymous keyword rest parameter is also used/)
170+
assert_valid_syntax("def b(**) ->() {c(**)} end")
171+
assert_valid_syntax("def b(k:, **) ->() {c(k: 1, **)} end")
172+
assert_valid_syntax("def b(**) ->(k:) {c(**)} end")
166173
assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}")
167174
begin;
168175
def b(**); c(**) end

0 commit comments

Comments
 (0)
0