Project

General

Profile

Actions

Bug #791

closed

Fiber using a Proc object with a parameter having default value doesn't work

Added by Skade (Florian Gilcher) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
Backport:
[ruby-core:20088]

Description

=begin
If you pass a Proc with a default value on a parameter into a Fiber, the default value is ignored.

Example by Wolfgang NĂ¡dasi-Donner:

irb(main):001:0> p = ->(i=4){i+5}
=> #<Proc:0xe8a370@(irb):1 (lambda)>
irb(main):002:0> p[]
=> 9
irb(main):003:0> Fiber.new(&p).resume
NoMethodError: undefined method +' for nil:NilClass from (irb):1:in block (3 levels) in irb_binding'

A more useful example is...

irb(main):001:0> f = Fiber.new(&(->(i=5){loop{Fiber.yield i+=1}}))
=> #Fiber:0xe860f8
irb(main):002:0> f.resume
NoMethodError: undefined method +' for nil:NilClass from (irb):1:in block (4 levels) in irb_binding'
from (irb):1:in loop' from (irb):1:in block (3 levels) in irb_binding'

Regards,
Florian Gilcher
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0