Issue #7290 has been reported by charliesome (Charlie Somerville). ---------------------------------------- Bug #7290: Overriding method_added on a refinement's anonymous module can cause the opt_* opcodes to behave incorrectly https://bugs.ruby-lang.org/issues/7290 Author: charliesome (Charlie Somerville) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0-preview1 Ruby stores flags in (({ruby_vm_redefined_flag})) to track whether certain methods have been redefined on particular classes. If the redefined flag for a certain class and operator is not set, Ruby will skip method lookup and directly call the method implementing that operator. The current implementation of refinements uses the (({method_added})) callback to set these flags. If this method is overridden, the flags are not set properly. This code should raise a RuntimeError with the message "addition is not allowed". Instead it outputs "3". If line 3 is removed, it behaves correctly. module Test refine Fixnum do def self.method_added(id); end def +(other) raise "addition is not allowed" end end end using Test puts 1 + 2
on 2012-11-06 12:12
[ruby-trunk - Bug #7290] Overriding method_added on a refinement's anonymous module can cause the op
on 2012-11-07 00:20
Issue #7290 has been updated by ko1 (Koichi Sasada). Category set to core Assignee set to shugo (Shugo Maeda) Target version set to 2.0.0 ---------------------------------------- Bug #7290: Overriding method_added on a refinement's anonymous module can cause the opt_* opcodes to behave incorrectly https://bugs.ruby-lang.org/issues/7290#change-32521 Author: charliesome (Charlie Somerville) Status: Open Priority: Normal Assignee: shugo (Shugo Maeda) Category: core Target version: 2.0.0 ruby -v: 2.0.0-preview1 Ruby stores flags in (({ruby_vm_redefined_flag})) to track whether certain methods have been redefined on particular classes. If the redefined flag for a certain class and operator is not set, Ruby will skip method lookup and directly call the method implementing that operator. The current implementation of refinements uses the (({method_added})) callback to set these flags. If this method is overridden, the flags are not set properly. This code should raise a RuntimeError with the message "addition is not allowed". Instead it outputs "3". If line 3 is removed, it behaves correctly. module Test refine Fixnum do def self.method_added(id); end def +(other) raise "addition is not allowed" end end end using Test puts 1 + 2
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.