[Issue 18138] New: non-shared method overload not accessible through interface

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Dec 28 11:23:28 UTC 2017


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

          Issue ID: 18138
           Summary: non-shared method overload not accessible through
                    interface
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: remi.thebault at gmail.com

Consider the following program and error.
The compiler should not complain.

If ITest is merged with IAtomicTest, the error is gone.
At run-time, methods are correctly dispatched.


interface ITest {
    void method();
}

interface IAtomicTest : ITest {
    shared void method();
}

class AtomicTest : IAtomicTest {
    int member;
    override final shared void method() {
        import core.atomic : atomicOp;
        import std.stdio : writeln;
        auto m = atomicOp!"+="(member, 1);
        writeln("atomic: ", m);
    }
    override final void method() {
        import std.stdio : writeln;
        member += 1;
        writeln("non-atomic: ", member);
    }
}

void main()
{
    auto ao = new shared(AtomicTest);
    auto o = new AtomicTest;
    ao.method();    // fine
    o.method();     // fine

    auto ai = cast(shared(IAtomicTest))ao;
    auto i = cast(IAtomicTest)o;
    ai.method();    // fine
    (cast(ITest)i).method();  // fine
    i.method();     // Error: shared method app.IAtomicTest.method is not
callable using a non-shared object
}

--


More information about the Digitalmars-d-bugs mailing list