[ruby-core:85647] [Ruby trunk Bug#14495] Enumerator::Lazy#uniq invalid state

From: chopraanmol1@...
Date: 2018-02-19 13:01:34 UTC
List: ruby-core #85647
Issue #14495 has been updated by chopraanmol1 (Anmol Chopra).


Solution https://github.com/ruby/ruby/pull/1820

----------------------------------------
Bug #14495: Enumerator::Lazy#uniq invalid state
https://bugs.ruby-lang.org/issues/14495#change-70439

* Author: chopraanmol1 (Anmol Chopra)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0preview1 (2017-10-10 trunk 60153) [x86_64-linux]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------

Currently

~~~ ruby
2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10}
 => #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq> 
2.5.0-preview1 :002 > arr.to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
2.5.0-preview1 :003 > arr.to_a
 => [] 
~~~

Expected

~~~ ruby
2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10}
 => #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq> 
2.5.0-preview1 :002 > arr.to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
2.5.0-preview1 :003 > arr.to_a
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 
~~~


Solution **Enumerator::Lazy#uniq**'s hash should be accessed from yielder memo



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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next