[Issue 15859] New: opApply resolution on attributes

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Apr 1 02:01:39 PDT 2016


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

          Issue ID: 15859
           Summary: opApply resolution on attributes
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: qs.il.paperinik at gmail.com

Simple as that, shouldn't this work?

The versions of opApply only differ in the attributes the delegate has.

struct X
{
    int opApply(int delegate(string) dg)
    {
        return dg("impure");
    }

    int opApply(int delegate(string) pure dg) pure
    {
        return dg("pure");
    }
}

void main()
{
    X x;
    string result;

    x.opApply(
        (string s)
        {
            result = s;
            return 0;
        }
    );
    writeln(result); // does compile and prints "pure".

    x.opApply(
        (string s)
        {
            result = s;
            write("");
            return 0;
        }
    );
    writeln(result); // does compile and prints "impure".

    /+ (1)
    foreach (string s; x)
    {
        result = s;
    }
    writeln(result); // does not compile: x.opApply matches more than one
declaration
    +/
    /+ (2)
    foreach (string s; x)
    {
        result = s;
        write("");
    }
    writeln(result); // does not compile: x.opApply matches more than one
declaration
    +/
}

--


More information about the Digitalmars-d-bugs mailing list