Bugs item #6348, was opened at 2006-10-27 00:15
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=6348&group_id=426

Category: Core
Group: 1.8.x
Status: Open
Resolution: None
Priority: 3
Submitted By: Riley Lynch (rlynch)
Assigned to: Nobody (None)
Summary: blocks with arity of 1 behave inconsistently when passed more or less parameters

Initial Comment:
In general, blocks defined with lambda raise ArgumentError when called with fewer than the required number of arguments (or more than the specified number when arity >= 0). Blocks defined with Proc.new do not raise an error or warn in this case. This behavior is as documented.

BUT: Blocks with an arity of 1 defined by lambda do not raise ArgumentError: They print a warning. Blocks with an arity of 1 defined by Proc.new also print a warning. I assume this inconsistency is a bug.

I have attached an RSpec specification which generates this output:

ruby 1.8.4 (2005-12-24) [i686-darwin8.7.1]

a block defined with lambda
- raises when passed an argument for arity 0
- warns when passed no argument for arity 1 (bug?)
- warns when passed 2 arguments for arity 1 (bug?)
- raises when passed 1 argument for arity 2
- raises when passed 3 arguments for arity 2
- raises when passed no arguments for arity -2
- raises when passed 1 argument for arity -3

a block defined with Proc.new
- should not raise or warn when passed 1 argument for arity 0
- warns when passed no arguments for arity 1 (bug?)
- warns when passed 2 arguments for arity 1 (bug?)
- should not raise or warn when passed 1 argument for arity 2
- should not raise or warn when passed 3 arguments for arity 2
- should not raise or warn when passed no arguments for arity -2
- should not raise or warn when passed 1 argument for arity -3

Jruby does not exhibit this questionable behavior, passing the specification with STRICT_BEHAVIOR=true.

ruby 1.8.5 (0) [java]

a block defined with lambda
- raises when passed an argument for arity 0
- raises when passed no arguments for arity 1
- raises when passed 2 arguments for arity 1
- raises when passed 1 argument for arity 2
- raises when passed 3 arguments for arity 2
- raises when passed no arguments for arity -2
- raises when passed 1 argument for arity -3

a block defined with Proc.new
- should not raise or warn when passed 1 argument for arity 0
- should not warn when passed no arguments for arity 1
- should not warn when passed 2 arguments for arity 1
- should not raise or warn when passed 1 argument for arity 2
- should not raise or warn when passed 3 arguments for arity 2
- should not raise or warn when passed no arguments for arity -2
- should not raise or warn when passed 1 argument for arity -3

I was not able to test this with ruby 1.9 because I was not able to run RSpec under ruby 1.9. (I didn't try very hard!)


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=6348&group_id=426