https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782012-03-26T14:12:32ZRuby Issue Tracking SystemRuby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=251772012-03-26T14:12:32Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li></ul><p>It's definitely not a bug.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=251782012-03-26T14:12:57Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/25178/diff?detail_id=18504">diff</a>)</li></ul> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=251812012-03-26T22:46:02Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>Hi,</p>
<p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>It's definitely not a bug.</p>
</blockquote>
<p>It's not?<br>
How do you explain:</p>
<pre><code>[1, 2, 3].values_at(2...42) # => [3]
[1, 2, 3].values_at(2..41) # => [3, nil]
</code></pre>
<p>I feel that both must return the same result.<br>
Moreover, the only acceptable results are either [3] or [3, nil, nil, ... nil]</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=253122012-03-29T01:57:46Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Tracker</strong> changed from <i>Feature</i> to <i>Bug</i></li></ul><p>Moving back to "bug", as no explanation from Nobu.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=253172012-03-29T05:14:11Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Assignee</strong> set to <i>marcandre (Marc-Andre Lafortune)</i></li><li><strong>Target version</strong> changed from <i>1.9.3</i> to <i>2.0.0</i></li><li><strong>ruby -v</strong> set to <i>trunk</i></li></ul><p>The patch from Mark Rada never made it through, but I concur that the problem is in rb_range_beg_len.<br>
I'll commit the fix below unless there's objection.<br>
I've already fixed RubySpec:<br>
<a href="https://github.com/rubyspec/rubyspec/commit/558a40edd5cd43a503641238cabe9f481ce9a723" class="external">https://github.com/rubyspec/rubyspec/commit/558a40edd5cd43a503641238cabe9f481ce9a723</a></p>
<p>diff --git a/range.c b/range.c<br>
index 61fb643..aa0628d 100644<br>
--- a/range.c<br>
+++ b/range.c<br>
@@ -746,16 +746,16 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)<br>
if (beg < 0)<br>
goto out_of_range;<br>
}</p>
<ul>
<li>if (end < 0)</li>
<li>
<pre><code> end += len;
</code></pre>
</li>
<li>if (!excl)</li>
<li>
<pre><code> end++; /* include end point */
</code></pre>
if (err == 0 || err == 2) {<br>
if (beg > len)<br>
goto out_of_range;<br>
if (end > len)<br>
end = len;<br>
}</li>
</ul>
<ul>
<li>if (end < 0)</li>
<li>
<pre><code> end += len;
</code></pre>
</li>
<li>if (!excl)</li>
<li>
<pre><code> end++; /* include end point */
</code></pre>
len = end - beg;<br>
if (len < 0)<br>
len = 0;</li>
</ul> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=253182012-03-29T05:22:39Zferrous26 (Mark Rada)markrada26@gmail.com
<ul></ul><p>marcandre (Marc-Andre Lafortune) wrote:</p>
<blockquote>
<p>The patch from Mark Rada never made it through, but I concur that the problem is in rb_range_beg_len.</p>
</blockquote>
<p>Hello Marc,</p>
<p>Sorry for not linking to the pull request here, though I did open a pull request on Github here: <a href="https://github.com/ruby/ruby/pull/109" class="external">https://github.com/ruby/ruby/pull/109</a></p>
<p>Though I think your solution is much nicer. Perhaps the tests I added are still useful.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=253432012-03-29T10:47:32Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> changed from <i>marcandre (Marc-Andre Lafortune)</i> to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>Is this a bug?</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=253452012-03-29T11:11:05Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>Hi,</p>
<p>naruse (Yui NARUSE) wrote:</p>
<blockquote>
<p>Is this a bug?</p>
</blockquote>
<p>I'm very curious: how could it not be bug?<br>
How would you explain that <code>values_at(2...42) != values_at(2..41)</code>?</p>
<p>I simply want to lighten the load for Matz; he has so many issues assigned to him or waiting on him already.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=253482012-03-29T12:27:44Znaruse (Yui NARUSE)naruse@airemix.jp
<ul></ul><p>marcandre (Marc-Andre Lafortune) wrote:</p>
<blockquote>
<p>I simply want to lighten the load for Matz; he has so many issues assigned to him or waiting on him already.</p>
</blockquote>
<p>You must wait (or press) matz if a fix of an issue is clear and no other option of the new behavior.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=258352012-04-12T03:28:19Zferrous26 (Mark Rada)markrada26@gmail.com
<ul></ul><p>naruse (Yui NARUSE) wrote:</p>
<blockquote>
<p>marcandre (Marc-Andre Lafortune) wrote:</p>
<blockquote>
<p>I simply want to lighten the load for Matz; he has so many issues assigned to him or waiting on him already.</p>
</blockquote>
<p>You must wait (or press) matz if a fix of an issue is clear and no other option of the new behavior.</p>
</blockquote>
<p>It has been 2 weeks since the last update. Has this issue been forgotten?</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=280612012-07-14T17:26:00Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Assignee</strong> changed from <i>matz (Yukihiro Matsumoto)</i> to <i>nobu (Nobuyoshi Nakada)</i></li></ul><p>The trailing nil must be a bug.</p>
<p>Matz.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=280742012-07-14T18:18:55Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r36393.<br>
Mark, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>array.c: fill with nil</p>
<ul>
<li>array.c (rb_get_values_at): fill with nil out of range.<br>
<a href="/issues/6203">[ruby-core:43678]</a> [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Array#values_at does not handle ranges with end index past the end of the array (Closed)" href="https://bugs.ruby-lang.org/issues/6203">#6203</a>]</li>
</ul> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=281502012-07-16T23:48:50Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>matz (Yukihiro Matsumoto) wrote:</p>
<blockquote>
<p>The trailing nil must be a bug.</p>
</blockquote>
<p>Was there a reason to change the behavior of <code>[].values_at(42..100)</code>? Could this not lead to incompatibilities?</p>
<p>Nobu: is there a reason not to fix <code>rb_range_beg_len</code> also as per <a href="/issues/6203">[ruby-core:43811]</a>?</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=282832012-07-23T09:11:39Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Closed</i> to <i>Open</i></li></ul><p>Marking as open, since fix doesn't seem to correspond to what Matz wrote.</p>
<p>marcandre (Marc-Andre Lafortune) wrote:</p>
<blockquote>
<p>matz (Yukihiro Matsumoto) wrote:</p>
<blockquote>
<p>The trailing nil must be a bug.</p>
</blockquote>
<p>Was there a reason to change the behavior of <code>[].values_at(42..100)</code>? Could this not lead to incompatibilities?</p>
<p>Nobu: is there a reason not to fix <code>rb_range_beg_len</code> also as per <a href="/issues/6203">[ruby-core:43811]</a>?</p>
</blockquote> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=330842012-11-19T14:13:19Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul></ul><p>Matz, could you please confirm what return value is correct for <code>[].values_at(1..3)</code>?</p>
<ol>
<li>It could be []. This would be compatible with Ruby 1.8 & 1.9.</li>
<li>It could be [nil, nil, nil]. This is current behavior in trunk after Nobu's commit, but with potential incompatibility.</li>
</ol>
<p>If 1, trunk must be changed<br>
If 2, NEWS must list incompatibility.</p>
<p>Nobu: in either case, any reason not to commit my patch in [#5]?</p>
<p>Thanks</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=331772012-11-20T18:26:22Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>This is a spec change in 2.0 unless any big compatibility problem arise.<br>
Array#values_at should be define as:</p>
<p>def values_at(*idx)<br>
idx.map{|i| self[i]}<br>
end</p>
<p>So it should be written in the NEWS file.</p>
<p>Matz.</p> Ruby master - Bug #6203: Array#values_at does not handle ranges with end index past the end of the arrayhttps://bugs.ruby-lang.org/issues/6203?journal_id=333772012-11-21T13:25:56Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Great, thanks.</p>
<p>NEWS updated.</p>