Skip to content

Commit 26ad84c

Browse files
authored
Merge pull request #8129 from enebo/arity_fix
arity for {|a,| } was -2 and should have been 1
2 parents a0507b7 + 16be728 commit 26ad84c

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

core/src/main/java/org/jruby/RubyHash.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ public RubyHash each_pairCommon(final ThreadContext context, final Block block)
16241624
public void visit(ThreadContext context, RubyHash self, IRubyObject key, IRubyObject value, int index, Block block) {
16251625
if (block.type == Block.Type.LAMBDA) {
16261626
block.call(context, context.runtime.newArray(key, value));
1627-
} else if (block.getSignature().arityValue() > 1) {
1627+
} else if (block.getSignature().isSpreadable()) {
16281628
block.yieldSpecific(context, key, value);
16291629
} else {
16301630
block.yield(context, context.runtime.newArray(key, value));

core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ public static IRubyObject[] convertValueIntoArgArray(ThreadContext context, IRub
513513
new IRubyObject[] { value };
514514
case 0:
515515
case 1:
516-
return new IRubyObject[] { value };
516+
return signature.rest() == org.jruby.runtime.Signature.Rest.ANON ?
517+
IRBlockBody.toAry(context, value) :
518+
new IRubyObject[] { value };
517519
}
518520

519521
return IRBlockBody.toAry(context, value);

core/src/main/java/org/jruby/runtime/IRBlockBody.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject
102102
}
103103

104104
private IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, Block block, IRubyObject... args) {
105-
int blockArity = signature.arityValue();
106-
if (blockArity == 1) {
105+
if (signature.isOneArgument()) {
107106
args = new IRubyObject[] { RubyArray.newArrayMayCopy(context.runtime, args) };
108107
}
109108

110109
if (canCallDirect()) return yieldDirect(context, block, args, null);
111110

112-
if (blockArity == 0) {
111+
if (signature.arityValue() == 0) {
113112
args = IRubyObject.NULL_ARRAY; // discard args
114113
}
115114
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

core/src/main/java/org/jruby/runtime/Signature.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public boolean restKwargs() {
8585
* Are there an exact (fixed) number of parameters to this signature?
8686
*/
8787
public boolean isFixed() {
88-
return arityValue() >= 0;
88+
return arityValue() >= 0 && rest != Rest.ANON;
8989
}
9090

9191
/**
@@ -135,8 +135,9 @@ public int calculateArityValue() {
135135
int oneForKeywords = requiredKwargs > 0 ? 1 : 0;
136136
int fixedValue = pre() + post() + oneForKeywords;
137137
boolean hasOptionalKeywords = kwargs - requiredKwargs > 0;
138+
boolean optionalFromRest = rest() != Rest.NONE && rest != Rest.ANON;
138139

139-
if (opt() > 0 || rest() != Rest.NONE || (hasOptionalKeywords || restKwargs()) && oneForKeywords == 0) {
140+
if (opt() > 0 || optionalFromRest || (hasOptionalKeywords || restKwargs()) && oneForKeywords == 0) {
140141
return -1 * (fixedValue + 1);
141142
}
142143

@@ -153,7 +154,7 @@ public int arityValue() {
153154
* @return true if the signature expects multiple args
154155
*/
155156
public boolean isSpreadable() {
156-
return arityValue < -1 || arityValue > 1 || (opt > 0 && !restKwargs());
157+
return arityValue < -1 || arityValue > 1 || (opt > 0 && !restKwargs()) || rest == Rest.ANON;
157158
}
158159

159160

spec/tags/ruby/core/proc/arity_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)