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

Regression: Enumerable#first on a Java list returns an array, not an element

    Details

    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      This fails on master but succeeds on 1.6:

      java.util.ArrayList.new.tap {|l| l << 'foo' }.first == 'foo' or abort
      

        Activity

        Hide
        Nick Sieger added a comment -
        Show
        Nick Sieger added a comment - git bisect says https://github.com/jruby/jruby/commit/a8850d81df57e025b68073976afb04e16a51125e is the bad commit.
        Hide
        Nick Sieger added a comment -

        Here's a regression spec if anyone wants to take this on.

        diff --git a/spec/regression/JRUBY-6341_enumerable_first_spec.rb b/spec/regression/JRUBY-6341_enumerable_first_spec.rb
        new file mode 100644
        index 0000000..62d7779
        --- /dev/null
        +++ b/spec/regression/JRUBY-6341_enumerable_first_spec.rb
        @@ -0,0 +1,16 @@
        +require 'rspec'
        +require 'java'
        +
        +describe 'JRUBY-6341' do
        +  context 'Enumerable#first behavior' do
        +    it 'returns an element, not an array' do
        +      java.util.ArrayList.new.tap {|l| l << 'foo' }.first.should == 'foo'
        +    end
        +  end
        +
        +  context 'Enumerable#first(n) behavior' do
        +    it 'returns an element, not an array' do
        +      java.util.ArrayList.new.tap {|l| l << 'foo' << 'bar' << 'baz' }.first(2).should == ['foo', 'bar']
        +    end
        +  end
        +end
        
        Show
        Nick Sieger added a comment - Here's a regression spec if anyone wants to take this on. diff --git a/spec/regression/JRUBY-6341_enumerable_first_spec.rb b/spec/regression/JRUBY-6341_enumerable_first_spec.rb new file mode 100644 index 0000000..62d7779 --- /dev/null +++ b/spec/regression/JRUBY-6341_enumerable_first_spec.rb @@ -0,0 +1,16 @@ +require 'rspec' +require 'java' + +describe 'JRUBY-6341' do + context 'Enumerable#first behavior' do + it 'returns an element, not an array' do + java.util.ArrayList.new.tap {|l| l << 'foo' }.first.should == 'foo' + end + end + + context 'Enumerable#first(n) behavior' do + it 'returns an element, not an array' do + java.util.ArrayList.new.tap {|l| l << 'foo' << 'bar' << 'baz' }.first(2).should == ['foo', 'bar'] + end + end +end
        Hide
        Nick Sieger added a comment -

        Note that java integration is not required to reproduce this either, see https://gist.github.com/1602130

        Show
        Nick Sieger added a comment - Note that java integration is not required to reproduce this either, see https://gist.github.com/1602130
        Hide
        Charles Oliver Nutter added a comment -

        Poking at it now...

        Show
        Charles Oliver Nutter added a comment - Poking at it now...
        Hide
        Nick Sieger added a comment -

        There's a temporary fix here, too: https://gist.github.com/1602285

        Show
        Nick Sieger added a comment - There's a temporary fix here, too: https://gist.github.com/1602285
        Hide
        Charles Oliver Nutter added a comment -

        Tom agreed that we should go with the temporary fix for now and let it bake on master. Recent work on 1.9 arg processing has made it clear we need to overhaul block args before 1.7 final, so this will probably get visited anyway. Making it so.

        Show
        Charles Oliver Nutter added a comment - Tom agreed that we should go with the temporary fix for now and let it bake on master. Recent work on 1.9 arg processing has made it clear we need to overhaul block args before 1.7 final, so this will probably get visited anyway. Making it so.
        Hide
        Charles Oliver Nutter added a comment -

        Fix pushed to master@02a0168.

        Show
        Charles Oliver Nutter added a comment - Fix pushed to master@02a0168.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Nick Sieger
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: