ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:103469] [Ruby master Bug#17806] Bad interaction between method cache, prepend, and refinements
@ 2021-04-16  3:25 XrXr
  2021-05-29  5:57 ` [ruby-core:104096] " nagachika00
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: XrXr @ 2021-04-16  3:25 UTC (permalink / raw)
  To: ruby-core

Issue #17806 has been reported by alanwu (Alan Wu).

----------------------------------------
Bug #17806: Bad interaction between method cache, prepend, and refinements
https://bugs.ruby-lang.org/issues/17806

* Author: alanwu (Alan Wu)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-darwin19]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: REQUIRED
----------------------------------------
I'm running into a couple of issues with Ruby 3's new method cache and
refinements.

The first script raises `SystemStackError` unexpectedly:

```ruby
module R1
  refine Hash do
    def foo; :r1; end
  end
end
class Hash
  prepend(Module.new)
end
class Hash
  def foo; end
end
{}.method(:foo) # put it on pCMC
module R2
  refine Hash do
    def foo; :r2; end
  end
end
{}.foo # SystemStackError
```

The second script calls the wrong method:

```ruby
klass = Class.new { def foo; end }
_refinement = Module.new do
  refine(klass) { def foo; :refined; end }
end
klass.prepend(Module.new)
klass.new.foo # cache foo
klass.define_method(:foo) { :second }
p klass.new.foo # prints nil. False caching.
```

I submitted a GitHub PR to fix the issue: https://github.com/ruby/ruby/pull/4386



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-12 13:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16  3:25 [ruby-core:103469] [Ruby master Bug#17806] Bad interaction between method cache, prepend, and refinements XrXr
2021-05-29  5:57 ` [ruby-core:104096] " nagachika00
2021-08-05 11:49 ` [ruby-core:104788] " mkaeppler
2021-08-05 15:29 ` [ruby-core:104791] " XrXr
2021-08-12 13:31 ` [ruby-core:104897] " mkaeppler

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).