Project

General

Profile

Actions

Bug #17509

closed

Custom respond_to? methods in modules break defined?(super)

Added by benediktdeicke (Benedikt Deicke) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
[ruby-core:101912]

Description

When using defined?(super) to check that a superclass method exists before calling super, including modules with a custom respond_to? method seems to break the check so it wrongfully returns a truthy value, even though the superclass method doesn't exist.

This only happens on Ruby 3.0.0 and works fine on previous Ruby versions. This is possibly related to this change: https://github.com/ruby/ruby/pull/3777

Example

module SomeModule
  def a_method
    defined?(super) ? super : :no_super_method
  end
end

module RespondModule
  def respond_to?(*)
    super
  end
end

class PlainClass
  include SomeModule
end

class ModuleClass
  include RespondModule
  include SomeModule
end

puts "PlainClass: #{PlainClass.new.a_method}"
puts "ModuleClass: #{ModuleClass.new.a_method}"

Actual Result on Ruby 3.0.0p0

PlainClass: no_super_method
test.rb:3:in `a_method': super: no superclass method `a_method' for #<ModuleClass:0x00007fd77383f908> (NoMethodError)
Did you mean?  method
	from test.rb:24:in `<main>'

Expected Result (like on older versions)

PlainClass: no_super_method
ModuleClass: no_super_method

Thanks to Rafael França for helping me unravel this.


Files

test.rb (359 Bytes) test.rb Example script to reproduce the problem benediktdeicke (Benedikt Deicke), 01/04/2021 02:48 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #11213: defined?(super) ignores respond_to_missing?Closedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Description updated (diff)
Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Related to Bug #11213: defined?(super) ignores respond_to_missing? added
Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONTNEED, 3.0: REQUIRED
Actions #4

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|85b5d4c8bf4cdcba4f1af65f2bc0c8ac716cb795.


Revert "[Bug #11213] let defined?(super) call respond_to_missing?"

This reverts commit fac2498e0299f13dffe4f09a7dd7657fb49bf643 for
now, due to [Bug #17509], the breakage in the case super is
called in respond_to?.

Updated by naruse (Yui NARUSE) almost 4 years ago

  • Backport changed from 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONTNEED, 3.0: REQUIRED to 2.5: DONTNEED, 2.6: DONTNEED, 2.7: DONTNEED, 3.0: DONE

ruby_3_0 147453ad1e85bc94506c269e363e736675946908 merged revision(s) 85b5d4c8bf4cdcba4f1af65f2bc0c8ac716cb795.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0