[Issue 2524] final override inconsistent when implementing interfaces
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jan 20 23:10:42 PST 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2524
------- Comment #11 from 2korden at gmail.com 2009-01-21 01:10 -------
(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.
>
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();
You just hijacked type system, that's it.
One possible solution would be to add protection flag into class typeinfo which
will be taken into account during dynamic cast. Or remove interface from
classinfo.interfaces altogether (it should still be possible to cast known
class to its known base class/interface statically, i.e. without dynamic cast).
I know the issue is not of high value but it should either be fixed for
consistency, or protection inheritance attributes should be removed from
language.
--
More information about the Digitalmars-d-bugs
mailing list