Project

General

Profile

Actions

Bug #19175

closed

Ripper does not recognize some pattern matching defining local variable

Added by tompng (tomoya ishida) almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:111161]

Description

Ripepr does not recognize hshptn and aryptn splat defining local variables.

Ripper.sexp('a in [*x]; x')
# =>
[:program,
 [[:case, [:vcall, [:@ident, "a", [1, 0]]], [:in, [:aryptn, nil, nil, [:var_field, [:@ident, "x", [1, 7]]], nil], nil, nil]],
  [:vcall, [:@ident, "x", [1, 11]]]]]

Ripper.sexp('a in {x:}; x')
# =>
[:program,                                                                  
 [[:case, [:vcall, [:@ident, "a", [1, 0]]], [:in, [:hshptn, nil, [[[:@label, "x:", [1, 6]], nil]], nil], nil, nil]],
  [:vcall, [:@ident, "x", [1, 11]]]]] 

RubyVM::AbstractSyntaxTree returns (LVAR@1:11-1:12 :x)
[:vcall, [:@ident, "x", [1, 11]]] should be [:var_ref, [:@ident, "x", [1, 11]]]

Ripper cannot parse this syntax OK code because rippter thinks local variable x is not defined.

{x:10} in {x:}; x /2 #=> 5
Ripper.sexp '{x:10} in {x:}; x /2' #=> nil

Other pattern seems to be OK.

Ripper.sexp('a in [x, y => z]; x; y; z')
# =>
[:program,
 [[:case,
   [:vcall, [:@ident, "a", [1, 0]]],
   [:in,
    [:aryptn,
     nil,
     [[:var_field, [:@ident, "x", [1, 6]]],
      [:binary, [:var_field, [:@ident, "y", [1, 9]]], :"=>", [:var_field, [:@ident, "z", [1, 14]]]]],
     nil,
     nil],
    nil,
    nil]],
  [:var_ref, [:@ident, "x", [1, 18]]],
  [:var_ref, [:@ident, "y", [1, 21]]],
  [:var_ref, [:@ident, "z", [1, 24]]]]]
Actions #1

Updated by tompng (tomoya ishida) almost 2 years ago

  • Description updated (diff)
Actions #2

Updated by ktsj (Kazuki Tsujimoto) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset git|6c0925ba7017efde6091e2ec4f1a6be268166696.


[Bug #19175] p_rest should be `assignable'

It should also check for duplicate names.

Actions #3

Updated by ktsj (Kazuki Tsujimoto) over 1 year ago

  • Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.7: WONTFIX, 3.0: WONTFIX, 3.1: WONTFIX
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0