@@ -55,6 +55,7 @@ public final class Arity implements Serializable {
5555 public final static Arity ONE_REQUIRED = newArity (-2 );
5656 public final static Arity TWO_REQUIRED = newArity (-3 );
5757 public final static Arity THREE_REQUIRED = newArity (-4 );
58+ public final static int UNLIMITED_ARGUMENTS = -1 ;
5859
5960 private Arity (int value ) {
6061 this .value = value ;
@@ -163,11 +164,11 @@ public void checkArity(Ruby runtime, IRubyObject[] args) {
163164 public void checkArity (Ruby runtime , int length ) {
164165 if (isFixed ()) {
165166 if (length != required ()) {
166- throw runtime .newArgumentError ("wrong number of arguments (" + length + " for " + required () + ")" );
167+ throw runtime .newArgumentError (length , required ());
167168 }
168169 } else {
169170 if (length < required ()) {
170- throw runtime .newArgumentError ("wrong number of arguments (" + length + " for " + required () + ")" );
171+ throw runtime .newArgumentError (length , required ());
171172 }
172173 }
173174 }
@@ -250,43 +251,42 @@ public static void raiseArgumentError(Ruby runtime, IRubyObject[] args, int min,
250251
251252 // FIXME: JRuby 2/next should change this name since it only sometimes raises an error
252253 public static void raiseArgumentError (Ruby runtime , int length , int min , int max ) {
253- if (length < min ) throw runtime . newArgumentError ( length , min );
254- if ( max > - 1 && length > max ) throw runtime .newArgumentError (length , max );
254+ if (length < min || ( max > UNLIMITED_ARGUMENTS && length > max ))
255+ throw runtime .newArgumentError (length , min , max );
255256 }
256257
257258 // FIXME: JRuby 2/next should change this name since it only sometimes raises an error
258259 public static void raiseArgumentError (ThreadContext context , int length , int min , int max ) {
259- if (length < min ) throw context .runtime .newArgumentError (length , min );
260- if (max > -1 && length > max ) throw context .runtime .newArgumentError (length , max );
260+ raiseArgumentError (context .runtime , length , min , max );
261261 }
262262
263263 // FIXME: JRuby 2/next should change this name since it only sometimes raises an error
264264 public static void raiseArgumentError (Ruby runtime , int length , int min , int max , boolean hasKwargs ) {
265- if (length < min ) throw runtime .newArgumentError (length , min );
266- if (max > - 1 && length > max ) {
265+ if (length < min ) throw runtime .newArgumentError (length , min , max );
266+ if (max > UNLIMITED_ARGUMENTS && length > max ) {
267267 if (hasKwargs && length == max + 1 ) {
268268 // we have an extra arg, but kwargs active; let it fall through to assignment
269269 return ;
270270 }
271- throw runtime .newArgumentError (length , max );
271+ throw runtime .newArgumentError (length , min , max );
272272 }
273273 }
274274
275275 // FIXME: JRuby 2/next should change this name since it only sometimes raises an error
276276 public static void raiseArgumentError (Ruby runtime , String name , int length , int min , int max ) {
277- if (length < min ) throw runtime . newArgumentError ( name , length , min );
278- if ( max > - 1 && length > max ) throw runtime .newArgumentError (name , length , max );
277+ if (length < min || ( max > UNLIMITED_ARGUMENTS && length > max ))
278+ throw runtime .newArgumentError (name , length , min , max );
279279 }
280280
281281 // FIXME: JRuby 2/next should change this name since it only sometimes raises an error
282282 public static void raiseArgumentError (Ruby runtime , String name , int length , int min , int max , boolean hasKwargs ) {
283- if (length < min ) throw runtime .newArgumentError (name , length , min );
284- if (max > - 1 && length > max ) {
283+ if (length < min ) throw runtime .newArgumentError (name , length , min , max );
284+ if (max > UNLIMITED_ARGUMENTS && length > max ) {
285285 if (hasKwargs && length == max + 1 ) {
286286 // we have an extra arg, but kwargs active; let it fall through to assignment
287287 return ;
288288 }
289- throw runtime .newArgumentError (name , length , max );
289+ throw runtime .newArgumentError (name , length , min , max );
290290 }
291291 }
292292
0 commit comments