Project

General

Profile

Actions

Bug #19632

closed

Disable external iterator for frozen enumerator

Added by make_now_just (Hiroya Fujinami) 12 months ago. Updated 6 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:113420]

Description

Currently, methods to manipulate an external iterator like #next and #feed can be called even if a receiver of an enumerator is frozen. However, these methods change the state of an external iterator in an enumerator. Therefore, it seems a BUG to me, and these methods should raise FrozenError if the receiver is frozen.

e = 3.times.freeze

# Current

e.next # => 1
e.next # => 2

# Expected

e.next # raise FrozenError

Two years ago, this issue was mentioned in a comment.

I suggest fixing the following methods to raise FrozenError against a frozen enumerator.

  • Enumerator#next
  • Enumerator#next_values
  • Enumerator#peek
  • Enumerator#peek_values
  • Enumerator#feed
  • Enumerator#rewind

Also, even if an enumerator is frozen, it does not affect other methods for internal iterators.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0