https://issues.dlang.org/show_bug.cgi?id=17567
Issue ID: 17567 Summary: make shared methods callable on unshared objects (and covariant) Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P3 Component: dmd Assignee: nob...@puremagic.com Reporter: c...@dawg.eu cat > bug.d << CODE struct S { void func() shared {} } void bug() { S s; s.func; } dmd -c bug ---- bug.d(9): Error: shared method bug.S.func is not callable using a non-shared object ---- cat > bug2.d << CODE interface I { void func(); } class C : I { void func() shared {} } CODE dmd -c bug ---- bug.d(5): Error: class bug.C interface function 'void func()' is not implemented ---- Both of these use-cases should be supported. Shared on a methods guarantees thread-safety which is compatible with being used in an unshared manner. Therefor shared methods should be fully covariant to unshared methods. This does not touch shared as type qualifier, `shared(T)` means the type is shared between threads, and hence is obviously not convertible to `T`. Looks like this would be the first storage class where we'd support covariance and real overloading. While overloading, e.g. `nothrow` and non-`nothrow` methods is not an error, the compiler always prefers `nothrow`, `pure`, `@safe`, or `@nogc` methods. But overloading should prefer unshared methods over `shared` ones, e.g. because the methods might avoid using a mutex. --