Project

General

Profile

Actions

Bug #11117

closed

When you refine String with to_regexp, then it breaks Regexp.try_convert even when the refinement is not used

Added by jirutka (Jakub Jirutka) almost 9 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.2.2p95
[ruby-core:69064]

Description

I’ve run into a very strange bug with refinements. Let me show you:

module Ref
  refine String do
    def to_regexp
    end
  end
end

Regexp.try_convert('foo')
# or Regexp.union('foo', 'bar')
bug.rb:8:in `try_convert': undefined method `to_regexp' for "foo":String (NoMethodError)
	from test.rb:8:in `<main>'

Note that the refinement is not used (using), only declared, and yet it has affected behaviour of the refined class! This problem occurs only when the method is named to_string. It seems that there’s some serious scoping issue with refinements.

I’ve reproduced this issue on MRI 2.2.2p95, 2.1.5p273, and 2.0.0p598.

Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 9 years ago

  • Status changed from Open to Closed

Applied in changeset r50430.


vm_eval.c: undefined refined check_funcall

  • vm_eval.c (rb_method_call_status): undefined refined method is
    not callable unless using. [ruby-core:69064] [Bug #11117]

Updated by nobu (Nobuyoshi Nakada) almost 9 years ago

  • Priority changed from 5 to Normal
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED

Updated by usa (Usaku NAKAMURA) over 8 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED

ruby_2_1 r51119 merged revision(s) 50430,50440.

Updated by nagachika (Tomoyuki Chikanaga) over 8 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE

Backported into ruby_2_2 branch at r51133.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0