[Issue 22145] New: Wrong error message when `scope` errors are detected in foreach body

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 26 03:30:07 UTC 2021


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

          Issue ID: 22145
           Summary: Wrong error message when `scope` errors are detected
                    in foreach body
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: pro.mathias.lang at gmail.com

Using HEAD as of July 26th (67132039c4c792d7722daeb9bef0a305e2f74fb1).

```
int* global;

struct Foo {
    int opApply (scope int delegate (scope int* ptr) @safe dg) @safe
    {
        return 0;
    }
}

void main () @safe
{
    Foo f;
    foreach (scope int* x; f) {
        global = x;
    }
}
```

Compiled with `-dip1000`, it should complain that the assignment violates
`scope`, but currently we get:
```
foreach.d(13): Error: function `foreach.Foo.opApply(scope int delegate(scope
int* ptr) @safe dg)` is not callable using argument types `(int delegate(int*
x) nothrow @nogc @safe)`
foreach.d(13):        cannot pass argument `__foreachbody2` of type `int
delegate(int* x) nothrow @nogc @safe` to parameter `scope int delegate(scope
int* ptr) @safe dg`
```

--


More information about the Digitalmars-d-bugs mailing list