September 12, 2023
https://issues.dlang.org/show_bug.cgi?id=24143

          Issue ID: 24143
           Summary: Chain unreachable code
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: phobos
          Assignee: nobody@puremagic.com
          Reporter: james.gray@remss.net

Compiled with -w the code:

import std;

void main() {
 auto x = only(1).chain(repeat(2));
}

gives the following errors:


/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(1010): Warning:
statement is not reachable
/dlang/dmd/linux/bin64/../../src/phobos/std/range/package.d(1011): Warning:
statement is not reachable
Error: warnings are treated as errors
       Use -wi if you wish to treat warnings only as informational.


So does the following where I have isolated chain:



import std.range : chain;

struct RepeatOne {
    enum empty = false;
    const front = 1;
    const back = 1;
    void popFront() {}
    void popBack() {}
    auto save() { return RepeatOne.init; }
}

struct OnlyOne {
    bool empty = true;
    auto front = 1;
    auto back = 1;
    void popFront() { empty=false; }
    void popBack() { empty=false; }
    auto save() { return typeof(this)(this.tupleof); }

}

void main() {
        auto x = OnlyOne.init.chain(RepeatOne.init);
}

--