Project

General

Profile

Actions

Bug #7290

closed

Overriding method_added on a refinement's anonymous module can cause the opt_* opcodes to behave incorrectly

Added by Anonymous over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
2.0.0-preview1
Backport:
[ruby-core:48970]

Description

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

Actions

Also available in: Atom PDF

Like0
Like0Like0