[Issue 10850] Inout substituted incorrectly for delegates/fptrs in inout function signature

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Sep 15 05:04:15 PDT 2014


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

Sobirari Muhomori <dfj1esp02 at sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |2573

--- Comment #11 from Sobirari Muhomori <dfj1esp02 at sneakemail.com> ---
Tests for binding:

1. Should pass:
---
struct S {
    int[] a;
    int opApply(scope int delegate(ref inout int) dg) inout {
        foreach(ref x;a) if(auto r=dg(x)) return r;
        return 0;
    }
}

void main() {
    auto s=S([1,2,3]);
    foreach(ref x;s) x++; // ok
}
---

2. Should not compile:
---
struct S {
    int[] a;
    int opApply(scope int delegate(ref inout int) dg) inout {
        foreach(ref x;a) if(auto r=dg(x)) return r;
        return 0;
    }
}

void main() {
    const(S) s=S([1,2,3]);
    foreach(ref x;s) {
        import std.stdio;
        writeln(x);
        x++; //error
    }
}
---

--


More information about the Digitalmars-d-bugs mailing list