whitequark / parser

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

`Prism::Translation::Parser` incompatibility AST for modifier `rescue` around parallel assignment #997

Closed koic closed 9 months ago

koic commented 9 months ago

Incompatibility AST for modifier rescue around parallel assignment between Parser gem and Prism:

a, b = 1, 2 rescue nil

Expected Behavior

This is an AST starting from masgn:

$ ruby -rparser/ruby33 -ve 'p Parser::Ruby33.parse("a, b = 1, 2 rescue nil")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:masgn,
  s(:mlhs,
    s(:lvasgn, :a),
    s(:lvasgn, :b)),
  s(:rescue,
    s(:array,
      s(:int, 1),
      s(:int, 2)),
    s(:resbody, nil, nil,
      s(:nil)), nil))

Actual Behavior

This is an AST starting from rescue:

$ ruby -rprism -rprism/translation/parser -ve 'p Prism::Translation::Parser.parse("a, b = 1, 2 rescue nil")'
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin22]
s(:rescue,
  s(:masgn,
    s(:mlhs,
      s(:lvasgn, :a),
      s(:lvasgn, :b)),
    s(:array,
      s(:int, 1),
      s(:int, 2))),
  s(:resbody, nil, nil,
    s(:nil)), nil)

Background

Found due to incompatibility with RuboCop's Style/RescueModifier cop.

koic commented 9 months ago

I apologize. I reported to the wrong place.