Project

General

Profile

Bug #11616

Forwardable fails to adjust backtrace when Forwardable is not reachable from the target class

Added by wanabe (_ wanabe) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-10-24 trunk 52254) [x86_64-darwin15]
[ruby-core:71176]

Description

as follows:

$ cat t.rb
require "forwardable"

class Foo < BasicObject
  extend ::Forwardable

  def_delegator :bar, :baz
end

Foo.new.baz

$ ruby t.rb
/Users/guest/.rbenv/versions/trunk/lib/ruby/2.3.0/forwardable.rb:185:in `rescue in baz': uninitialized constant Foo::Forwardable (NameError)
    from /Users/guest/.rbenv/versions/trunk/lib/ruby/2.3.0/forwardable.rb:182:in `baz'
    from t.rb:9:in `<main>'

or define Forwardable in the target class:

$ cat t2.rb
require "forwardable"

class Foo
  extend Forwardable

  def_delegator :bar, :baz

  module Forwardable
  end
end

Foo.new.baz

$ ruby t2.rb
/Users/guest/.rbenv/versions/trunk/lib/ruby/2.3.0/forwardable.rb:185:in `rescue in baz': undefined method `debug' for Foo::Forwardable:Module (NoMethodError)
    from /Users/guest/.rbenv/versions/trunk/lib/ruby/2.3.0/forwardable.rb:182:in `baz'
    from t2.rb:12:in `<main>'

expected result:

$ cat t3.rb
require "forwardable"

class Foo
  extend ::Forwardable

  def_delegator :bar, :baz
end

Foo.new.baz

$ ruby t3.rb 
t3.rb:9:in `<main>': undefined local variable or method `bar' for #<Foo:0x007fff0b8db3e8> (NameError)

Also available in: Atom PDF