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

Array dereference from SimpleDelegator doesn't work in each (iterating) #2719

Closed
frvade opened this issue Sep 6, 2022 · 2 comments
Closed

Comments

@frvade
Copy link

frvade commented Sep 6, 2022

Description

Array dereference in truffleruby works with arrays, but doesn't work with wrapped delegated arrays

How to reproduce

irb(main):001:0> Desc = Class.new(SimpleDelegator)
=> Desc
irb(main):002:0> obj = Desc.new([:first, :second])
=> [:first, :second]
irb(main):003:0> [obj].each { |first, second| p first, second }
[:first, :second]
nil
=> [[:first, :second]]
irb(main):004:0> [obj].each { |(first, second)| p first, second }
:first
:second
=> [[:first, :second]]
irb(main):005:0> first, second = obj
=> [:first, :second]
irb(main):006:0> p first, second
:first
:second
irb(main):007:0> RUBY_VERSION
=> "3.0.3"
irb(main):008:0> exit
user@lima-default:/Users/user/projects/github/gruf-demo$ ruby -v
truffleruby 22.2.0, like ruby 3.0.3, GraalVM CE Native [x86_64-linux]

In MRI it would be

irb(main):001:0> Desc = Class.new(SimpleDelegator)
=> Desc
irb(main):002:0> obj = Desc.new([:first, :second])
=> [:first, :second]
irb(main):003:0> [obj].each { |first, second| p first, second }
:first
:second
=> [[:first, :second]]
irb(main):004:0> [obj].each { |(first, second)| p first, second }
:first
:second
=> [[:first, :second]]
irb(main):005:0> first, second = obj
=> [:first, :second]
irb(main):006:0> p first, second
:first
:second
irb(main):007:0> RUBY_VERSION
=> "3.0.3"
irb(main):008:0> exit
user@lima-default:/Users/user/projects/github/gruf-demo$ ruby -v
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]

The normal array dereference works as expected as well as not wrapped array in each

@eregon
Copy link
Member

eregon commented Sep 6, 2022

Thanks for the report.

A minimal repro based on that is:

require 'delegate'

Desc = Class.new(SimpleDelegator)
obj = Desc.new([:first, :second])
[obj].each { |first, second| p first, second }

puts "regular array:"
[[:first, :second]].each { |first, second| p first, second }
ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
:first
:second
regular array:
:first
:second

truffleruby 22.3.0-dev-16c74eb6, like ruby 3.0.3, Interpreted JVM [x86_64-linux]
[:first, :second]
nil
regular array:
:first
:second

@andrykonchin andrykonchin self-assigned this Sep 6, 2022
@eregon
Copy link
Member

eregon commented Nov 3, 2022

Fixed in c00d9f4

@eregon eregon closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants