ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: jakub@jirutka.cz
To: ruby-core@ruby-lang.org
Subject: [ruby-core:69064] [Ruby trunk - Bug #11117] [Open] When you refine String with to_regexp, then it breaks Regexp.try_convert even when the refinement is not used
Date: Sun, 03 May 2015 19:16:48 +0000	[thread overview]
Message-ID: <redmine.issue-11117.20150503191647.afad4cd1a386800e@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11117.20150503191647@ruby-lang.org

Issue #11117 has been reported by Jakub Jirutka.

----------------------------------------
Bug #11117: When you refine String with to_regexp, then it breaks Regexp.try_convert even when the refinement is not used
https://bugs.ruby-lang.org/issues/11117

* Author: Jakub Jirutka
* Status: Open
* Priority: High
* Assignee: 
* ruby -v: 2.2.2p95
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
I’ve run into a very strange bug with refinements. Let me show you:

~~~ruby
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.



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

       reply	other threads:[~2015-05-03 19:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11117.20150503191647@ruby-lang.org>
2015-05-03 19:16 ` jakub [this message]
2015-05-08  4:22 ` [ruby-core:69098] [Ruby trunk - Bug #11117] When you refine String with to_regexp, then it breaks Regexp.try_convert even when the refinement is not used nobu
2015-07-03  8:56 ` [ruby-core:69853] " usa
2015-07-03 19:45 ` [ruby-core:69864] " 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.issue-11117.20150503191647.afad4cd1a386800e@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).