ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
@ 2022-08-29 14:10 masasakano (Masa Sakano)
  2022-09-14 22:01 ` [ruby-core:109895] " thiagofm (Thiago Massa)
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: masasakano (Masa Sakano) @ 2022-08-29 14:10 UTC (permalink / raw)
  To: ruby-core

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

----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)


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

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

* [ruby-core:109895] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
  2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
@ 2022-09-14 22:01 ` thiagofm (Thiago Massa)
  2022-09-14 22:18 ` [ruby-core:109896] " thiagofm (Thiago Massa)
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: thiagofm (Thiago Massa) @ 2022-09-14 22:01 UTC (permalink / raw)
  To: ruby-core

Issue #18983 has been updated by thiagofm (Thiago Massa).

File 6378.patch added

I've fixed the bug on the attached patch.

It's my first time contributing to Ruby, so please let me know if anything is missing. I'm following the contribution guide on https://ruby-doc.org/core-3.1.1/doc/contributing_rdoc.html

Thanks!

----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983#change-99138

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)
6378.patch (1.37 KB)


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

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

* [ruby-core:109896] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
  2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
  2022-09-14 22:01 ` [ruby-core:109895] " thiagofm (Thiago Massa)
@ 2022-09-14 22:18 ` thiagofm (Thiago Massa)
  2022-09-16 17:48 ` [ruby-core:109920] " jeremyevans0 (Jeremy Evans)
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: thiagofm (Thiago Massa) @ 2022-09-14 22:18 UTC (permalink / raw)
  To: ruby-core

Issue #18983 has been updated by thiagofm (Thiago Massa).


Nevermind. Build failed.

----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983#change-99139

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)
6378.patch (1.37 KB)


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

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

* [ruby-core:109920] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
  2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
  2022-09-14 22:01 ` [ruby-core:109895] " thiagofm (Thiago Massa)
  2022-09-14 22:18 ` [ruby-core:109896] " thiagofm (Thiago Massa)
@ 2022-09-16 17:48 ` jeremyevans0 (Jeremy Evans)
  2022-10-20  4:32 ` [ruby-core:110428] " matz (Yukihiro Matsumoto)
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-09-16 17:48 UTC (permalink / raw)
  To: ruby-core

Issue #18983 has been updated by jeremyevans0 (Jeremy Evans).


Returning Infinity for numeric ranges bounded in either direction is expected (there are tests explicitly for it).

It does seem inconsistent that `(..object).size` returns Infinity and `(object..).size` returns nil for non-numeric objects.  I think returning nil in both cases makes sense.

----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983#change-99168

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)
6378.patch (1.37 KB)


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

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

* [ruby-core:110428] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
  2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
                   ` (2 preceding siblings ...)
  2022-09-16 17:48 ` [ruby-core:109920] " jeremyevans0 (Jeremy Evans)
@ 2022-10-20  4:32 ` matz (Yukihiro Matsumoto)
  2022-10-21  4:41 ` [ruby-core:110454] " mame (Yusuke Endoh)
  2022-10-21  4:41 ` [ruby-core:110455] " mame (Yusuke Endoh)
  5 siblings, 0 replies; 7+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-10-20  4:32 UTC (permalink / raw)
  To: ruby-core

Issue #18983 has been updated by matz (Yukihiro Matsumoto).


I agree with inconsistency; if edges were numeric, return the count (or Infinity), otherwise it should return nil.
`nil .. nil` can be considered as numeric-range both edge omitted, but at the moment I feel it should return nil as well.
Let us experiment how it works.

Matz.


----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983#change-99738

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)
6378.patch (1.37 KB)


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

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

* [ruby-core:110454] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
  2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
                   ` (3 preceding siblings ...)
  2022-10-20  4:32 ` [ruby-core:110428] " matz (Yukihiro Matsumoto)
@ 2022-10-21  4:41 ` mame (Yusuke Endoh)
  2022-10-21  4:41 ` [ruby-core:110455] " mame (Yusuke Endoh)
  5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) @ 2022-10-21  4:41 UTC (permalink / raw)
  To: ruby-core

Issue #18983 has been updated by mame (Yusuke Endoh).


https://github.com/ruby/ruby/pull/6604

----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983#change-99770

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)
6378.patch (1.37 KB)


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

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

* [ruby-core:110455] [Ruby master Bug#18983] Range#size for beginless Range is not nil.
  2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
                   ` (4 preceding siblings ...)
  2022-10-21  4:41 ` [ruby-core:110454] " mame (Yusuke Endoh)
@ 2022-10-21  4:41 ` mame (Yusuke Endoh)
  5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) @ 2022-10-21  4:41 UTC (permalink / raw)
  To: ruby-core

Issue #18983 has been updated by mame (Yusuke Endoh).


Oops, I missed the attached patch. Sorry

----------------------------------------
Bug #18983: Range#size for beginless Range is not nil.
https://bugs.ruby-lang.org/issues/18983#change-99771

* 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#size` should, according to [Official docs](https://ruby-doc.org/core-3.1.2/Range.html#method-i-size),

> Returns the count of elements in self if both begin and end values are numeric; otherwise, returns nil

but it doesn't with beginless non-Numeric Ranges (in Ruby-3.1.2 or earlier).

```ruby
(..?a).size      # => Infinity
(nil..nil).size  # => Infinity
```

whereas it certainly does with endless Ranges

```ruby
(?a..).size      # => nil
```


---Files--------------------------------
bug-20220829-beginless_range.rb (1.24 KB)
6378.patch (1.37 KB)


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

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 14:10 [ruby-core:109770] [Ruby master Bug#18983] Range#size for beginless Range is not nil masasakano (Masa Sakano)
2022-09-14 22:01 ` [ruby-core:109895] " thiagofm (Thiago Massa)
2022-09-14 22:18 ` [ruby-core:109896] " thiagofm (Thiago Massa)
2022-09-16 17:48 ` [ruby-core:109920] " jeremyevans0 (Jeremy Evans)
2022-10-20  4:32 ` [ruby-core:110428] " matz (Yukihiro Matsumoto)
2022-10-21  4:41 ` [ruby-core:110454] " mame (Yusuke Endoh)
2022-10-21  4:41 ` [ruby-core:110455] " mame (Yusuke Endoh)

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