Forum: Ruby-core [ruby-trunk - Bug #8686][Open] Calling define_singleton_method on an "extended self" module raises T

D4b05ef42d1c28f6dad24cdb9b2fb337?d=identicon&s=25 krieghan (Krieghan Riley) (Guest)
on 2013-07-25 19:06
(Received via mailing list)
Issue #8686 has been reported by krieghan (Krieghan Riley).

----------------------------------------
Bug #8686: Calling define_singleton_method on an "extended self" module
raises TypeError: compared with non class/module
https://bugs.ruby-lang.org/issues/8686

Author: krieghan (Krieghan Riley)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674)
[x86_64-darwin11.4.2]
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


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 `<main>'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).
5cf8f058a4c094bb708174fb43e7a387?d=identicon&s=25 nagachika (Tomoyuki Chikanaga) (Guest)
on 2013-08-02 17:43
(Received via mailing list)
Issue #8686 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED,
2.0.0: REQUIRED


----------------------------------------
Bug #8686: Calling define_singleton_method on an "extended self" module
raises TypeError: compared with non class/module
https://bugs.ruby-lang.org/issues/8686#change-40835

Author: krieghan (Krieghan Riley)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 2.0.0p247 (2013-06-27 revision 41674)
[x86_64-darwin11.4.2]
Backport: 1.9.3: DONTNEED, 2.0.0: REQUIRED


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 `<main>'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).
This topic is locked and can not be replied to.