oliverhunt@gmail.com wrote:> One thing to note is that in general it is not possible to completely> statically check a strongly typed OO programming language if it allows> down casting, though i only mention this as it's a pet peave of mine> :D

How about something like the following...

Instead of doing explicit runtime downcasting one has to define additional
functions dynamically dispatched on the type(s) of one of their
argument(s).

Then a compiler checks if those types being dispatched on fully cover type
subhierarchy of static type of the object being passed as an argument.

Notice, that compiler can statically check at every call site if there is no
such my_base_class subclass for which there is not any matching
do_special_thing() variant.

The above example is good for the aformementioned hierarchy, as my_derived_1
covers itself as well as my_subderived_1 & 2 while my_derived_2 covers
itself and my_subderived_3. my_base_class is abstract so it has no
possioble instances and thus does not need to be covered.

Besides, there is the 'classic' option:

switch class(obj)
{
case my_derived_1:
obj.foo();
break;

case my_derived_2:
obj.bar();
break;}

Again, a compiler could (statically) check if above switch covers all the
possible variants.