ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: hanachin@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:67982] [ruby-trunk - Bug #10765] Module#remove_method remove refined method entry.
Date: Tue, 03 Feb 2015 15:20:26 +0000	[thread overview]
Message-ID: <redmine.journal-51370.20150203152025.cccf284237a9017f@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-10765.20150121134713@ruby-lang.org

Issue #10765 has been updated by Seiei Higa.


If touch the `me` after `rb_unlink_method_entry`, it could cause error?

``` patch
diff --git vm_method.c vm_method.c
index 8ad2b72..41a311c 100644
--- vm_method.c
+++ vm_method.c
@@ -775,11 +775,13 @@ remove_method(VALUE klass, ID mid)
     key = (st_data_t)mid;
     st_delete(RCLASS_M_TBL(klass), &key, &data);

+    int keep_refined_method_entry = me->def->type == VM_METHOD_TYPE_REFINED;
+
     rb_vm_check_redefinition_opt_method(me, klass);
     rb_clear_method_cache_by_class(klass);
     rb_unlink_method_entry(me);

-    if (me->def->type == VM_METHOD_TYPE_REFINED) {
+    if (keep_refined_method_entry) {
 	rb_add_refined_method_entry(klass, mid);
     }
```

----------------------------------------
Bug #10765: Module#remove_method remove refined method entry.
https://bugs.ruby-lang.org/issues/10765#change-51370

* Author: Seiei Higa
* Status: Assigned
* Priority: Normal
* Assignee: Shugo Maeda
* ruby -v: ruby 2.3.0dev (2015-01-21 trunk 49326) [x86_64-darwin14]
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
----------------------------------------
`Module#remove_method` should raise a `NameError`
if method is not defined in refined class, such as [`undef`](https://bugs.ruby-lang.org/issues/8966).
But if method is defined in refined class, `Module#remove_method` should keep refined method and remove original method.

I confirmed by following examples in ruby-trunk, 2.2.0, 2.1.5, 2.0.0-p598

``` ruby
class C
  def foo
    "C#foo"
  end
end

module RefinementBug
  refine C do
    def foo
      "RefinementBug#foo"
    end
  end
end

using RefinementBug

class C
  remove_method :foo
end

puts C.new.foo

# expected:
#   RefinementBug#foo
#
# actual:
#   bug.rb:21:in `<main>': undefined method `foo' for #<C:0x007f9e5c087b48> (NoMethodError)
```

``` ruby
class C
end

module RefinementBug
  refine C do
    def foo
    end
  end
end

using RefinementBug

class C
  remove_method :foo
end

# expected:
#   bug2.rb:14:in `remove_method': method `foo' not defined in C (NameError)
#   from bug2.rb:14:in `<class:C>'
#   from bug2.rb:13:in `<main>'
#
# actual:
#   # => nothing raised.
```

---Files--------------------------------
bug2.rb (327 Bytes)
bug.rb (342 Bytes)
0001-vm_method.c-fix-remove-refined-method.patch (2.68 KB)


-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2015-02-03 15:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-10765.20150121134713@ruby-lang.org>
2015-01-21 13:47 ` [ruby-core:67722] [ruby-trunk - Bug #10765] [Open] Module#remove_method remove refined method entry hanachin
2015-01-21 13:50 ` [ruby-core:67723] [ruby-trunk - Bug #10765] " hanachin
2015-02-03  6:15 ` [ruby-core:67967] [ruby-trunk - Bug #10765] [Assigned] " shugo
2015-02-03  6:30 ` [ruby-core:67969] [ruby-trunk - Bug #10765] " shugo
2015-02-03 13:26 ` [ruby-core:67978] [ruby-trunk - Bug #10765] [Assigned] " v.ondruch
2015-02-03 15:20 ` hanachin [this message]
2015-02-04  5:39 ` [ruby-core:67996] [ruby-trunk - Bug #10765] " shugo
2015-02-04  5:52 ` [ruby-core:67998] " shugo
2015-02-04  8:16 ` [ruby-core:68002] [ruby-trunk - Bug #10765] [Closed] " shugo
2015-02-04 15:46 ` [ruby-core:68007] [ruby-trunk - Bug #10765] " v.ondruch
2015-02-19  7:20 ` [ruby-core:68182] [Ruby trunk " naruse
2015-02-25  6:01 ` [ruby-core:68302] " usa
2015-03-17 16:13 ` [ruby-core:68544] " nagachika00

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-51370.20150203152025.cccf284237a9017f@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).