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

Bug in else without a rescue #320

Closed
JoshCheek opened this issue Sep 27, 2016 · 0 comments
Closed

Bug in else without a rescue #320

JoshCheek opened this issue Sep 27, 2016 · 0 comments

Comments

@JoshCheek
Copy link
Collaborator

Initially opened as #304. Adding a new issue b/c it seems to have a bug in its implementation:

# Latest Parser (as of 26 Sept)
$ ruby-parse -v
ruby-parse based on parser version 2.3.1.4

This bit works fine:

# Ruby has no issue
$ ruby -e 'begin; rescue; else; p 1; end'
1


# Parser makes it a second child of `rescue`
$ ruby-parse -e 'def a; rescue; else; p 1; end; a'
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.5-compliant syntax, but you are running 2.2.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
(kwbegin
  (rescue nil
    (resbody nil nil nil)
    (send nil :p
      (int 1))))

This one has a bug, compound_stmt is nil (I'd look into it, but there's a television on and two dogs running around, so it's difficult to concentrate)

# Ruby dislikes it, but still runs it
$ ruby -e 'begin; else; p 1; end'
-e:1: warning: else without rescue is useless
1


# Parser explodes with a NoMethodError
$ ruby-parse -e 'begin; else; p 1; end'
warning: parser/current is loading parser/ruby22, which recognizes
warning: 2.2.5-compliant syntax, but you are running 2.2.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
Failed on: (fragment:0)
/Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/builders/default.rb:987:in `begin_body': undefined method `type' for nil:NilClass (NoMethodError)
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/ruby22.rb:3387:in `_reduce_9'
    from /Users/josh/.rubies/ruby-2.2.2/lib/ruby/2.2.0/racc/parser.rb:258:in `_racc_do_parse_c'
    from /Users/josh/.rubies/ruby-2.2.2/lib/ruby/2.2.0/racc/parser.rb:258:in `do_parse'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/base.rb:162:in `parse'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner/ruby_parse.rb:132:in `process'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:207:in `process_buffer'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:181:in `block in process_fragments'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:173:in `each'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:173:in `each_with_index'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:173:in `process_fragments'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:163:in `block in process_all_input'
    from /Users/josh/.rubies/ruby-2.2.2/lib/ruby/2.2.0/benchmark.rb:288:in `measure'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:162:in `process_all_input'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner/ruby_parse.rb:128:in `process_all_input'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:33:in `execute'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/lib/parser/runner.rb:11:in `go'
    from /Users/josh/.gem/ruby/2.2.2/gems/parser-2.3.1.4/bin/ruby-parse:6:in `<top (required)>'
    from /Users/josh/.gem/ruby/2.2.2/bin/ruby-parse:23:in `load'
    from /Users/josh/.gem/ruby/2.2.2/bin/ruby-parse:23:in `<main>'
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

1 participant