Project

General

Profile

Actions

Backport #8686

closed

Calling define_singleton_method on an "extended self" module raises TypeError: compared with non class/module

Added by krieghan (Krieghan Riley) over 11 years ago. Updated over 11 years ago.


Description

The following code, issued through rake console, works fine on ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0],
but fails on ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2].

module A
extend self

def a
return "a"
end
end

def b
return "b"
end

a = A.method(:a)
A.define_singleton_method(:a, method(:b))
A.define_singleton_method(:a, a)

On ruby 2.0, the last line raises the following exception:

TypeError: compared with non class/module
from (irb):15:in define_singleton_method' from (irb):15 from ./Rakefile:17:in block in <top (required)>'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in call' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in block in execute'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in each' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in execute'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in block in invoke_with_call_chain' from ~/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in mon_synchronize'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in invoke_with_call_chain' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in invoke'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in invoke_task' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in block (2 levels) in top_level'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in each' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in block in top_level'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in run_with_threads' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in top_level'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in block in run' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in standard_exception_handling'
from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in run' from ./vendor/bundler/ruby/2.0.0/gems/rake-10.1.0/bin/rake:33:in <top (required)>'
from ./vendor/bundler/ruby/2.0.0/bin/rake:23:in load' from ./vendor/bundler/ruby/2.0.0/bin/rake:23:in '2.0.0 :016 >

The result that I expect is that the original method "a" should be replaced back on the module (and in 1.9.3, that is exactly what happens).

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED
Actions #2

Updated by Anonymous over 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42380.
Krieghan, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • object.c (rb_class_inherited_p): allow iclasses to be tested for
    inheritance. [Bug #8686] [ruby-core:56174]

  • test/ruby/test_method.rb: add test

Actions #3

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport200
  • Status changed from Closed to Assigned
  • Assignee set to nagachika (Tomoyuki Chikanaga)
Actions #4

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r42914.
Krieghan, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 40021,42380: [Backport #8686]

test_method.rb: split

* test/ruby/test_method.rb (test_define_method): split for each tests.
* object.c (rb_class_inherited_p): allow iclasses to be tested for
  inheritance. [Bug #8686] [ruby-core:56174]

* test/ruby/test_method.rb: add test
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0