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: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: JRuby 1.6.6, JRuby 1.7.0.pre1
    • Fix Version/s: None
    • Component/s: Ruby 1.9.3, RubySpec
    • Labels:
      None
    • Environment:
      export JRUBY_OPTS=--1.9
    • Number of attachments :
      0

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

        Activity

        Hide
        Martin Harriman added a comment -

        In jruby, qs gets [[1, 2, 3], [4, 5, 6]].

        Show
        Martin Harriman added a comment - In jruby, qs gets [ [1, 2, 3] , [4, 5, 6] ].
        Hide
        Hiro Asari added a comment -
        1)
        The for expression yields only as many values as there are arguments FAILED
        Expected [[1, 2, 3], [4, 5, 6]]
         to equal [1, 4]
        
        /Users/asari/Development/src/jruby/spec/ruby/language/for_spec.rb:99:in `(root)'
        org/jruby/RubyBasicObject.java:1753:in `instance_eval'
        org/jruby/RubyEnumerable.java:1313:in `all?'
        org/jruby/RubyArray.java:1596:in `each'
        /Users/asari/Development/src/jruby/spec/ruby/language/for_spec.rb:6:in `(root)'
        org/jruby/RubyKernel.java:996:in `load'
        /Users/asari/Development/src/jruby/spec/ruby/language/for_spec.rb:56:in `files'
        org/jruby/RubyBasicObject.java:1753:in `instance_eval'
        org/jruby/RubyArray.java:1596:in `each'
        
        Show
        Hiro Asari added a comment - 1) The for expression yields only as many values as there are arguments FAILED Expected [[1, 2, 3], [4, 5, 6]] to equal [1, 4] /Users/asari/Development/src/jruby/spec/ruby/language/for_spec.rb:99:in `(root)' org/jruby/RubyBasicObject.java:1753:in `instance_eval' org/jruby/RubyEnumerable.java:1313:in `all?' org/jruby/RubyArray.java:1596:in `each' /Users/asari/Development/src/jruby/spec/ruby/language/for_spec.rb:6:in `(root)' org/jruby/RubyKernel.java:996:in `load' /Users/asari/Development/src/jruby/spec/ruby/language/for_spec.rb:56:in `files' org/jruby/RubyBasicObject.java:1753:in `instance_eval' org/jruby/RubyArray.java:1596:in `each'
        Hide
        Charles Oliver Nutter added a comment -

        This is likely another bug that will be fixed by argument-splatting improvements intended to go into 1.6.6.

        Show
        Charles Oliver Nutter added a comment - This is likely another bug that will be fixed by argument-splatting improvements intended to go into 1.6.6.
        Hide
        Charles Oliver Nutter added a comment -

        Still broken in 1.6.6. Investigating a bit today. Likely specific to the "for" logic.

        Show
        Charles Oliver Nutter added a comment - Still broken in 1.6.6. Investigating a bit today. Likely specific to the "for" logic.
        Hide
        Charles Oliver Nutter added a comment -

        Does not work with each either. Seems to be some case we missed?

        Show
        Charles Oliver Nutter added a comment - Does not work with each either. Seems to be some case we missed?
        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]

          People

          • Assignee:
            Thomas E Enebo
            Reporter:
            Martin Harriman
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: