www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19422] New: Associative arrays break inference of safe,

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

          Issue ID: 19422
           Summary: Associative arrays break inference of  safe, nothrow,
                    pure
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: stanislav.blinov gmail.com

struct S {
    int x;

    this(this) {
        /* do  system stuff... */
        import std.stdio;
        writeln("copy");
    }
const:
    bool opEquals(S rhs) { return x == rhs.x; }
    size_t toHash() { return hashOf(x); }
}

void testS()  safe nothrow pure {
    S a;
    auto b = a;
    a.opEquals(b);
    auto h = a.toHash();
}

void testAA()  safe nothrow pure {
    int[S] aa;
    S key;
    aa[key] = 0;
}

testS() will not compile since neither postblit, nor opEquals or toHash satisfy
the attributes.

But testAA() compiles, even though the AA implementation calls all the same
functions.

--
Nov 22 2018