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

Incompatibility with Ruby 2.2.0 #72

Closed
wasamasa opened this issue Feb 13, 2015 · 10 comments
Closed

Incompatibility with Ruby 2.2.0 #72

wasamasa opened this issue Feb 13, 2015 · 10 comments

Comments

@wasamasa
Copy link

See also #71 for more context.

error in process filter: erm-parse: undefined method `size' for nil:NilClass: /home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:261:in `on_eol'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:400:in `on_nl'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:121:in `parse'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:121:in `block in parse'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:120:in `catch'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:120:in `parse'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:605:in `parse'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm.rb:44:in `<main>'

I get this error when using this mode with Ruby 2.2.0. Downgrading to Ruby 2.1.5 makes it go away, looks like an incompatible change. The backtrace suggests it's calling on_nl nil somewhere and therefore crashes because that should never happen.

@zenspider
Copy link
Owner

On Feb 13, 2015, at 13:25, Vasilij Schneidermann notifications@github.com wrote:

See also #71 for more context.

error in process filter: erm-parse: undefined method size' for nil:NilClass: /home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:261:inon_eol'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:400:in on_nl' /home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:121:inparse'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:121:in block in parse' /home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:120:incatch'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:120:in parse' /home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm_buffer.rb:605:inparse'
/home/wasa/.emacs.d/elpa/enh-ruby-mode-20140901.2122/ruby/erm.rb:44:in `

'

I get this error when using this mode with Ruby 2.2.0. Downgrading to Ruby 2.1.5 makes it go away, looks like an incompatible change. The backtrace suggests it's calling on_nl nil somewhere and therefore crashes because that should never happen.

Using 2.2.0 with a fresh emacs? or upgrading / switching ruby versions in the same emacs session? Try experimenting with erm-reset.

@wasamasa
Copy link
Author

Yes, this happens in a fresh Emacs instance. No, erm-reset does nothing except giving me the error again (presumably because it's not a problem with the Emacs instance).

@zenspider
Copy link
Owner

OK. Cool. It is probably unrelated to the other problem then. Can you provide a snippet to repro with?

@wasamasa
Copy link
Author

I think I've narrowed it down to a minimal example:

'a'.gsub('a', 'b')
  .gsub('b', 'c') # inline comment
  .gsub('c', 'a')

Using Ruby 2.1 I get no errors. Using Ruby 2.2 I get the earlier backtrace.

@vzvu3k6k
Copy link

Nice work 😄

Here are outputs of Ripper.lex(src) on your example in Ruby 2.1.4 and 2.2.0.

An output of Ripper.lex(src) consists of [[lineno(), column()], :on_#{event}, tok] of each token. This is diff 2.1.4.output 2.2.0.output.

16,17c16,19
<  [[1, 18], :on_period, "\n"],
<  [[2, 0], :on_ident, "  .gsub"],
---
>  [[1, 18], :on_ignored_nl, "\n"],
>  [[2, 0], :on_sp, "  "],
>  [[2, 2], :on_period, "."],
>  [[2, 3], :on_ident, "gsub"],
30c32,34
<  [[3, 0], :on_period, "  ."],
---
>  [[1, 18], :on_ignored_nl, nil],
>  [[3, 0], :on_sp, "  "],
>  [[3, 2], :on_period, "."],

In Ruby 2.2.0, on_ignored_nl (which is an alias of on_nl in erm_buffer.rb) is invoked twice at the end of the first line, and the token is nil in the second call. It is probably the reason of the crash.


This is a quick workaround for it.

diff --git a/ruby/erm_buffer.rb b/ruby/erm_buffer.rb
index b4456b4..8bbbf43 100644
--- a/ruby/erm_buffer.rb
+++ b/ruby/erm_buffer.rb
@@ -299,6 +299,12 @@ class ErmBuffer
       end
     end

+    def on_ignored_nl tok
+      unless tok.nil?
+        on_nl tok
+      end
+    end
+
     def on_kw sym # TODO: break up. 61 lines long
       sym = sym.to_sym
       case @mode
@@ -516,7 +522,6 @@ class ErmBuffer
       end
     end

-    alias on_ignored_nl on_nl
     alias on_lbracket   on_lparen
     alias on_rbracket   on_rparen
   end

@zenspider
Copy link
Owner

Awesome. I've applied your patch @vzvu3k6k. Thanks!

@gabriel-dehan
Copy link

Hello, there. Still having the issue :

error in process filter: undefined method `size' for nil:NilClass: /home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:261:in `on_eol'                                                        
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:400:in `on_nl'                                                                                                                            
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:121:in `parse'                                                                                                                            
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:121:in `block in parse'                                                                                                                   
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:120:in `catch'                                                                                                                            
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:120:in `parse'                                                                                                                            
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm_buffer.rb:605:in `parse'                                                                                                                            
/home/gaby/.emacs.d/elpa/enh-ruby-mode-20140901.1222/ruby/erm.rb:44:in `<main>'         

Around this code :

 most_recent_trip = self.trip.class # Trip                                                                                                                                                                   
      .where.not(id: self.trip.id)                                                                                                                                                                                
      .where({ user_id: self.trip.user_id }.merge(hotel_query))                                                                                                                                                   
      .order(created_at: :desc)                                                                                                                                                                                   
      .limit(1)                                                                                                                                                                                                   
      .first          

Seems to be the same problem, any idea why ?

@wasamasa
Copy link
Author

wasamasa commented Dec 2, 2015

@gabriel-dehan Your version of enh-ruby-mode seems to be too old to contain the above patch. Please update and try again.

@zenspider
Copy link
Owner

@gabriel-dehan that code works for me under ruby 2.2.2:

(set-variable (quote enh-ruby-program) "~/\.rbenv/versions/2\.2\.2/bin/ruby" nil)
(erm-reset)

seems to reparse fine

@gabriel-dehan
Copy link

@wasmasa 👍 , thank you

Repository owner locked and limited conversation to collaborators Jan 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants