https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112023-05-09T01:26:18ZRuby Issue Tracking SystemRuby master - Bug #19632: Disable external iterator for frozen enumeratorhttps://bugs.ruby-lang.org/issues/19632?journal_id=1029942023-05-09T01:26:18Zmake_now_just (Hiroya Fujinami)make.just.on@gmail.com
<ul></ul><p>A Pull Request for this is created. <a href="https://github.com/ruby/ruby/pull/7791" class="external">https://github.com/ruby/ruby/pull/7791</a></p> Ruby master - Bug #19632: Disable external iterator for frozen enumeratorhttps://bugs.ruby-lang.org/issues/19632?journal_id=1029952023-05-09T01:41:30Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Sounds reasonable.</p> Ruby master - Bug #19632: Disable external iterator for frozen enumeratorhttps://bugs.ruby-lang.org/issues/19632?journal_id=1030462023-05-13T14:14:35Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p><code>peek</code> does not seem to modify the enumerator? Should we prohibit it (or not)?</p> Ruby master - Bug #19632: Disable external iterator for frozen enumeratorhttps://bugs.ruby-lang.org/issues/19632?journal_id=1030472023-05-14T00:41:59Zmake_now_just (Hiroya Fujinami)make.just.on@gmail.com
<ul></ul><p>If a result value is not stored, <code>peek</code> invokes the iterator and stores it in its internal state. For that reason, I consider <code>peek</code> is also a mutable method like <code>next</code>.</p>
<p>If you call <code>peek</code> in advance and then call <code>freeze</code>, <code>peek</code> will not change the internal state. IMHO, this case is exceptional and should still raise a <code>FrozenError</code> for simplicity. However, I would follow matz's decision.</p> Ruby master - Bug #19632: Disable external iterator for frozen enumeratorhttps://bugs.ruby-lang.org/issues/19632?journal_id=1030632023-05-14T10:53:22ZEregon (Benoit Daloze)
<ul></ul><p>+1. And yes peek can have side effect so should be considered mutating method.</p> Ruby master - Bug #19632: Disable external iterator for frozen enumeratorhttps://bugs.ruby-lang.org/issues/19632?journal_id=1050712023-10-25T07:32:36Zmake_now_just (Hiroya Fujinami)make.just.on@gmail.com
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="Fix [Bug #19632]: Disable external iterator for frozen enumerator (#7791) * Fix [Bug #19632]: Di..." href="https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/3e64cf60b5162bb5dad772f300b7f6346e5f83f9">git|3e64cf60b5162bb5dad772f300b7f6346e5f83f9</a>.</p>
<hr>
<p>Fix [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Disable external iterator for frozen enumerator (Closed)" href="https://bugs.ruby-lang.org/issues/19632">#19632</a>]: Disable external iterator for frozen enumerator (<a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Let symbols be garbage collected (Closed)" href="https://bugs.ruby-lang.org/issues/7791">#7791</a>)</p>
<ul>
<li>Fix [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Disable external iterator for frozen enumerator (Closed)" href="https://bugs.ruby-lang.org/issues/19632">#19632</a>]: Disable external iterator for frozen enumerator</li>
</ul>
<p>Currently, methods to manipulate an external iterator like <code>#next</code><br>
and <code>#feed</code> can be called even if a receiver of an enumerator is<br>
frozen. However, these methods change the state of an external<br>
iterator in an enumerator. Therefore, it seems a BUG to me, and<br>
these methods should raise FrozenError if the receiver is frozen.</p>
<p>This fixed the following methods to raise FrozenError if the receiver is<br>
frozen.</p>
<ul>
<li><code>Enumerator#next</code></li>
<li><code>Enumerator#next_values</code></li>
<li><code>Enumerator#peek</code></li>
<li><code>Enumerator#peek_values</code></li>
<li><code>Enumerator#feed</code></li>
<li><code>Enumerator#rewind</code></li>
</ul>
<ul>
<li>Fix a typo in the document</li>
</ul>
<p>Thanks <a class="user active user-mention" href="https://bugs.ruby-lang.org/users/9835">@Maumagnaguagno (Mau Magnaguagno)</a>.</p>