[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
SXNzdWUgIzE4MjI4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku
11 messages
2021/09/27
[ruby-core:105183] [Ruby master Bug#18155] (nil..nil).cover?(x) is true for all x since beginless ranges were introduced
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2021-09-09 01:16:09 UTC
List:
ruby-core #105183
Issue #18155 has been updated by jeremyevans0 (Jeremy Evans).
I'm definitely against option 3. It would break backwards compatibility for code that expects Ruby 2.7 behavior:
```ruby
start = params['start']
finish = params['finish']
(start..finish).cover? obj.modified_date
```
There are libraries that at least have tests for ranges unbounded in both directions (Sequel does, I would guess Rails does as well), and those would break if option 3 was taken.
I'm fine with the current behavior, and don't consider it a bug. I'm not strongly against option 2, though.
----------------------------------------
Bug #18155: (nil..nil).cover?(x) is true for all x since beginless ranges were introduced
https://bugs.ruby-lang.org/issues/18155#change-93587
* Author: urbanautomaton (Simon Coffey)
* Status: Open
* Priority: Normal
* ruby -v: 2.7.0 and greater
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
### Description
The introduction of beginless ranges in #14799 changed the behaviour of `Range#cover?` when both the beginning and the end of a `Range` are `nil`. Previously such a range would cover no values; now it covers all values:
```
irb-2.6.6> (nil..nil).cover?("23 dogs")
=> false
irb-2.7.0> (nil..nil).cover?("23 dogs")
=> true
```
This change was [noted at the time](https://bugs.ruby-lang.org/issues/14799#note-12), but it was believed that the call would have previously raised an error instead of returning `false`. I've not exhaustively checked, but the old behaviour goes back to at least ruby 2.2.
### Discussion
I'm not sure that either of these results are "correct", since I'm not sure that the concept of a range with no beginning or end is meaningful. Without either parameter, it seems impossible to infer the values it ranges over, since we have no type information available.
However, I did find both the current result and the change in behaviour quite surprising, so I've opened this issue.
Some options I considered:
1. **Do nothing:** a beginless-and-endless range is unbounded in both value and type, so covers all values of all types
2. **Reinstate the old behaviour:** a beginless-and-endless range has no type, so covers no values
3. **Raise an error:** a beginless-and-endless range is meaningless, so constructing one should raise an error
My personal preference is option 3, but I can clearly see that it represents the most effort. I'd welcome people's thoughts; if option 1 is preferred, I'd be happy to contribute a documentation patch to make the new behaviour clear.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>