* [ruby-core:92495] [Ruby trunk Feature#15813] Proposal: Add exception support in `Range#first`
[not found] <redmine.issue-15813.20190430145248@ruby-lang.org>
@ 2019-04-30 14:52 ` manga.osyo
2019-04-30 15:06 ` [ruby-core:92497] " mame
2019-04-30 15:10 ` [ruby-core:92498] " manga.osyo
2 siblings, 0 replies; 3+ messages in thread
From: manga.osyo @ 2019-04-30 14:52 UTC (permalink / raw)
To: ruby-core
Issue #15813 has been reported by osyo (manga osyo).
----------------------------------------
Feature #15813: Proposal: Add exception support in `Range#first`
https://bugs.ruby-lang.org/issues/15813
* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
## Current status
Calling `Range#last` in endless range(`(1..)`) raises an exception.
```ruby
# OK
p (1..Float::INFINITY).end # => Infinity
p (1..).end # => nil
p (1..Float::INFINITY).last # => Infinity
# NG: Raise error: in `last': cannot get the last element of endless range (RangeError)
p (1..).last
p (1..).last(1)
```
But, calling `Range#first` in beginless range(`(..1)`) does not raise an exception.
```ruby
# OK
p (-Float::INFINITY..1).begin # => -Infinity
p (..1).begin # => nil
p (-Float::INFINITY..1).first # => -Infinity
# OK: Does not raise
p (..1).first # => nil
# NG: Raise error: in `each': can't iterate from NilClass (TypeError)
p (..1).first(1)
```
I think the current situation is not consistent, so it is necessary to move the behavior to one side or the other.
Also, in the case of `Range#last`, an exception is explicitly raised.
see: https://github.com/ruby/ruby/blob/6a3165e19dfa21babfb2ef1f1c20c9930410b0ec/range.c#L1100-L1102
## Proposal
Added support to raise an exception for `Range#first` too.
### Before
```ruby
# OK
p (-Float::INFINITY..10).begin # => -Infinity
p (..10).begin # => nil
p (-Float::INFINITY..10).first # => -Infinity
p (..10).first # => nil
p Range.new(nil, 10).first # => nil
# NG: Raise error: in `each': can't iterate from NilClass (TypeError)
p (..10).first(1)
```
### After
```ruby
# OK
p (-Float::INFINITY..10).begin # => -Infinity
p (..10).begin # => nil
p (-Float::INFINITY..10).first # => -Infinity
# NG: Raise error: in `first': cannot get the first element of beginless range (RangeError)
p (..10).first
p Range.new(nil, 10).first
p (..10).first(1)
# in Ruby 2.6.1
p Range.new(nil, 10).first
# Error: in `initialize': bad value for range (ArgumentError)
```
Thank you.
pull request : https://github.com/ruby/ruby/pull/2163
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:92497] [Ruby trunk Feature#15813] Proposal: Add exception support in `Range#first`
[not found] <redmine.issue-15813.20190430145248@ruby-lang.org>
2019-04-30 14:52 ` [ruby-core:92495] [Ruby trunk Feature#15813] Proposal: Add exception support in `Range#first` manga.osyo
@ 2019-04-30 15:06 ` mame
2019-04-30 15:10 ` [ruby-core:92498] " manga.osyo
2 siblings, 0 replies; 3+ messages in thread
From: mame @ 2019-04-30 15:06 UTC (permalink / raw)
To: ruby-core
Issue #15813 has been updated by mame (Yusuke Endoh).
Merged at 4e88e8692844a2a317bc19481f0f2601b6f00955. Thank you.
----------------------------------------
Feature #15813: Proposal: Add exception support in `Range#first`
https://bugs.ruby-lang.org/issues/15813#change-77857
* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
## Current status
Calling `Range#last` in endless range(`(1..)`) raises an exception.
```ruby
# OK
p (1..Float::INFINITY).end # => Infinity
p (1..).end # => nil
p (1..Float::INFINITY).last # => Infinity
# NG: Raise error: in `last': cannot get the last element of endless range (RangeError)
p (1..).last
p (1..).last(1)
```
But, calling `Range#first` in beginless range(`(..1)`) does not raise an exception.
```ruby
# OK
p (-Float::INFINITY..1).begin # => -Infinity
p (..1).begin # => nil
p (-Float::INFINITY..1).first # => -Infinity
# OK: Does not raise
p (..1).first # => nil
# NG: Raise error: in `each': can't iterate from NilClass (TypeError)
p (..1).first(1)
```
I think the current situation is not consistent, so it is necessary to move the behavior to one side or the other.
Also, in the case of `Range#last`, an exception is explicitly raised.
see: https://github.com/ruby/ruby/blob/6a3165e19dfa21babfb2ef1f1c20c9930410b0ec/range.c#L1100-L1102
## Proposal
Added support to raise an exception for `Range#first` too.
### Before
```ruby
# OK
p (-Float::INFINITY..10).begin # => -Infinity
p (..10).begin # => nil
p (-Float::INFINITY..10).first # => -Infinity
p (..10).first # => nil
p Range.new(nil, 10).first # => nil
# NG: Raise error: in `each': can't iterate from NilClass (TypeError)
p (..10).first(1)
```
### After
```ruby
# OK
p (-Float::INFINITY..10).begin # => -Infinity
p (..10).begin # => nil
p (-Float::INFINITY..10).first # => -Infinity
# NG: Raise error: in `first': cannot get the first element of beginless range (RangeError)
p (..10).first
p Range.new(nil, 10).first
p (..10).first(1)
# in Ruby 2.6.1
p Range.new(nil, 10).first
# Error: in `initialize': bad value for range (ArgumentError)
```
Thank you.
pull request : https://github.com/ruby/ruby/pull/2163
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:92498] [Ruby trunk Feature#15813] Proposal: Add exception support in `Range#first`
[not found] <redmine.issue-15813.20190430145248@ruby-lang.org>
2019-04-30 14:52 ` [ruby-core:92495] [Ruby trunk Feature#15813] Proposal: Add exception support in `Range#first` manga.osyo
2019-04-30 15:06 ` [ruby-core:92497] " mame
@ 2019-04-30 15:10 ` manga.osyo
2 siblings, 0 replies; 3+ messages in thread
From: manga.osyo @ 2019-04-30 15:10 UTC (permalink / raw)
To: ruby-core
Issue #15813 has been updated by osyo (manga osyo).
Thanks!!!!!!!
----------------------------------------
Feature #15813: Proposal: Add exception support in `Range#first`
https://bugs.ruby-lang.org/issues/15813#change-77859
* Author: osyo (manga osyo)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
## Current status
Calling `Range#last` in endless range(`(1..)`) raises an exception.
```ruby
# OK
p (1..Float::INFINITY).end # => Infinity
p (1..).end # => nil
p (1..Float::INFINITY).last # => Infinity
# NG: Raise error: in `last': cannot get the last element of endless range (RangeError)
p (1..).last
p (1..).last(1)
```
But, calling `Range#first` in beginless range(`(..1)`) does not raise an exception.
```ruby
# OK
p (-Float::INFINITY..1).begin # => -Infinity
p (..1).begin # => nil
p (-Float::INFINITY..1).first # => -Infinity
# OK: Does not raise
p (..1).first # => nil
# NG: Raise error: in `each': can't iterate from NilClass (TypeError)
p (..1).first(1)
```
I think the current situation is not consistent, so it is necessary to move the behavior to one side or the other.
Also, in the case of `Range#last`, an exception is explicitly raised.
see: https://github.com/ruby/ruby/blob/6a3165e19dfa21babfb2ef1f1c20c9930410b0ec/range.c#L1100-L1102
## Proposal
Added support to raise an exception for `Range#first` too.
### Before
```ruby
# OK
p (-Float::INFINITY..10).begin # => -Infinity
p (..10).begin # => nil
p (-Float::INFINITY..10).first # => -Infinity
p (..10).first # => nil
p Range.new(nil, 10).first # => nil
# NG: Raise error: in `each': can't iterate from NilClass (TypeError)
p (..10).first(1)
```
### After
```ruby
# OK
p (-Float::INFINITY..10).begin # => -Infinity
p (..10).begin # => nil
p (-Float::INFINITY..10).first # => -Infinity
# NG: Raise error: in `first': cannot get the first element of beginless range (RangeError)
p (..10).first
p Range.new(nil, 10).first
p (..10).first(1)
# in Ruby 2.6.1
p Range.new(nil, 10).first
# Error: in `initialize': bad value for range (ArgumentError)
```
Thank you.
pull request : https://github.com/ruby/ruby/pull/2163
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-30 15:11 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-15813.20190430145248@ruby-lang.org>
2019-04-30 14:52 ` [ruby-core:92495] [Ruby trunk Feature#15813] Proposal: Add exception support in `Range#first` manga.osyo
2019-04-30 15:06 ` [ruby-core:92497] " mame
2019-04-30 15:10 ` [ruby-core:92498] " manga.osyo
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).