Skip to content

Commit

Permalink
Merge pull request #2335 from ruby/ruby-next-fixes
Browse files Browse the repository at this point in the history
Fixes for ruby-next
  • Loading branch information
kddnewton authored Feb 1, 2024
2 parents b2ef327 + 51e9f73 commit 4ccf309
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 9 additions & 3 deletions lib/prism/translation/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,21 @@ def try_declare_numparam(node)

private

# This is a hook to allow consumers to disable some errors if they don't
# want them to block creating the syntax tree.
def valid_error?(error)
true
end

# If there was a error generated during the parse, then raise an
# appropriate syntax error. Otherwise return the result.
def unwrap(result)
return result if result.success?
error = result.errors.find { |error| valid_error?(error) }
return result if error.nil?

error = result.errors.first
offset_cache = build_offset_cache(source_buffer.source)

diagnostic = Diagnostic.new(error.message, build_range(error.location, offset_cache))

raise ::Parser::SyntaxError, diagnostic
end

Expand Down
4 changes: 1 addition & 3 deletions lib/prism/translation/parser/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,7 @@ def visit_false_node(node)
# foo => [*, bar, *]
# ^^^^^^^^^^^
def visit_find_pattern_node(node)
elements = [*node.requireds]
elements << node.rest if !node.rest.nil? && !node.rest.is_a?(ImplicitRestNode)
elements.concat(node.posts)
elements = [node.left, *node.requireds, node.right]

if node.constant
builder.const_pattern(visit(node.constant), token(node.opening_loc), builder.find_pattern(nil, visit_all(elements), nil), token(node.closing_loc))
Expand Down

0 comments on commit 4ccf309

Please sign in to comment.