Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/prism
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ module Prism
source, filepath = read_source(argv)
result = Prism.parse(source)


if result.errors.any?
puts result.errors_format
else
Expand Down
3 changes: 3 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4065,6 +4065,9 @@ nodes:
- on error: NoKeywordsParameterNode
# On parsing error of `f(..., ...)`, the first forwarding parameter is moved here:
- on error: ForwardingParameterNode
# On parsing error of `f(&nil, &foo)`/`f(&foo, &nil)`, the first forwarding parameter is moved here:
- on error: BlockParameterNode
- on error: NoBlockParameterNode
- name: keywords
type: node[]
kind:
Expand Down
4 changes: 3 additions & 1 deletion lib/prism/node_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ def signature
case param
when MultiTargetNode
names << [:req]
when NoKeywordsParameterNode, KeywordRestParameterNode, ForwardingParameterNode
when NoKeywordsParameterNode, KeywordRestParameterNode,
NoBlockParameterNode, BlockParameterNode,
ForwardingParameterNode
# Invalid syntax, e.g. "def f(**nil, ...)" moves the NoKeywordsParameterNode to posts
raise "Invalid syntax"
else
Expand Down
61 changes: 61 additions & 0 deletions snapshots/4.1/noblock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@ ProgramNode (location: (1,0)-(4,12))
├── flags: ∅
├── locals: []
└── statements:
@ StatementsNode (location: (1,0)-(4,12))
├── flags: ∅
└── body: (length: 2)
├── @ DefNode (location: (1,0)-(2,3))
│ ├── flags: newline
│ ├── name: :foo
│ ├── name_loc: (1,4)-(1,7) = "foo"
│ ├── receiver: ∅
│ ├── parameters:
│ │ @ ParametersNode (location: (1,8)-(1,12))
│ │ ├── flags: ∅
│ │ ├── requireds: (length: 0)
│ │ ├── optionals: (length: 0)
│ │ ├── rest: ∅
│ │ ├── posts: (length: 0)
│ │ ├── keywords: (length: 0)
│ │ ├── keyword_rest: ∅
│ │ └── block:
│ │ @ NoBlockParameterNode (location: (1,8)-(1,12))
│ │ ├── flags: ∅
│ │ ├── operator_loc: (1,8)-(1,9) = "&"
│ │ └── keyword_loc: (1,9)-(1,12) = "nil"
│ ├── body: ∅
│ ├── locals: []
│ ├── def_keyword_loc: (1,0)-(1,3) = "def"
│ ├── operator_loc: ∅
│ ├── lparen_loc: (1,7)-(1,8) = "("
│ ├── rparen_loc: (1,12)-(1,13) = ")"
│ ├── equal_loc: ∅
│ └── end_keyword_loc: (2,0)-(2,3) = "end"
└── @ LambdaNode (location: (4,0)-(4,12))
├── flags: newline
├── locals: []
├── operator_loc: (4,0)-(4,2) = "->"
├── opening_loc: (4,10)-(4,11) = "{"
├── closing_loc: (4,11)-(4,12) = "}"
├── parameters:
│ @ BlockParametersNode (location: (4,3)-(4,9))
│ ├── flags: ∅
│ ├── parameters:
│ │ @ ParametersNode (location: (4,4)-(4,8))
│ │ ├── flags: ∅
│ │ ├── requireds: (length: 0)
│ │ ├── optionals: (length: 0)
│ │ ├── rest: ∅
│ │ ├── posts: (length: 0)
│ │ ├── keywords: (length: 0)
│ │ ├── keyword_rest: ∅
│ │ └── block:
│ │ @ NoBlockParameterNode (location: (4,4)-(4,8))
│ │ ├── flags: ∅
│ │ ├── operator_loc: (4,4)-(4,5) = "&"
│ │ └── keyword_loc: (4,5)-(4,8) = "nil"
│ ├── locals: (length: 0)
│ ├── opening_loc: (4,3)-(4,4) = "("
│ └── closing_loc: (4,8)-(4,9) = ")"
└── body: ∅
2 changes: 1 addition & 1 deletion src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -13949,7 +13949,7 @@ parse_parameters(
pm_token_t operator = parser->previous;
pm_node_t *param;

if (accept1(parser, PM_TOKEN_KEYWORD_NIL)) {
if (parser->version >= PM_OPTIONS_VERSION_CRUBY_4_1 && accept1(parser, PM_TOKEN_KEYWORD_NIL)) {
param = (pm_node_t *) pm_no_block_parameter_node_create(parser, &operator, &parser->previous);
} else {
pm_token_t name = {0};
Expand Down
6 changes: 6 additions & 0 deletions test/prism/errors/3.3-4.0/noblock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def foo(&nil)
^~~ unexpected 'nil'; expected a `)` to close the parameters
^ unexpected ')', expecting end-of-input
^ unexpected ')', ignoring it
end

12 changes: 12 additions & 0 deletions test/prism/errors/4.1/multiple_blocks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def foo(&nil, &nil); end
^ unexpected parameter order
^~~~ multiple block parameters; only one block is allowed

def foo(&foo, &nil); end
^ unexpected parameter order
^~~~ multiple block parameters; only one block is allowed

def foo(&nil, &foo); end
^ unexpected parameter order
^~~~ multiple block parameters; only one block is allowed

4 changes: 4 additions & 0 deletions test/prism/fixtures/4.1/noblock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def foo(&nil)
end

-> (&nil) {}
4 changes: 2 additions & 2 deletions test/prism/locals_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LocalsTest < TestCase
"command_method_call_2.txt",

# https://bugs.ruby-lang.org/issues/21669
"4.1/void_value.txt"
"4.1/void_value.txt",
]

Fixture.each_for_current_ruby(except: except) do |fixture|
Expand Down Expand Up @@ -207,7 +207,7 @@ def prism_locals(source)
end
end

if params.block
if params.block.is_a?(BlockParameterNode)
sorted << (params.block.name || :&)
end

Expand Down
3 changes: 3 additions & 0 deletions test/prism/ruby/ripper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class RipperTest < TestCase
# https://bugs.ruby-lang.org/issues/21669
incorrect << "4.1/void_value.txt"

# https://bugs.ruby-lang.org/issues/19979
incorrect << "4.1/noblock.txt"

# Skip these tests that we haven't implemented yet.
omitted_sexp_raw = [
"bom_leading_space.txt",
Expand Down