February 25, 2023
https://issues.dlang.org/show_bug.cgi?id=23739

          Issue ID: 23739
           Summary: Can't return by ref from opApply iteration
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody@puremagic.com
          Reporter: timon.gehr@gmx.ch

DMD 2.102.1:

---
struct S{
    int x;
    int opApply(scope int delegate(ref int x) dg){
        return dg(x);
    }
}

ref int foo(ref S s){
    foreach(x;s)
        return x;
    assert(0);
}

void main(){
    auto s=new S;
    assert(&foo(*s) is &s.x); // fail
}
---

The assertion should pass.

--