Project

General

Profile

Actions

Feature #16350

open

ArithmeticSequence#member? can result in infinite loop

Added by parker (Parker Finch) over 4 years ago. Updated almost 4 years ago.

Status:
Assigned
Target version:
-
[ruby-core:95864]
Tags:

Description

I'm not sure if this is a bug or a feature, it feels somewhere in between.

This is my first time contributing to the Ruby code, let me know what I can improve in this report!

ArithmeticSequence#member? enumerates through the sequence in order to determine if an element is included. (It just uses Enumerable#member?.) This leads to an infinite loop if the sequence is infinite and the element is not included, such as 1.step.member?(0).

I expected 1.step.member?(0) to return false.

Since ArithmeticSequences are much more constrained than regular Enumerables, the #member? method can be overridden to efficiently determine if an element is included in the sequence.

I started implementing this change (patch attached) but got a little confused when trying to handle floats. Before digging in too deeply, I wanted to check if this is a change that will be accepted.

Let me know if I should keep looking into this!


Files

0001-Start-implementing-ArithmeticSequence-member.patch (3.96 KB) 0001-Start-implementing-ArithmeticSequence-member.patch patch (unfinished implementation, tests currently fail) parker (Parker Finch), 11/16/2019 05:10 PM

Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to mrkn (Kenta Murata)
Actions #2

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

  • Tracker changed from Bug to Feature
  • ruby -v deleted (ruby 2.7.0dev)
  • Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0