'process_hash': undefined method `first' for nil:NilClass
joenas opened this issue · 5 comments
Working code
class A
def initialize(var, keyword: nil, **args)
end
end
class B
def initialize
var, keyword, args = :var, :keyword, {arg1: :arg1}
A.new(var, keyword: keyword, **args)
end
end
puts B.new => #<B:0x007fabea057b28>
Fails
require 'ruby2ruby'
require 'ruby_parser'
ruby = '
class B
def initialize
var, keyword, args = :var, :keyword, {arg1: :arg1}
A.new(var, keyword: keyword, **args)
end
end
'
sexp = RubyParser.new.process(ruby)
Ruby2Ruby.new.process(sexp)
Error
ruby2ruby-2.1.3/lib/ruby2ruby.rb:486:in
process_hash': undefined method first' for nil:NilClass
Is it this or sexp_processor
?
As a total aside... I know this is an abstracted example, but you know that the A.new
is totally thrown away, right? I don't want you getting bit by that.
This is actually a bug in ruby_parser. The call currently looks like:
s(:call,
s(:const, :A),
:new,
s(:call, nil, :var),
s(:hash, s(:lit, :keyword), s(:call, nil, :keyword), s(:call, nil, :args)))
which is just wrong. I think @whitequark already filed a related bug over there, but you might want to check if you want to track this.
As a total aside... I know this is an abstracted example, but you know that the A.new is totally thrown away, right? I don't want you getting bit by that.
Yeah I know but thanks 😄 The actual code looked a bit different but I just cut the not so relevant parts out.
but you might want to check if you want to track this.
Him or me?
@zenspider I cannot find the bug in the ruby_parser repository. Do you have a reference?
Fixed on both ruby_parser and ruby2ruby.