[Issue 2524] final override inconsistent when implementing interfaces

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 21 03:47:54 PST 2009


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





------- Comment #12 from smjg at iname.com  2009-01-21 05:47 -------
(In reply to comment #10)
> But I can still cast to the interface.  Protection attributes are compile-time
> entities, they are not flagged at runtime:
> 
> SoundManager s;
> Object o = s;
> 
> INetworkListener inl = cast(INetworkListener)o;
> 
> The compiler just looks in the object's list of interfaces to see if it finds
> that interface.  There is no protection associated with it at runtime.

But the compiler is capable of checking to see whether the inheritance is
public or private.  It just doesn't at the moment.  No runtime protection
checking needed in this instance.

> What you are asking for requires a major compiler redesign for limited value. 

I still think this "major compiler redesign" should be removing inheritance
protection altogether.  Which would have the value of simplifying the language
by getting rid of these things that don't make sense.

(In reply to comment #11)
> So what? How does this differ from the following in C++:
> 
> class A {
>     void foo();
> }
> 
> class B : protected A {
> }
> 
> B* b = new B();
> //b->foo(); // error
> //A* a = b; // error
> void* o = b;
> A* a = (A*)o;
> a->foo();

Firstly, try putting your code through a C++ compiler.

Secondly, your code goes through void*, whereby it's obvious that you're intent
on subverting the type system.  Moreover, it may break if multiple inheritance
is involved.

That said, as I try it C++ allows the cast straight from B* to A*, but it must
be explicit.


-- 



More information about the Digitalmars-d-bugs mailing list