D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18138 - non-shared method overload not accessible through interface
Summary: non-shared method overload not accessible through interface
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-28 11:23 UTC by Remi Thebault
Modified: 2024-12-13 18:55 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Remi Thebault 2017-12-28 11:23:28 UTC
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
}
Comment 1 Seb 2017-12-28 13:23:37 UTC
`i` isn't shared, but the method of the interface requires sharedness. Thus, the error is legit, imho.
Am I missing something?
Comment 2 Remi Thebault 2017-12-28 14:20:37 UTC
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.
Comment 3 dlangBugzillaToGithub 2024-12-13 18:55:51 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19356

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB