[Issue 2051] interfaces should allow private methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 28 09:27:04 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2051





------- Comment #4 from andrei at metalanguage.com  2008-04-28 11:27 -------
(In reply to comment #2)
> By the current D spec private functions are never virtual. I'm pretty sure
> that's why having a private function in an interface won't work.

That explains part of the odd behavior - the compiler has a conflict of
interest of sorts. 

Now that I think of it, probably protected functions in an interface should be
enough. Consider:

interface Foo
{
    protected void bar();
}

class Bar : Foo
{
    void bar() {}
}

void main()
{
    Foo bar = new Bar;
    bar.bar;
}

This goes through, and is probably enough to make NVI work. There is the minor
annoyance that the class Bar can graduate visibility from protected to public,
but if it wants to, no language rule can stop it (e.g. Bar could expose the
method under a different name).

I will leave the bug opened because at a minimum the linker error should be
really a compile-time error. Alternatively, private functions in interfaces
could be allowed because they are technically final. Thanks all for your
comments.


-- 



More information about the Digitalmars-d-bugs mailing list