[ruby-core:113060] [Ruby master Bug#19564] Range.cover? fails for Range wrapped in SimpleDelegator

Issue #19564 has been reported by PeteMichaud (Pete Michaud). ---------------------------------------- Bug #19564: Range.cover? fails for Range wrapped in SimpleDelegator https://bugs.ruby-lang.org/issues/19564 * Author: PeteMichaud (Pete Michaud) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby test 'built-in cover? method is broken for SimpleDelegator' do class TimeRangeDelegator < SimpleDelegator end t1 = Time.now t2 = t1+1.day t3 = t1+1.week r_long = t1..t3 r_short = t1..t2 assert r_long.cover?(r_short) #passes correctly, assert == true r_long_delegated = TimeRangeDelegator.new(r_long) r_short_delegated = TimeRangeDelegator.new(r_short) assert r_long_delegated.cover?(r_short_delegated) #fails incorrectly, assert == false end ``` -- https://bugs.ruby-lang.org/

Issue #19564 has been updated by jeremyevans0 (Jeremy Evans). I'm not sure if this is a bug. There are many other cases where wrapping an object in a delegate changes behavior (e.g. `if false` vs. `if SimpleDelegator.new(false)`). If we want to allow this to work, the most likely approach would be adding something like `Range#to_range`, and having `Range#cover?` try to use `to_range` to convert arguments if the arguments respond to `to_range`. I'm not sure the benefits of that are worth the costs. ---------------------------------------- Bug #19564: Range.cover? fails for Range wrapped in SimpleDelegator https://bugs.ruby-lang.org/issues/19564#change-102598 * Author: PeteMichaud (Pete Michaud) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby test 'built-in cover? method is broken for SimpleDelegator' do class TimeRangeDelegator < SimpleDelegator end t1 = Time.now t2 = t1+1.day t3 = t1+1.week r_long = t1..t3 r_short = t1..t2 assert r_long.cover?(r_short) #passes correctly, assert == true r_long_delegated = TimeRangeDelegator.new(r_long) r_short_delegated = TimeRangeDelegator.new(r_short) assert r_long_delegated.cover?(r_short_delegated) #fails incorrectly, assert == false end ``` -- https://bugs.ruby-lang.org/

Issue #19564 has been updated by matz (Yukihiro Matsumoto). I have a few ideas to address the issue, but all of them have significant side-effect. I don't think it's worth making `cover?` to support Delegators, despite those side effect. Matz. ---------------------------------------- Bug #19564: Range.cover? fails for Range wrapped in SimpleDelegator https://bugs.ruby-lang.org/issues/19564#change-102758 * Author: PeteMichaud (Pete Michaud) * Status: Open * Priority: Normal * ruby -v: ruby 3.2.0 (2022-12-25 revision a528908271) [x86_64-darwin22] * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN ---------------------------------------- ```ruby test 'built-in cover? method is broken for SimpleDelegator' do class TimeRangeDelegator < SimpleDelegator end t1 = Time.now t2 = t1+1.day t3 = t1+1.week r_long = t1..t3 r_short = t1..t2 assert r_long.cover?(r_short) #passes correctly, assert == true r_long_delegated = TimeRangeDelegator.new(r_long) r_short_delegated = TimeRangeDelegator.new(r_short) assert r_long_delegated.cover?(r_short_delegated) #fails incorrectly, assert == false end ``` -- https://bugs.ruby-lang.org/
participants (3)
-
jeremyevans0 (Jeremy Evans)
-
matz (Yukihiro Matsumoto)
-
PeteMichaud (Pete Michaud)