Project

General

Profile

Bug #13096

error using undef_method + refinements

Added by zenspider (Ryan Davis) about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
2.3 or 2.4
[ruby-core:78944]

Description

I've got a bug report on minitest/mock that I've reduced to the following:

class Object
  def to_query            # remove this, works fine
  end
end

Object.prepend Module.new # remove this, works fine

module ObjectExtensions
  refine ::Object do
    def to_query          # remove this, works fine
    end
  end
end

class Mock
  instance_methods.each do |m|
    next if m =~ /object_id|__send__/
    undef_method m
  end
end

giving me the error:

bug671.rb:18:in `undef_method': undefined method `to_query' for class `Mock' (NameError)
    from bug671.rb:18:in `block in <class:Mock>'
    from bug671.rb:16:in `each'
    from bug671.rb:16:in `<class:Mock>'
    from bug671.rb:15:in `<main>'

This code comes from activesupport via regular requires, so this is a real problem for me.

Looks like the culprit might be here:

https://github.com/ruby/ruby/blob/v2_4_0/vm_method.c#L1187

I'd expect to be able to undef anything that comes back from instance_methods regardless of whether there is a refinement in place or not.

Additionally, the error message is just plain wrong. The method is most certainly defined (twice!) and should be improved.

Associated revisions

Revision b38823ce
Added by nobu (Nobuyoshi Nakada) about 3 years ago

vm_method.c: resolve refined method to undef

  • vm_method.c (rb_undef): resolve the method entry which refines a prepended method entry. [ruby-core:78944] [Bug #13096]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57362
Added by nobu (Nobuyoshi Nakada) about 3 years ago

vm_method.c: resolve refined method to undef

  • vm_method.c (rb_undef): resolve the method entry which refines a prepended method entry. [ruby-core:78944] [Bug #13096]

Revision 57362
Added by nobu (Nobuyoshi Nakada) about 3 years ago

vm_method.c: resolve refined method to undef

  • vm_method.c (rb_undef): resolve the method entry which refines a prepended method entry. [ruby-core:78944] [Bug #13096]

Revision 57362
Added by nobu (Nobuyoshi Nakada) about 3 years ago

vm_method.c: resolve refined method to undef

  • vm_method.c (rb_undef): resolve the method entry which refines a prepended method entry. [ruby-core:78944] [Bug #13096]

Revision 0543b90d
Added by naruse (Yui NARUSE) almost 3 years ago

merge revision(s) 57362: [Backport #13096]

    vm_method.c: resolve refined method to undef

    * vm_method.c (rb_undef): resolve the method entry which refines a
      prepended method entry.  [ruby-core:78944] [Bug #13096]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@57862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57862
Added by naruse (Yui NARUSE) almost 3 years ago

merge revision(s) 57362: [Backport #13096]

vm_method.c: resolve refined method to undef

* vm_method.c (rb_undef): resolve the method entry which refines a
  prepended method entry.  [ruby-core:78944] [Bug #13096]

Revision d5b08a46
Added by usa (Usaku NAKAMURA) almost 3 years ago

merge revision(s) 57362: [Backport #13096]

    vm_method.c: resolve refined method to undef

    * vm_method.c (rb_undef): resolve the method entry which refines a
      prepended method entry.  [ruby-core:78944] [Bug #13096]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@58126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58126
Added by usa (Usaku NAKAMURA) almost 3 years ago

merge revision(s) 57362: [Backport #13096]

vm_method.c: resolve refined method to undef

* vm_method.c (rb_undef): resolve the method entry which refines a
  prepended method entry.  [ruby-core:78944] [Bug #13096]

Revision f8e37f57
Added by nagachika (Tomoyuki Chikanaga) almost 3 years ago

merge revision(s) 57362: [Backport #13096]

    vm_method.c: resolve refined method to undef

    * vm_method.c (rb_undef): resolve the method entry which refines a
      prepended method entry.  [ruby-core:78944] [Bug #13096]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@58174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 58174
Added by nagachika (Tomoyuki Chikanaga) almost 3 years ago

merge revision(s) 57362: [Backport #13096]

vm_method.c: resolve refined method to undef

* vm_method.c (rb_undef): resolve the method entry which refines a
  prepended method entry.  [ruby-core:78944] [Bug #13096]

History

#1

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Status changed from Open to Closed

Applied in changeset r57362.


vm_method.c: resolve refined method to undef

  • vm_method.c (rb_undef): resolve the method entry which refines a prepended method entry. [ruby-core:78944] [Bug #13096]

Updated by naruse (Yui NARUSE) almost 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE

ruby_2_4 r57862 merged revision(s) 57362.

Updated by nagachika (Tomoyuki Chikanaga) almost 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: DONE to 2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE
#4

Updated by usa (Usaku NAKAMURA) almost 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

Updated by usa (Usaku NAKAMURA) almost 3 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: DONE, 2.3: REQUIRED, 2.4: DONE

ruby_2_2 r58126 merged revision(s) 57362.

Updated by nagachika (Tomoyuki Chikanaga) almost 3 years ago

  • Backport changed from 2.2: DONE, 2.3: REQUIRED, 2.4: DONE to 2.2: DONE, 2.3: DONE, 2.4: DONE

ruby_2_3 r58174 merged revision(s) 57362.

Also available in: Atom PDF