ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109834] [Ruby master Bug#18994] Range#last(n) returns empty for single-element Integer Range
@ 2022-09-03 15:20 masasakano (Masa Sakano)
  2022-09-04  7:49 ` [ruby-core:109839] " byroot (Jean Boussier)
  2022-10-23 10:41 ` [ruby-core:110489] " nagachika (Tomoyuki Chikanaga)
  0 siblings, 2 replies; 3+ messages in thread
From: masasakano (Masa Sakano) @ 2022-09-03 15:20 UTC (permalink / raw)
  To: ruby-core

Issue #18994 has been reported by masasakano (Masa Sakano).

----------------------------------------
Bug #18994: Range#last(n) returns empty for single-element Integer Range
https://bugs.ruby-lang.org/issues/18994

* Author: masasakano (Masa Sakano)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
`Range#last(n)` with a single-element of Integer returns an empty Array. It should return a one-element Array.

Interestingly, when the element is a String, `last(n)` returns a one-element Array, expectedly.

I have checked the behaviour with some selected past versions of Ruby. In up to Ruby-2.6.5, it worked correctly. In Ruby-2.7.0, it doesn't. Nor in Ruby-3, including the current version (Ruby-3.1.2).

The following demonstrates the behaviour (Ruby-3.1.2; same in Ruby-2.7.0). Only the first one does not work in the way it should.

```ruby
(8..8).last(1)        # => []  (!!) (should be: [8])
(8..8).to_a.last(1)   # => [8]
(8..8).first(1)       # => [8]
(?a..?a).last(1)      #=> ["a"]
(?a..?a).to_a.last(1) #=> ["a"]
(?a..?a).first(1)     #=> ["a"]
```




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

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

* [ruby-core:109839] [Ruby master Bug#18994] Range#last(n) returns empty for single-element Integer Range
  2022-09-03 15:20 [ruby-core:109834] [Ruby master Bug#18994] Range#last(n) returns empty for single-element Integer Range masasakano (Masa Sakano)
@ 2022-09-04  7:49 ` byroot (Jean Boussier)
  2022-10-23 10:41 ` [ruby-core:110489] " nagachika (Tomoyuki Chikanaga)
  1 sibling, 0 replies; 3+ messages in thread
From: byroot (Jean Boussier) @ 2022-09-04  7:49 UTC (permalink / raw)
  To: ruby-core

Issue #18994 has been updated by byroot (Jean Boussier).

Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.7: WONTFIX, 3.0: REQUIRED, 3.1: REQUIRED

Thanks, I have a patch for it: https://github.com/ruby/ruby/pull/6324

----------------------------------------
Bug #18994: Range#last(n) returns empty for single-element Integer Range
https://bugs.ruby-lang.org/issues/18994#change-99076

* Author: masasakano (Masa Sakano)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
* Backport: 2.7: WONTFIX, 3.0: REQUIRED, 3.1: REQUIRED
----------------------------------------
`Range#last(n)` with a single-element of Integer returns an empty Array. It should return a one-element Array.

Interestingly, when the element is a String, `last(n)` returns a one-element Array, expectedly.

I have checked the behaviour with some selected past versions of Ruby. In up to Ruby-2.6.5, it worked correctly. In Ruby-2.7.0, it doesn't. Nor in Ruby-3, including the current version (Ruby-3.1.2).

The following demonstrates the behaviour (Ruby-3.1.2; same in Ruby-2.7.0). Only the first one does not work in the way it should.

```ruby
(8..8).last(1)        # => []  (!!) (should be: [8])
(8..8).to_a.last(1)   # => [8]
(8..8).first(1)       # => [8]
(?a..?a).last(1)      #=> ["a"]
(?a..?a).to_a.last(1) #=> ["a"]
(?a..?a).first(1)     #=> ["a"]
```




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

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

* [ruby-core:110489] [Ruby master Bug#18994] Range#last(n) returns empty for single-element Integer Range
  2022-09-03 15:20 [ruby-core:109834] [Ruby master Bug#18994] Range#last(n) returns empty for single-element Integer Range masasakano (Masa Sakano)
  2022-09-04  7:49 ` [ruby-core:109839] " byroot (Jean Boussier)
@ 2022-10-23 10:41 ` nagachika (Tomoyuki Chikanaga)
  1 sibling, 0 replies; 3+ messages in thread
From: nagachika (Tomoyuki Chikanaga) @ 2022-10-23 10:41 UTC (permalink / raw)
  To: ruby-core

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

Backport changed from 2.7: WONTFIX, 3.0: REQUIRED, 3.1: REQUIRED to 2.7: WONTFIX, 3.0: REQUIRED, 3.1: DONE

ruby_3_1 941c888b041decb45034572d766120f9be34986e merged revision(s) bbe5ec78463f8d6ef2e1a3571f17357a3d9ec8e4.

----------------------------------------
Bug #18994: Range#last(n) returns empty for single-element Integer Range
https://bugs.ruby-lang.org/issues/18994#change-99810

* Author: masasakano (Masa Sakano)
* Status: Closed
* Priority: Normal
* ruby -v: ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
* Backport: 2.7: WONTFIX, 3.0: REQUIRED, 3.1: DONE
----------------------------------------
`Range#last(n)` with a single-element of Integer returns an empty Array. It should return a one-element Array.

Interestingly, when the element is a String, `last(n)` returns a one-element Array, expectedly.

I have checked the behaviour with some selected past versions of Ruby. In up to Ruby-2.6.5, it worked correctly. In Ruby-2.7.0, it doesn't. Nor in Ruby-3, including the current version (Ruby-3.1.2).

The following demonstrates the behaviour (Ruby-3.1.2; same in Ruby-2.7.0). Only the first one does not work in the way it should.

```ruby
(8..8).last(1)        # => []  (!!) (should be: [8])
(8..8).to_a.last(1)   # => [8]
(8..8).first(1)       # => [8]
(?a..?a).last(1)      #=> ["a"]
(?a..?a).to_a.last(1) #=> ["a"]
(?a..?a).first(1)     #=> ["a"]
```




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

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

end of thread, other threads:[~2022-10-23 10:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-03 15:20 [ruby-core:109834] [Ruby master Bug#18994] Range#last(n) returns empty for single-element Integer Range masasakano (Masa Sakano)
2022-09-04  7:49 ` [ruby-core:109839] " byroot (Jean Boussier)
2022-10-23 10:41 ` [ruby-core:110489] " nagachika (Tomoyuki Chikanaga)

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).