Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError in RubyLex #4719

Closed
madrob opened this issue Jul 17, 2017 · 2 comments
Closed

NoMethodError in RubyLex #4719

madrob opened this issue Jul 17, 2017 · 2 comments

Comments

@madrob
Copy link
Contributor

madrob commented Jul 17, 2017

$ ruby -v
jruby 9.1.10.0 (2.3.3) 2017-05-25 b09c48a Java HotSpot(TM) 64-Bit Server VM 25.131-b11 on 1.8.0_131-b11 +jit [darwin-x86_64]
$ cat test.rb 
require 'irb/ruby-lex'
RubyLex.new.each_top_level_statement do |s, linenum|
  puts s
end
$ echo "foo" | ruby test.rb 
NoMethodError: undefined method `encoding' for #<IO:<STDIN>>
Did you mean?  set_encoding
  block in each_top_level_statement at /Users/mdrob/.rvm/rubies/jruby-9.1.10.0/lib/ruby/stdlib/irb/ruby-lex.rb:245
                               loop at org/jruby/RubyKernel.java:1298
  block in each_top_level_statement at /Users/mdrob/.rvm/rubies/jruby-9.1.10.0/lib/ruby/stdlib/irb/ruby-lex.rb:232
                              catch at org/jruby/RubyKernel.java:1120
           each_top_level_statement at /Users/mdrob/.rvm/rubies/jruby-9.1.10.0/lib/ruby/stdlib/irb/ruby-lex.rb:231
                             <main> at test.rb:2

https://github.com/jruby/jruby/blob/master/lib/ruby/stdlib/irb/ruby-lex.rb#L245 might need to be @io.external_encoding?

@enebo
Copy link
Member

enebo commented Jul 17, 2017

I guess you can say we are bug for bug compatible!

echo "foo" | mri23 ../snippets/lex1.rb 
/home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:245:in `block (2 levels) in each_top_level_statement': undefined method `encoding' for #<IO:<STDIN>> (NoMethodError)
Did you mean?  set_encoding
	from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `loop'
	from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:232:in `block in each_top_level_statement'
	from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `catch'
	from /home/enebo/.rvm/rubies/ruby-2.3.3/lib/ruby/2.3.0/irb/ruby-lex.rb:231:in `each_top_level_statement'
	from ../snippets/lex1.rb:2:in `<main>'

Can you perhaps open up an issue on ruby-lang.org and see what they say? I see this present in 2.3 and 2.4 so I am guessing perhaps you are the first person to try this?

@enebo enebo added this to the Invalid or Duplicate milestone Jul 17, 2017
@enebo
Copy link
Member

enebo commented Jul 17, 2017

Did a little analysis on this and talked on IRC and it looks like the issue is that ruby-lex.rb uses 'io' as a variable but it does not really work with an IO since IO has no .encoding method. It seems to use a subclass of InputMethod (which has the missing .encoding method). So my conclusion is that naming is confusing and there is no bug here; but perhaps there could be some better documentation in ruby-lex.rb

@enebo enebo closed this as completed Jul 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants