( Proc.new {} ).arity incorrect ( == -1, should be 0)
-----------------------------------------------------

                 Key: JRUBY-5625
                 URL: http://jira.codehaus.org/browse/JRUBY-5625
             Project: JRuby
          Issue Type: Bug
    Affects Versions: JRuby 1.6, JRuby 1.5.1
         Environment: windows (7 in particular)
Jruby 1.6.0 & 1.5.1 (id'd issue in 1.5.1; just confirmed in 1.6.0 today)
            Reporter: michael william buda
            Assignee: Thomas E Enebo
            Priority: Minor


proc.arity does not work correctly for zero argument procs; it returns -1 
instead of 0.

per ruby documentation (http://ruby-doc.org/core-1.8.7/):
"""
Returns the number of arguments that would not be ignored. If the block is 
declared to take no arguments, returns 0. If the block is known to take exactly 
n arguments, returns n. If the block has optional arguments, return -n-1, where 
n is the number of mandatory arguments. A proc with no argument declarations is 
the same a block declaring || as its arguments.

   Proc.new {}.arity          #=>  0
   Proc.new {||}.arity        #=>  0
   Proc.new {|a|}.arity       #=>  1
   Proc.new {|a,b|}.arity     #=>  2
   Proc.new {|a,b,c|}.arity   #=>  3
   Proc.new {|*a|}.arity      #=> -1
   Proc.new {|a,*b|}.arity    #=> -2
"""

problem DOES NOT occur if you provide the argument bars (so Proc.new {||} 
instead of Proc.new{} )

also: refer to issue 3706; which seems to be a resolved duplicate for Method 
objects

marking as minor; since there multiple workarounds (live with -1 when checking 
arity, or always provide ||'s)

//
//test cases (as method):
//
def test_proc_arity()
 p01 = (Proc.new {}      ).arity ==  0  #returns false in 1.6.0; 1.5.1
 p02 = (Proc.new {||}    ).arity ==  0  #returns true in 1.6.0; 1.5.1
 p03 = (Proc.new {|*xs|} ).arity == -1  #returns true in 1.6.0; 1.5.1
 ( p01 and p02 and p03 )
end


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to