From: "johnnyshields (Johnny Shields) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "johnnyshields (Johnny Shields)" <noreply@ruby-lang.org>
Subject: [ruby-core:120619] [Ruby master Bug#21030] Bug: #step with Range<ActiveSupport::Duration> behavior broken on Ruby 3.4.1
Date: Sun, 12 Jan 2025 05:59:43 +0000 (UTC) [thread overview]
Message-ID: <redmine.issue-21030.20250112055943.10741@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-21030.20250112055943.10741@ruby-lang.org>
Issue #21030 has been reported by johnnyshields (Johnny Shields).
----------------------------------------
Bug #21030: Bug: #step with Range<ActiveSupport::Duration> behavior broken on Ruby 3.4.1
https://bugs.ruby-lang.org/issues/21030
* Author: johnnyshields (Johnny Shields)
* Status: Open
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Issue also filed at: https://github.com/rails/rails/issues/54199
### System configuration
**Rails version**: 7.1.5.1
**Ruby version**: 3.3.4 (works) vs 3.4.1 (broken)
### What's broken
Calling `#step` then `#to_a` on a `Range` whose beginning/end values are the same is expected to return an `Array` wrapping the `Range`'s singular value. In other words, `(x..x).step(n).to_a` should return `[x]` -- note this is also the same as `(x..x).to_a`
The following case breaks on Ruby 3.4.1 related to `ActiveSupport::Duration` class, where it returns an empty array. It works on Ruby 3.3. Both tested with Rails 7.1.5.1. It's very easy to reproduce.
I'm unsure if this is a Ruby bug or a Rails bug so I'm filing it in both places. The upgrade of Ruby is what produces the difference.
```ruby
require 'active_support/all' # version 7.1.5.1
int = 100
dur = 100.seconds # ActiveSupport/Duration
# The bug
(dur..dur).step(10).to_a # => Ruby 3.3 returns [100 seconds] - CORRECT
# => Ruby 3.4 returns [] - INCORRECT
(int..dur).step(10).to_a # => Ruby 3.3 returns [100] - CORRECT
# => Ruby 3.4 returns [] - INCORRECT
# Note the following cases work correctly on both Ruby versions:
(int..int).step(10).to_a #=> [100]
(int..dur).to_a #=> [100]
# Range with non-equivalent values also works fine on different versions:
dur2 = 120.seconds
(dur..dur2).step(10).to_a #=> [100 seconds, 110 seconds, 120 seconds]
(int..dur2).step(10).to_a #=> [100, 110, 120]
```
--
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/
next parent reply other threads:[~2025-01-12 5:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-12 5:59 johnnyshields (Johnny Shields) via ruby-core [this message]
2025-01-12 8:21 ` [ruby-core:120622] " zverok (Victor Shepelev) via ruby-core
2025-01-12 8:23 ` [ruby-core:120623] " zverok (Victor Shepelev) via ruby-core
2025-01-12 23:15 ` [ruby-core:120625] " johnnyshields (Johnny Shields) via ruby-core
2025-01-13 1:22 ` [ruby-core:120626] " nobu (Nobuyoshi Nakada) via ruby-core
2025-02-11 5:26 ` [ruby-core:120936] " johnnyshields (Johnny Shields) via ruby-core
2025-02-20 19:26 ` [ruby-core:121135] " jamesst20 (James St-Pierre) via ruby-core
2025-03-03 23:06 ` [ruby-core:121227] " k0kubun (Takashi Kokubun) via ruby-core
2025-05-05 18:44 ` [ruby-core:121831] [Ruby " jamesst20 (James St-Pierre) via ruby-core
2025-05-05 20:09 ` [ruby-core:121833] " Eregon (Benoit Daloze) via ruby-core
2025-05-05 21:26 ` [ruby-core:121834] " johnnyshields (Johnny Shields) via ruby-core
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-21030.20250112055943.10741@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).