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

[1.9] [RubySpec] In 1.9 mode, for should yield only as many values as there are arguments

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.6, JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 9000
    • Component/s: Ruby 1.9.3, RubySpec
    • Labels:
      None
    • Environment:
      export JRUBY_OPTS=--1.9
    • Number of attachments :
      2

      Description

      In MRI 1.9.2:

            class OFor
              def each
                [[1,2,3], [4,5,6]].each do |a|
                  yield(a[0],a[1],a[2])
                end
              end
            end
            o = OFor.new
            qs = []
            for q in o
              qs << q
            end
      

      This snippet comes from rubyspec/language/for_spec.rb; in MRI 1.9.2, qs gets [1, 4].

      1. output.log
        1.0 kB
        Richard Nienaber
      2. test.rb
        0.2 kB
        Richard Nienaber

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Oops, I was mistaken...not running in 1.9 mode. It does only fail with "for".

        Show
        Charles Oliver Nutter added a comment - Oops, I was mistaken...not running in 1.9 mode. It does only fail with "for".
        Hide
        Charles Oliver Nutter added a comment -

        Ok, here's the deal. We separate logic for 1.9 versus 1.8 blocks, but we don't do the same for `for` loops. It shouldn't be hard to do that, but we need the parser to do the right thing here. I'll talk to Tom today about getting parser help, and this should make 1.6.7.

        Show
        Charles Oliver Nutter added a comment - Ok, here's the deal. We separate logic for 1.9 versus 1.8 blocks, but we don't do the same for `for` loops. It shouldn't be hard to do that, but we need the parser to do the right thing here. I'll talk to Tom today about getting parser help, and this should make 1.6.7.
        Hide
        Thomas E Enebo added a comment -

        It sucks to punt this to 1.7.0, but the underlying issue is ForBlock is written in terms of the production lhs and mlhs which are written in *AsgnNode. Our 1.9 block implementation and compiler are written around them being wrapped in an ArgsNode and being ArgumentNodes. Massive changes are needed to make this work, so I don't think we should attempt this late into the 1.6.x cycle. High priority for 1.7.0 though.

        If at all possible please rewrite your code to use 'each' instead of 'for'.

        Show
        Thomas E Enebo added a comment - It sucks to punt this to 1.7.0, but the underlying issue is ForBlock is written in terms of the production lhs and mlhs which are written in *AsgnNode. Our 1.9 block implementation and compiler are written around them being wrapped in an ArgsNode and being ArgumentNodes. Massive changes are needed to make this work, so I don't think we should attempt this late into the 1.6.x cycle. High priority for 1.7.0 though. If at all possible please rewrite your code to use 'each' instead of 'for'.
        Hide
        Charles Oliver Nutter added a comment -

        Still broken for 1.7.0. Bumping to 1.7.1.

        system ~/projects/jruby $ jruby test.rb
        test.rb:5 warning: multiple values for a block parameter (3 for 1)
        test.rb:5 warning: multiple values for a block parameter (3 for 1)
        [[1, 2, 3], [4, 5, 6]]
        
        system ~/projects/jruby $ jruby -X-C test.rb
        [[1, 2, 3], [4, 5, 6]]
        
        system ~/projects/jruby $ jruby -X-CIR test.rb
        [1, 4]
        
        Show
        Charles Oliver Nutter added a comment - Still broken for 1.7.0. Bumping to 1.7.1. system ~/projects/jruby $ jruby test.rb test.rb:5 warning: multiple values for a block parameter (3 for 1) test.rb:5 warning: multiple values for a block parameter (3 for 1) [[1, 2, 3], [4, 5, 6]] system ~/projects/jruby $ jruby -X-C test.rb [[1, 2, 3], [4, 5, 6]] system ~/projects/jruby $ jruby -X-CIR test.rb [1, 4]
        Hide
        Richard Nienaber added a comment -

        This still seems to be failing in JRuby 1.7.18 but passing in JRuby HEAD (c1be61a). I've attached the test code and output.log.

        Show
        Richard Nienaber added a comment - This still seems to be failing in JRuby 1.7.18 but passing in JRuby HEAD (c1be61a). I've attached the test code and output.log.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Martin Harriman

            Dates

            • Created:
              Updated:
              Resolved: