Bug #6644

Weird behavior of defined?(super) check invoked from a metaprogrammatically defined class method

Added by Alexey Smolianinov almost 2 years ago. Updated almost 2 years ago.

[ruby-core:45831]
Status:Closed
Priority:Normal
Assignee:-
Category:core
Target version:2.0.0
ruby -v:ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux] Backport:

Description

=begin
Lately I came across some weird behavior with the (({defined?})) operator used to check if (({super})) keyword can be invoked in current context. Usually it works fine, but when I tried to combine the (({defined? super})) check with a tiny bit of metaprogramming, it gave me unexpected results.

Here's an example:

class A;
def self.deff!;
singleton
class.send(:define_method, :f) { defined? super }
end
end
class AA < A; end

A.def_f!

A.f # => nil
AA.f # => nil

AA.def_f!

AA.f # => "super"
A.f # => "super" - WHY???

The last result is really strange, isn't it?

A.f has no super method, so I would expect the last (({A.f})) to return (({nil})).
Is it a bug?

=end


Related issues

Related to Backport200 - Backport #8367: regression in defined?(super) starting with 2.0.0-p0 Closed 05/04/2013
Duplicated by ruby-trunk - Bug #6722: Weird behavior of defined?(super) check invoked from a me... Closed 07/11/2012

Associated revisions

Revision 36369
Added by Nobuyoshi Nakada almost 2 years ago

defined: me in cfp

  • insns.def (defined): use method entry and id in cfp for proper superclass, since klass in iseq is shared by dynamically defined methods from the same block. [Bug #6644]

History

#1 Updated by Alexey Smolianinov almost 2 years ago

Hello? Is anyone here? :)

#2 Updated by Nobuyoshi Nakada almost 2 years ago

  • Category set to core
  • Target version changed from 1.9.3 to 2.0.0

#3 Updated by Nobuyoshi Nakada almost 2 years ago

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

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


defined: me in cfp

  • insns.def (defined): use method entry and id in cfp for proper superclass, since klass in iseq is shared by dynamically defined methods from the same block. [Bug #6644]

Also available in: Atom PDF