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

splash params lose a nesting level *only* in #_to_proc #3371

Closed
RobertDober opened this issue Oct 6, 2015 · 6 comments
Closed

splash params lose a nesting level *only* in #_to_proc #3371

RobertDober opened this issue Oct 6, 2015 · 6 comments
Milestone

Comments

@RobertDober
Copy link

@RobertDober RobertDober commented Oct 6, 2015

This concerns 9k only, worx correctly in 1.7.6

class Splash                                                                                                                                          
  def to_proc                                                                                                                                         
    -> *a do                                                                                                                                          
      a                                                                                                                                             
    end                                                                                                                                               
  end                                                                                                                                                 
end                                                                                                                                 

p [1,2].map(&Splash.new)        # --> [[1],[2]] correct
p  [[1,2]].map(&Splash.new)    # --> [[1,2]] one set of brackets missing                                                                                                            
p ->(*a){ a }.([[1,2]])                  # --> [[[1,2]]]] correct

When browsing through the issues I asked myself if this was not related to #3338?

RobertDober added a commit to RobertDober/lab42_core that referenced this issue Oct 6, 2015
@RobertDober
Copy link
Author

@RobertDober RobertDober commented Oct 6, 2015

sorry for the last comment: bad copy/paste, quite ashamed...
Sorry for the noise again

@enebo enebo added this to the JRuby 9.0.2.0 milestone Oct 7, 2015
@enebo
Copy link
Member

@enebo enebo commented Oct 7, 2015

@RobertDober anything is possible and the interactions in setting up block parameters is hairy but I do not think this is related to to_ary (or not because of to_ary). 'a' in the lambda is getting invoked and it is returning an array. If it did call to_ary it would return itself. So I think something else is wrong with our logic.

@headius
Copy link
Member

@headius headius commented Oct 8, 2015

Tom's still poking at the to_ary stuff so I'll have a look around on this one.

@headius
Copy link
Member

@headius headius commented Oct 8, 2015

Looks like this only happens when the to_proc result is a lambda. If I change it to a proc, the results match MRI and the brackets are not lost:

[] ~/projects/jruby $ cat blah.rb
class Splash                                                                                                                                          
  def to_proc                                                                                                                                         
    proc do |*a|                                                                                                                                         
      a                                                                                                                                             
    end                                                                                                                                               
  end                                                                                                                                                 
end                                                                                                                                 

p [1,2].map(&Splash.new)        # --> [[1],[2]] correct
p  [[1,2]].map(&Splash.new)    # --> [[1,2]] one set of brackets missing                                                                                                            
p ->(*a){ a }.([[1,2]])    

[] ~/projects/jruby $ jruby blah.rb
[[1], [2]]
[[[1, 2]]]
[[[1, 2]]]
@headius
Copy link
Member

@headius headius commented Oct 8, 2015

A somewhat smaller reproduction that doesn't involve map:

class X
  def to_proc
    ->(*a){ p a }
  end
end

def foo; yield [1,2]; end

foo(&(X.new)) # => [[1, 2]] on MRI, [1, 2] on JRuby
@headius headius closed this in f3dd725 Oct 8, 2015
headius added a commit that referenced this issue Oct 8, 2015
@RobertDober
Copy link
Author

@RobertDober RobertDober commented Oct 8, 2015

Great I can change the lambda to proc in my lib and release it for jruby 9k.

Thx guys.

KR
Robert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.