[Issue 23116] New: foreach with opApply infer ref when opApply delegate is templated

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 16 16:43:48 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23116

          Issue ID: 23116
           Summary: foreach with opApply infer ref when opApply delegate
                    is templated
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: contact at lsferreira.net

For the following code:

```
struct S {
        int opApply(Dg)(scope Dg dg)
        {
                return dg(1);
        }
}

int main()
{
        foreach(int i; S())
        {
                return i;
        }

        return 0;
}
```

The compiler interprets this as:
```
foreach(ref int i; S())
```

Which is wrongly inferred.

--


More information about the Digitalmars-d-bugs mailing list