Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

non-shared method overload not accessible through interface #19356

Open
dlangBugzillaToGithub opened this issue Dec 28, 2017 · 2 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

Remi Thebault (@rtbo) reported this on 2017-12-28T11:23:28Z

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

CC List

  • Seb
  • ZombineDev

Description

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
}
@dlangBugzillaToGithub
Copy link
Author

greeenify commented on 2017-12-28T13:23:37Z

`i` isn't shared, but the method of the interface requires sharedness. Thus, the error is legit, imho.
Am I missing something?

@dlangBugzillaToGithub
Copy link
Author

remi.thebault commented on 2017-12-28T14:20:37Z

yes, but the ITest interface has a non-shared method, which is overloaded in IAtomicTest (IAtomicTest extends ITest), so the non-shared method should be visible too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant