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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Show comment
Hide comment
@RobertDober

RobertDober Oct 6, 2015

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

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

This comment has been minimized.

Show comment
Hide comment
@enebo

enebo Oct 7, 2015

Member

@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.

Member

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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Oct 8, 2015

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Oct 8, 2015

Member

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]]]
Member

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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Oct 8, 2015

Member

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
Member

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
@RobertDober

This comment has been minimized.

Show comment
Hide comment
@RobertDober

RobertDober Oct 8, 2015

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

Thx guys.

KR
Robert

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