Skip to content

stree write turns correct code into incorrect code for method call with mix of keyword types #446

Open
@bradleybuda

Description

@bradleybuda

When calling a method with multiple keyword values, where one of the keywords is "static" and another is "dynamic" (for lack of better terms), stree write emits bad code. Possibly related to #419 but I'm not 100% certain. A minimal example:

Input

def search(keyword:, author: nil, category: nil)
  # implementation elided
end

keyword = 'Ruby'
facet = :author
value = 'Matz'

search(facet => value, keyword:)

Formatted Output

def search(keyword:, author: nil, category: nil)
  # implementation elided
end

keyword = "Ruby"
facet = :author
value = "Matz"

search(facet => value, :keyword =>)

This is with the latest released version (6.2.0). Here's a full transcript of the commands I ran, just in case I missed something:

% cat before.rb
def search(keyword:, author: nil, category: nil)
  # implementation elided
end

keyword = 'Ruby'
facet = :author
value = 'Matz'

search(facet => value, keyword:)

% cp before.rb after.rb

% bundle exec stree version
6.2.0

% bundle exec stree write after.rb
after.rb 2ms

% cat after.rb
def search(keyword:, author: nil, category: nil)
  # implementation elided
end

keyword = "Ruby"
facet = :author
value = "Matz"

search(facet => value, :keyword =>)

% ruby before.rb

% ruby after.rb
after.rb: --> after.rb
syntax error, unexpected ')'
> 1  def search(keyword:, author: nil, category: nil)
> 3  end
> 5  keyword = "Ruby"
> 6  facet = :author
> 7  value = "Matz"
> 9  search(facet => value, :keyword =>)

after.rb:9: syntax error, unexpected ')' (SyntaxError)
...ch(facet => value, :keyword =>)
...                              ^

% ruby --version
ruby 3.2.3 (2024-01-18 revision 52bb2ac0a6) [arm64-darwin23]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions