ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:81638] [Ruby trunk Bug#13648] [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result
       [not found] <redmine.issue-13648.20170609161134@ruby-lang.org>
@ 2017-06-09 16:11 ` akihiko.odaki.4i
  2017-06-10 10:26 ` [ruby-core:81646] " nobu
  2017-07-18 12:42 ` [ruby-core:82098] " nagachika00
  2 siblings, 0 replies; 3+ messages in thread
From: akihiko.odaki.4i @ 2017-06-09 16:11 UTC (permalink / raw
  To: ruby-core

Issue #13648 has been reported by akihikodaki (Akihiko Odaki).

----------------------------------------
Bug #13648: [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result
https://bugs.ruby-lang.org/issues/13648

* Author: akihikodaki (Akihiko Odaki)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
This test case ends up with the following result.

~~~ ruby
class Step
  include Enumerable
  attr_reader :current, :args

  def initialize(enum)
    @enum = enum
    @current = nil
    @args = nil
  end

  def each(*args)
    @args = args
    @enum.each do |v|
      @current = v
    if v.is_a? Enumerable
      yield *v
    else
      yield v
    end
  end
end

a = Step.new([[1, 2]])
assert_equal([[[1, 2]]], a.lazy.map {|*args| args}.map {|*args| args}.to_a)
~~~

~~~
<[[[1, 2]]]> expected but was
<[[1, 2]]>.
~~~

Here, `[[[1, 2]]]` is expected because:
* An array should be created with the first map, which results in `[1, 2]`.
* The array should be wrapped in another array with the second map, which results in `[[1, 2]]`.
* The array should be wrapped in another array with to_a, which results in `[[[1, 2]]]`.

However, it returns `[[1, 2]]` because:
* An array will be created with the first map, which results in `[1, 2]`.
* However, the array will be internally considered as "packed" and the unpacked arguments will be passed to the second map.
* The second map wraps them into another array, which results in `[1, 2]`.
* The array will be wrapped in another array with to_a, which results in `[[1, 2]]`.

I have attached the test case and a fix. The fix marks values returned by blocks are not packed.

---Files--------------------------------
fix.patch (2.18 KB)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:81646] [Ruby trunk Bug#13648] [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result
       [not found] <redmine.issue-13648.20170609161134@ruby-lang.org>
  2017-06-09 16:11 ` [ruby-core:81638] [Ruby trunk Bug#13648] [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result akihiko.odaki.4i
@ 2017-06-10 10:26 ` nobu
  2017-07-18 12:42 ` [ruby-core:82098] " nagachika00
  2 siblings, 0 replies; 3+ messages in thread
From: nobu @ 2017-06-10 10:26 UTC (permalink / raw
  To: ruby-core

Issue #13648 has been updated by nobu (Nobuyoshi Nakada).

Description updated
Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED

Thank you, I commit your patch without GCC extension.

----------------------------------------
Bug #13648: [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result
https://bugs.ruby-lang.org/issues/13648#change-65340

* Author: akihikodaki (Akihiko Odaki)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-06-09 trunk 59052) [x86_64-linux]
* Backport: 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED
----------------------------------------
This test case ends up with the following result.

~~~ ruby
class Step
  include Enumerable
  attr_reader :current, :args

  def initialize(enum)
    @enum = enum
    @current = nil
    @args = nil
  end

  def each(*args)
    @args = args
    @enum.each do |v|
      @current = v
      if v.is_a? Enumerable
        yield *v
      else
        yield v
      end
    end
  end
end

a = Step.new([[1, 2]])
assert_equal([[[1, 2]]], a.lazy.map {|*args| args}.map {|*args| args}.to_a)
~~~

~~~
<[[[1, 2]]]> expected but was
<[[1, 2]]>.
~~~

Here, `[[[1, 2]]]` is expected because:

* An array should be created with the first map, which results in `[1, 2]`.
* The array should be wrapped in another array with the second map, which results in `[[1, 2]]`.
* The array should be wrapped in another array with to_a, which results in `[[[1, 2]]]`.

However, it returns `[[1, 2]]` because:

* An array will be created with the first map, which results in `[1, 2]`.
* However, the array will be internally considered as "packed" and the unpacked arguments will be passed to the second map.
* The second map wraps them into another array, which results in `[1, 2]`.
* The array will be wrapped in another array with to_a, which results in `[[1, 2]]`.

I have attached the test case and a fix. The fix marks values returned by blocks are not packed.


---Files--------------------------------
fix.patch (2.18 KB)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:82098] [Ruby trunk Bug#13648] [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result
       [not found] <redmine.issue-13648.20170609161134@ruby-lang.org>
  2017-06-09 16:11 ` [ruby-core:81638] [Ruby trunk Bug#13648] [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result akihiko.odaki.4i
  2017-06-10 10:26 ` [ruby-core:81646] " nobu
@ 2017-07-18 12:42 ` nagachika00
  2 siblings, 0 replies; 3+ messages in thread
From: nagachika00 @ 2017-07-18 12:42 UTC (permalink / raw
  To: ruby-core

Issue #13648 has been updated by nagachika (Tomoyuki Chikanaga).

Backport changed from 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE

ruby_2_4 r59363 merged revision(s) 59056.

----------------------------------------
Bug #13648: [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result
https://bugs.ruby-lang.org/issues/13648#change-65838

* Author: akihikodaki (Akihiko Odaki)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0dev (2017-06-09 trunk 59052) [x86_64-linux]
* Backport: 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE
----------------------------------------
This test case ends up with the following result.

~~~ ruby
class Step
  include Enumerable
  attr_reader :current, :args

  def initialize(enum)
    @enum = enum
    @current = nil
    @args = nil
  end

  def each(*args)
    @args = args
    @enum.each do |v|
      @current = v
      if v.is_a? Enumerable
        yield *v
      else
        yield v
      end
    end
  end
end

a = Step.new([[1, 2]])
assert_equal([[[1, 2]]], a.lazy.map {|*args| args}.map {|*args| args}.to_a)
~~~

~~~
<[[[1, 2]]]> expected but was
<[[1, 2]]>.
~~~

Here, `[[[1, 2]]]` is expected because:

* An array should be created with the first map, which results in `[1, 2]`.
* The array should be wrapped in another array with the second map, which results in `[[1, 2]]`.
* The array should be wrapped in another array with to_a, which results in `[[[1, 2]]]`.

However, it returns `[[1, 2]]` because:

* An array will be created with the first map, which results in `[1, 2]`.
* However, the array will be internally considered as "packed" and the unpacked arguments will be passed to the second map.
* The second map wraps them into another array, which results in `[1, 2]`.
* The array will be wrapped in another array with to_a, which results in `[[1, 2]]`.

I have attached the test case and a fix. The fix marks values returned by blocks are not packed.


---Files--------------------------------
fix.patch (2.18 KB)


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-18 12:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-13648.20170609161134@ruby-lang.org>
2017-06-09 16:11 ` [ruby-core:81638] [Ruby trunk Bug#13648] [PATCH] Nested map of Enumerator::Lazy with packed values gives wrong result akihiko.odaki.4i
2017-06-10 10:26 ` [ruby-core:81646] " nobu
2017-07-18 12:42 ` [ruby-core:82098] " nagachika00

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).