Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 53748e3da09c
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 20499fbbb490
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 16, 2017

  1. Fixes #4706. TypeError: debugging with --debug

    This is really about fixing:
    ```ruby
    @t = [[1, 2], [3, 4]]
    for th, in @t
       p th
    end
    ```
    
    which stdlib debug happens to use (notice the extra ,).  Spec commit coming
    after this one.
    enebo committed Aug 16, 2017
    Copy the full SHA
    c3a1d6c View commit details
  2. Copy the full SHA
    20499fb View commit details
Showing with 15 additions and 7 deletions.
  1. +9 −7 core/src/main/java/org/jruby/runtime/Signature.java
  2. +6 −0 spec/ruby/language/for_spec.rb
16 changes: 9 additions & 7 deletions core/src/main/java/org/jruby/runtime/Signature.java
Original file line number Diff line number Diff line change
@@ -208,13 +208,15 @@ public static Signature from(ForNode iter) {
// ForNode can aggregate either a single node (required = 1) or masgn
if (var instanceof MultipleAsgnNode) {
MultipleAsgnNode masgn = (MultipleAsgnNode)var;

Rest rest = Rest.NONE;
if (masgn.getRest() != null) {
Node restArg = masgn.getRest();
rest = restFromArg(restArg);
}
return Signature.from(masgn.getPreCount(), 0, masgn.getPostCount(), 0, 0, rest, -1);
Rest rest = masgn.getRest() == null ? Rest.NONE : restFromArg(masgn.getRest());

// 'for' can only have rest and pre args (no post or opt). If var is a masgn then it is either
// n > 1 args, it includes rest, or it is a special case (for th, in @bleh). In this last case,
// we need to increase the arg count by one so our iter arg passing code will destructure the
// incoming args array and not just pass it through as a single value.
int argCount = masgn.getPreCount();
if (rest == Rest.NONE && argCount == 1) argCount = 2;
return Signature.from(argCount, 0, 0, 0, 0, rest, -1);
}
return Signature.ONE_ARGUMENT;
}
6 changes: 6 additions & 0 deletions spec/ruby/language/for_spec.rb
Original file line number Diff line number Diff line change
@@ -12,6 +12,12 @@
j.should == 6
end

it "iterates over a list of arrays and destructures with empty comma" do
for i, in [[1,2]]
i.should == 1
end
end

it "iterates over an Hash passing each key-value pair to the block" do
k = 0
l = 0