https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112018-12-21T13:27:57ZRuby Issue Tracking SystemRuby master - Bug #15449: Range#=== is not using cover in Ruby 2.6https://bugs.ruby-lang.org/issues/15449?journal_id=758262018-12-21T13:27:57Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><p>According to <a href="https://github.com/ruby/ruby/blob/trunk/range.c#L1287" class="external">code</a>, it first tries to use <code>range_include_internal</code>, which has <a href="https://github.com/ruby/ruby/blob/trunk/range.c#L1330" class="external">special handling for strings</a>.</p>
<p>Justification is not obvious, but probably it is an attempt to preserve backwards compatibility?</p> Ruby master - Bug #15449: Range#=== is not using cover in Ruby 2.6https://bugs.ruby-lang.org/issues/15449?journal_id=758272018-12-21T13:35:24Zana06 (Ana Maria Martinez Gomez)
<ul></ul><p>If that the case, this should be clarified in NEWS, because it sounds as it was changed for all cases...</p> Ruby master - Bug #15449: Range#=== is not using cover in Ruby 2.6https://bugs.ruby-lang.org/issues/15449?journal_id=758292018-12-21T13:55:55ZHanmac (Hans Mackowiak)hanmac@gmx.de
<ul></ul><p>That isn't new, that is since 1.9 as #cover? was added</p> Ruby master - Bug #15449: Range#=== is not using cover in Ruby 2.6https://bugs.ruby-lang.org/issues/15449?journal_id=758302018-12-21T13:58:18Zosyo (manga osyo)
<ul></ul><p>Sorry, <code>Range#===</code> is called <code>Range#cover?</code> in Ruby 2.6.<br>
see: <a href="https://bugs.ruby-lang.org/issues/14575" class="external">https://bugs.ruby-lang.org/issues/14575</a></p> Ruby master - Bug #15449: Range#=== is not using cover in Ruby 2.6https://bugs.ruby-lang.org/issues/15449?journal_id=802192019-07-29T23:36:31Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>File</strong> <a href="/attachments/7922">range-case-cover-string.patch</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/7922/range-case-cover-string.patch">range-case-cover-string.patch</a> added</li><li><strong>Backport</strong> changed from <i>2.4: UNKNOWN, 2.5: UNKNOWN</i> to <i>2.5: DONTNEED, 2.6: REQUIRED</i></li></ul><p>I agree that this is a bug, and not the intended behavior now that <code>Range#===</code> calls <code>Range#cover?</code> in most cases. Hopefully nobu can confirm. Attached is a patch that fixes the behavior.</p>
<p>I think this should be backported to 2.6, assuming this behavior is not intentional.</p> Ruby master - Bug #15449: Range#=== is not using cover in Ruby 2.6https://bugs.ruby-lang.org/issues/15449?journal_id=807672019-08-14T23:16:19Zjeremyevans (Jeremy Evans)code@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Make Range#=== operate like cover? instead of include? for string ranges Previously, Range#=== t..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/6954ff1dcb538ee6c042872088b64464a1ef6089">git|6954ff1dcb538ee6c042872088b64464a1ef6089</a>.</p>
<hr>
<p>Make Range#=== operate like cover? instead of include? for string ranges</p>
<p>Previously, Range#=== treated string ranges that were not endless or<br>
beginless the same as include?, instead of the same as cover?.<br>
I think this was an oversight in 989e07c0f2fa664a54e52a475c2fcc145f06539d,<br>
as the commit message did not indicate this behavior was desired.</p>
<p>This also makes some previously dead code no longer dead. Previously,<br>
the conditionals were doing this:</p>
<pre><code>if (RB_TYPE_P(beg, T_STRING)
if (NIL_P(beg)) # can never be true
</code></pre>
<p>This restructures it so at the NIL_P(beg) check, beg could possibly<br>
be nil (beginless ranges).</p>
<p>Fixes [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Range#=== is not using cover in Ruby 2.6 (Closed)" href="https://bugs.ruby-lang.org/issues/15449">#15449</a>]</p>