JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-6568

A Proc on a symbol like (&:first) works in 1.8, but not in 1.9 mode

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.7
    • Fix Version/s: JRuby 1.7.0.RC1
    • Component/s: Ruby 1.9.2
    • Labels:
      None
    • Environment:
      Ubuntu 10.11 - x64
    • Number of attachments :
      0

      Description

      The following code fragment should show it clearly.

      me@mypc:~/$ cat test.rb 
      class Array
        def proc_on_first
          yield([0])
        end
      end
      
      ary = [[42]]
      
      p ary.proc_on_first{|b|b.first}
      p ary.proc_on_first(&:first)
      
      me@mypc:~/$ jruby --1.9 test.rb 
      0
      NoMethodError: undefined method `first' for 0:Fixnum
        proc_on_first at test.rb:3
               (root) at test.rb:10
      me@mypc:~/$ jruby --1.8 test.rb 
      0
      0
      me@mypc:~/$
      

      There are severeal issues concerning Procs, Symbols and &, but I couldn't find one that shows this behaviour.
      In MRI Ruby 1.9.2 and 1.9.3 this works fine like in JRuby --1.8

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Ahh, seems like a good find. It looks like we're unboxing too much in the 1.9 case, which has been a common challenge for 1.9 mode block argument passing.

        Show
        Charles Oliver Nutter added a comment - Ahh, seems like a good find. It looks like we're unboxing too much in the 1.9 case, which has been a common challenge for 1.9 mode block argument passing.
        Hide
        Charles Oliver Nutter added a comment -

        Still broken as of today on master.

        Show
        Charles Oliver Nutter added a comment - Still broken as of today on master.
        Hide
        Charles Oliver Nutter added a comment -
        commit a964aa436ce6d4321af75c445e24219ee397e037
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Fri Sep 7 13:34:43 2012 -0500
        
            Fix JRUBY-6568
            
            A Proc on a symbol like (&:first) works in 1.8, but not in 1.9 mode
            
            In 1.9 mode, we do a better job of yielding the *actual* argument
            given ([0] in this case) rather than always doing the extraneous
            boxing that 1.8 mode does. However, we did not implement those
            yieldSpecific paths in the Symbol#to_proc proc, so they fell back
            on the old 1.8 logic that did arg list unwrapping. Implementing
            the specific paths appears to make 1.9 mode yield to procified
            Symbols properly.
        
        :000000 100644 0000000... 355da5b... A	spec/regression/JRUBY-6568_procified_Symbol_unwraps_too_much_spec.rb
        :100644 100644 d727192... 3614711... M	src/org/jruby/RubySymbol.java
        
        Show
        Charles Oliver Nutter added a comment - commit a964aa436ce6d4321af75c445e24219ee397e037 Author: Charles Oliver Nutter <headius@headius.com> Date: Fri Sep 7 13:34:43 2012 -0500 Fix JRUBY-6568 A Proc on a symbol like (&:first) works in 1.8, but not in 1.9 mode In 1.9 mode, we do a better job of yielding the *actual* argument given ([0] in this case) rather than always doing the extraneous boxing that 1.8 mode does. However, we did not implement those yieldSpecific paths in the Symbol#to_proc proc, so they fell back on the old 1.8 logic that did arg list unwrapping. Implementing the specific paths appears to make 1.9 mode yield to procified Symbols properly. :000000 100644 0000000... 355da5b... A spec/regression/JRUBY-6568_procified_Symbol_unwraps_too_much_spec.rb :100644 100644 d727192... 3614711... M src/org/jruby/RubySymbol.java
        Hide
        Heiko Seebach added a comment -

        very good, Charlie, thank you very much for all those years of making JRuby the best Ruby environment!

        Show
        Heiko Seebach added a comment - very good, Charlie, thank you very much for all those years of making JRuby the best Ruby environment!

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Heiko Seebach
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: