www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22145] New: Wrong error message when `scope` errors are


          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 puremagic.com
          Reporter: pro.mathias.lang 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`

Jul 25 2021