Skip to content

Commit 7135ab5

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] Only accept noblock in Ruby 4.1+
ruby/prism@fb88c72dce
1 parent babbbf3 commit 7135ab5

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

prism/prism.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13949,7 +13949,7 @@ parse_parameters(
1394913949
pm_token_t operator = parser->previous;
1395013950
pm_node_t *param;
1395113951

13952-
if (accept1(parser, PM_TOKEN_KEYWORD_NIL)) {
13952+
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_4_1 && accept1(parser, PM_TOKEN_KEYWORD_NIL)) {
1395313953
param = (pm_node_t *) pm_no_block_parameter_node_create(parser, &operator, &parser->previous);
1395413954
} else {
1395513955
pm_token_t name = {0};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def foo(&nil)
2+
^~~ unexpected 'nil'; expected a `)` to close the parameters
3+
^ unexpected ')', expecting end-of-input
4+
^ unexpected ')', ignoring it
5+
end
6+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def foo(&nil)
2+
end
3+
4+
-> (&nil) {}

test/prism/locals_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LocalsTest < TestCase
3030
"command_method_call_2.txt",
3131

3232
# https://bugs.ruby-lang.org/issues/21669
33-
"4.1/void_value.txt"
33+
"4.1/void_value.txt",
3434
]
3535

3636
Fixture.each_for_current_ruby(except: except) do |fixture|
@@ -207,7 +207,7 @@ def prism_locals(source)
207207
end
208208
end
209209

210-
if params.block
210+
if params.block.is_a?(BlockParameterNode)
211211
sorted << (params.block.name || :&)
212212
end
213213

test/prism/ruby/ripper_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class RipperTest < TestCase
4040
# https://bugs.ruby-lang.org/issues/21669
4141
incorrect << "4.1/void_value.txt"
4242

43+
# https://bugs.ruby-lang.org/issues/19979
44+
incorrect << "4.1/noblock.txt"
45+
4346
# Skip these tests that we haven't implemented yet.
4447
omitted_sexp_raw = [
4548
"bom_leading_space.txt",

0 commit comments

Comments
 (0)