Usability of "allMembers and derivedMembers traits now only return visible symbols"

Martin Nowak via Digitalmars-d digitalmars-d at puremagic.com
Sat Sep 3 09:37:20 PDT 2016


On Wednesday, 31 August 2016 at 21:12:54 UTC, Ali Çehreli wrote:
> On 08/30/2016 03:24 PM, Ali Çehreli wrote:
> > v2.071.2-b3 is bringing a change for this bug:
> >
> >   https://issues.dlang.org/show_bug.cgi?id=15907
> >
> > I don't agree with the current solution:
> >
> > 
> http://dlang.org/changelog/2.071.2.html#traits-members-visibility
> >
> > Modules should be able to use library templates without
> needing to mix
> > them in first.
> >
> > Do you think the solution in the change log usable? I don't
> think so
> > because silently skipping my private members is an unexpected
> behavior
> > that will cause bugs.
>
> Here is a regression caused by the above change:
>
> interface I {
>     void foo();
>
> package:
>
>     void foo(int);
> }
>
> string how(alias Base, alias func)() {
>     return "";
> }
>
> import std.typecons;
> class C : AutoImplement!(I, how) {
> }

What this derives a class in std.typecons that implements the 
interface, and yes such a derived class can't override/implement 
package protected methods.
AutoImplement would also work better as mixin in order to 
instantiate the passed in how template in the original 
instantiation scope.

>
> void main() {
>     auto c = new C();
>     c.foo();
>     c.foo(42);    // COMPILATION ERROR:
> // deneme.o: In function `_Dmain':
> // deneme.d:(.text._Dmain+0x39): undefined reference to 
> `_D6deneme1I3fooMFiZv'

The missing interface method implementation should've give a 
compile error, please file a bug.

> The recommended solution of mixing in every template instance 
> is not a viable solution because that would effectively remove 
> IFTI from D. What a huge loss that would be. We can't afford 
> that.

Exaggeration won't help us to find good solutions. Remember that 
private fields never were accessible, so only some edge cases 
will be affected. The need for mixin templates will remain rare.


More information about the Digitalmars-d mailing list