www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18560] New: find on infinite ranges is broken


          Issue ID: 18560
           Summary: find on infinite ranges is broken
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: default_357-line yahoo.de


assert(true.repeat.all != false);

We may expect this to hang indefinitely. We will certainly not expect it to
fail immediately!

What happens is this.

true.repeat is an infinite range. all searches for a place at which its
condition becomes false. For this, it employs find. Find uses "empty" to signal
success, ie.  it returns an empty range if the element was not found. However,
in this case find *cannot* return an empty range because the Repeat range type
can never be empty. It compiles anyways. This then leads to .empty concluding,
correctly, that find may never return an empty range, and immediately, without
evaluating its input range, returning false.

Either all must not be implemented on top of find, or find must be adjusted to
signal failure in some other way, possibly using a VariantN.

Mar 06 2018