[Ironruby-core] Code Review: arity

Tomas Matousek Tomas.Matousek at microsoft.com
Fri Oct 3 23:56:35 EDT 2008

tfpt review "/shelveset:arity;REDMOND\tomat"
Comment  :
  Fixes bugs in block parameters:
  1)    Anonymous unsplat parameters were not handled correctly (the parser ignored them):
  def y
    a = [1,2,3,4,5]
    yield a,[6]

  y { |(x,y,*),*| p x,y }
  2)    Arity wasn't calculated correctly. Arity depends upon AST structure that is not preserved in runtime. Therefore we need to calculate block arity at compile time and save it to BlockDispatcher.
  Some peculiar cases:

  Proc.new{|(a,b,c,*)|}.arity.should == -4
  Proc.new{|(*)|}.arity.should == -1
  Proc.new{}.arity.should == -1
  Proc.new{||}.arity.should == 0
  Proc.new{x,}.arity.should == 1
  Proc.new{(x,)}.arity.should == 1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: arity.diff
Type: application/octet-stream
Size: 599751 bytes
Desc: arity.diff
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20081003/ec4c7d31/attachment-0001.obj>

More information about the Ironruby-core mailing list