Project

General

Profile

Actions

Bug #10753

closed

Refined class returns unexpected value when call public_method_defined?, protected_method_defined?, private_method_defined?

Added by hanachin (Seiei Miyagi) over 9 years ago. Updated about 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-01-18 trunk 49312) [x86_64-darwin14]
[ruby-core:67656]

Description

When I call public_method_defined? or protected_method_defined? or private_method_defined? methods of the class,
the result is not expected if the method is refined.

i confirmed with following example programs in ruby-trunk, 2.0.0-p598, 2.1.5, 2.2.0

examples

bug_refined_method_defined.rb

c = Class.new do
  def refined_public; end
  def refined_protected; end
  def refined_private; end

  public :refined_public
  protected :refined_protected
  private :refined_private
end

m = Module.new do
  refine(c) do
    def refined_public; end
    def refined_protected; end
    def refined_private; end

    public :refined_public
    protected :refined_protected
    private :refined_private
  end
end

using m

predicate_methods = %i(
  method_defined?
  public_method_defined?
  protected_method_defined?
  private_method_defined?
)

methods = %i(
  refined_public
  refined_protected
  refined_private
)
predicate_methods.each do |predicate_method|
  puts predicate_method
  puts '-' * 8
  methods.each do |method|
    puts "#{predicate_method}(#{method}) # => #{c.send(predicate_method, method)}"
  end
  puts
end

expected:

$ ./ruby --disable-gems bug_refined_method_defined.rb
method_defined?
--------
method_defined?(refined_public) # => true
method_defined?(refined_protected) # => true
method_defined?(refined_private) # => false

public_method_defined?
--------
public_method_defined?(refined_public) # => true
public_method_defined?(refined_protected) # => false
public_method_defined?(refined_private) # => false

protected_method_defined?
--------
protected_method_defined?(refined_public) # => false
protected_method_defined?(refined_protected) # => true
protected_method_defined?(refined_private) # => false

private_method_defined?
--------
private_method_defined?(refined_public) # => false
private_method_defined?(refined_protected) # => false
private_method_defined?(refined_private) # => true

actual:

$ ./ruby --disable-gems bug_refined_method_defined.rb
method_defined?
--------
method_defined?(refined_public) # => true
method_defined?(refined_protected) # => true
method_defined?(refined_private) # => false

public_method_defined?
--------
public_method_defined?(refined_public) # => true
public_method_defined?(refined_protected) # => true
public_method_defined?(refined_private) # => true

protected_method_defined?
--------
protected_method_defined?(refined_public) # => false
protected_method_defined?(refined_protected) # => false
protected_method_defined?(refined_private) # => false

private_method_defined?
--------
private_method_defined?(refined_public) # => false
private_method_defined?(refined_protected) # => false
private_method_defined?(refined_private) # => false

bug_undefined_refined_method_defined.rb

c = Class.new
m = Module.new do
  refine(c) do
    def undefined_refined_public; end
    def undefined_refined_protected; end
    def undefined_refined_private; end
    public :undefined_refined_public
    protected :undefined_refined_protected
    private :undefined_refined_private
  end
end

using m

predicate_methods = %i(
  method_defined?
  public_method_defined?
  protected_method_defined?
  private_method_defined?
)

methods = %i(
  undefined_refined_public
  undefined_refined_protected
  undefined_refined_private
)
predicate_methods.each do |predicate_method|
  puts predicate_method
  puts '-' * 8
  methods.each do |method|
    puts "#{predicate_method}(#{method}) # => #{c.send(predicate_method, method)}"
  end
  puts
end

expected:

$ ./ruby --disable-gems bug_undefined_refined_method_defined.rb
method_defined?
--------
method_defined?(undefined_refined_public) # => false
method_defined?(undefined_refined_protected) # => false
method_defined?(undefined_refined_private) # => false

public_method_defined?
--------
public_method_defined?(undefined_refined_public) # => false
public_method_defined?(undefined_refined_protected) # => false
public_method_defined?(undefined_refined_private) # => false

protected_method_defined?
--------
protected_method_defined?(undefined_refined_public) # => false
protected_method_defined?(undefined_refined_protected) # => false
protected_method_defined?(undefined_refined_private) # => false

private_method_defined?
--------
private_method_defined?(undefined_refined_public) # => false
private_method_defined?(undefined_refined_protected) # => false
private_method_defined?(undefined_refined_private) # => false

actual:

$ ./ruby --disable-gems bug_undefined_refined_method_defined.rb
method_defined?
--------
method_defined?(undefined_refined_public) # => false
method_defined?(undefined_refined_protected) # => false
method_defined?(undefined_refined_private) # => false

public_method_defined?
--------
public_method_defined?(undefined_refined_public) # => true
public_method_defined?(undefined_refined_protected) # => true
public_method_defined?(undefined_refined_private) # => true

protected_method_defined?
--------
protected_method_defined?(undefined_refined_public) # => false
protected_method_defined?(undefined_refined_protected) # => false
protected_method_defined?(undefined_refined_private) # => false

private_method_defined?
--------
private_method_defined?(undefined_refined_public) # => false
private_method_defined?(undefined_refined_protected) # => false
private_method_defined?(undefined_refined_private) # => false

Files

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

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

Applied in changeset r49322.


vm_method.c: method defined should not use refinements.

  • vm_method.c (check_definition): Module#public_method_defined?,
    Module#private_method_defined?, Module#protected_method_defined?
    should not use refinements. [ruby-core:67656] [Bug #10753]
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 9 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED

Updated by naruse (Yui NARUSE) about 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE

ruby_2_2 r49409 merged revision(s) 49322.

Updated by usa (Usaku NAKAMURA) about 9 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: DONE to 2.0.0: DONE, 2.1: REQUIRED, 2.2: DONE

ruby_2_0_0 r49737 merged revision(s) 49322.

Actions #6

Updated by nagachika (Tomoyuki Chikanaga) about 9 years ago

  • Backport changed from 2.0.0: DONE, 2.1: REQUIRED, 2.2: DONE to 2.0.0: DONE, 2.1: DONE, 2.2: DONE

Backported into ruby_2_1 branch at r49991.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0