[#120465] [Ruby master Bug#20998] rb_str_locktmp() changes flags of frozen strings and string literals — "Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Issue #20998 has been reported by Eregon (Benoit Daloze).
17 messages
2025/01/03
[ruby-core:120571] [Ruby master Bug#20980] Range#size new TypeError vs semi-open ranges
From:
"mame (Yusuke Endoh) via ruby-core" <ruby-core@...>
Date:
2025-01-09 11:42:00 UTC
List:
ruby-core #120571
Issue #20980 has been updated by mame (Yusuke Endoh).
Status changed from Open to Closed
The current behavior is intended. In principle, `#size` should return how many times `#each` will call a given block. (It could return nil as unknown.) Since beginless range does not respond to `#each`, it is now natural for `#size` to raise an exception. @naruse said he will try improving the document.
----------------------------------------
Bug #20980: Range#size new TypeError vs semi-open ranges
https://bugs.ruby-lang.org/issues/20980#change-111395
* Author: zverok (Victor Shepelev)
* Status: Closed
* ruby -v: ruby 3.4.0dev (2024-12-24T14:40:12Z master 07e89bde46) +PRISM [x86_64-linux]
* Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
----------------------------------------
Since #18984, `Range#size` throws `TypeError` if the `begin` is not iterable (doesn't respond to `#succ`). It produces one small inconvenience compared to 3.3:
```ruby
('a'..).size #=> nil
(..'a').size
# 3.3: nil
# 3.4: can't iterate from NilClass (TypeError) -- well, probably makes sense
# BUT:
(3..).size #=> Infinity -- cool!
(..3).size
# 3.3: Infinity -- reasonable?
# 3.4: can't iterate from NilClass (TypeError) -- worse?
```
I believe that while 3.4's behavior is explainable, 3.3's one has better DX.
(Obviously too late to change before the release, but maybe might be considered for some patch version or Ruby 3.5?..)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/