whitequark / parser

A Ruby parser.
Other
1.59k stars 199 forks source link

undefined method `type' for nil:NilClass when using forwarded anonymous kwargs and additional kwarg #911

Closed owst closed 1 year ago

owst commented 1 year ago

With test.rb:

def foo(**kwargs) = p kwargs

def bar(**) = foo(**, from_bar: true)

bar(x: 1, y: 2)

then ruby 3.2 evaluates as follows:

$ ruby -v test.rb
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-darwin22]
{:x=>1, :y=>2, :from_bar=>true}

but unfortunately ruby-parse raises:

$ ruby-parse --version
ruby-parse based on parser version 3.2.1.0
$ ruby-parse --32 test.rb
Failed on: test.rb
/Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/builders/default.rb:550:in `block (2 levels) in associate': undefined method `type' for nil:NilClass (NoMethodError)

          case key1.type
                   ^^^^^
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/builders/default.rb:542:in `upto'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/builders/default.rb:542:in `block in associate'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/builders/default.rb:541:in `upto'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/builders/default.rb:541:in `associate'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/ruby32.rb:9934:in `_reduce_284'
    from (eval):3:in `_racc_do_parse_c'
    from (eval):3:in `do_parse'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/base.rb:190:in `parse'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner/ruby_parse.rb:141:in `process'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:259:in `process_buffer'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:252:in `block in process_files'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:241:in `each'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:241:in `process_files'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:221:in `block in process_all_input'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/3.2.0/benchmark.rb:296:in `measure'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:219:in `process_all_input'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner/ruby_parse.rb:137:in `process_all_input'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:35:in `execute'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/lib/parser/runner.rb:13:in `go'
    from /Users/owenstephens/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/parser-3.2.1.0/bin/ruby-parse:7:in `<top (required)>'
    from /Users/owenstephens/.rbenv/versions/3.2.1/bin/ruby-parse:25:in `load'
    from /Users/owenstephens/.rbenv/versions/3.2.1/bin/ruby-parse:25:in `<main>'