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

multi-level mlhs treated as single level #825

Open
hmdne opened this issue Nov 4, 2021 · 3 comments
Open

multi-level mlhs treated as single level #825

hmdne opened this issue Nov 4, 2021 · 3 comments

Comments

@hmdne
Copy link
Contributor

hmdne commented Nov 4, 2021

This bug was found in opal/opal#1703

$ ruby-parse -e '((x, y)) = [[1,2]]'
(masgn
  (mlhs             # <- shouldn't this be (mlhs (mlhs ... ))?
    (lvasgn :x)
    (lvasgn :y))
  (array
    (array
      (int 1)
      (int 2))))
$ ruby-parse -e '(x, y) = [[1,2]]'
(masgn
  (mlhs            # <- the same as above, can't differentiate
    (lvasgn :x)
    (lvasgn :y))
  (array
    (array
      (int 1)
      (int 2))))
$ ruby-parse -V
ruby-parse based on parser version 3.0.2.0
$

This also happens in all legacy modes. This works correctly for ((x,y),) and for ((x,y),z)

@iliabylich
Copy link
Collaborator

Thanks for reporting, yes, looks like a bug

3.0.0 :004 > (x, y) = [[1,2]]; [x, y]
 => [[1, 2], nil]
3.0.0 :005 > ((x, y)) = [[1,2]]; [x, y]
 => [1, 2]

@hmdne
Copy link
Contributor Author

hmdne commented Nov 4, 2021

There's another issue that I encountered and may be a similar problem:

$ ruby-parse -e 'proc { |a| }'
(block
  (send nil :proc)
  (args
    (procarg0
      (arg :a))) nil)
$ ruby-parse -e 'proc { |(a)| }'
(block
  (send nil :proc)
  (args
    (procarg0              # <- It's the same! But why?
      (arg :a))) nil)
$ ruby-parse --legacy -e 'proc { |a| }'
(block
  (send nil :proc)
  (args                      # <- In this example Opal (running in legacy mode) checks source for "," to check if procarg0
    (arg :a)) nil)
$ ruby-parse --legacy -e 'proc { |(a)| }'
(block
  (send nil :proc)
  (args                      # <- But this is denoted clearly!
    (mlhs
      (arg :a))) nil)
$

Yet:

$ ruby -e 'p proc { |i| i }.([1,2,3])'
[1, 2, 3]
$ ruby -e 'p proc { |(i)| i }.([1,2,3])'
1
$

@hmdne
Copy link
Contributor Author

hmdne commented Dec 1, 2021

Ref: #550

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