[#81492] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid — normalperson@...

Issue #13618 has been reported by normalperson (Eric Wong).

12 messages 2017/06/01

[ruby-core:81847] [Ruby trunk Bug#13700] Enumerable#sum may not work for Ranges subclasses due to optimization

From: mail@...
Date: 2017-06-30 09:05:46 UTC
List: ruby-core #81847
Issue #13700 has been reported by sos4nt (Stefan Schテシテ殕er).

----------------------------------------
Bug #13700: Enumerable#sum may not work for Ranges subclasses due to optimization
https://bugs.ruby-lang.org/issues/13700

* Author: sos4nt (Stefan Schテシテ殕er)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
`Enumerable#sum` is optimized for integer ranges. Unfortunately, this can break subclasses:

```ruby
class StepTwoRange < Range
  def each(&block)
    step(2, &block)
  end
end

r = StepTwoRange.new(0, 10)
r.to_a     #=> [0, 2, 4, 6, 8, 10]

r.to_a.sum #=> 30
r.sum      #=> 55
```

The optimization should therefore only be triggered for instances of `Range` and not for instances of subclasses.



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

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next