Array implicit conversions subvert type system

Gregor Richards Richards at codu.org
Fri Nov 24 16:39:17 PST 2006


Mike Capp wrote:
> Can't remember if I raised this before (it was loitering among the testcases
> from my last peek at D), but it's still true in 0.174. "Derived[] to Base[]"
> assignments really shouldn't happen without either a copy or an explit cast.
> 
> ---
> 
> class Fruit {};
> class Apple : Fruit {};
> class Orange : Fruit {};
> 
> void main()
> {
> 	Apple[] apples;
> 	apples.length = 3;
> 	Fruit[] fruits = apples;
> 	Orange orange = new Orange;
> 	fruits[1] = orange;
> 
> 	if (apples[1] == orange) printf("Oops.\n");
> }

No, purposeful, contrived subversion of the type system subverts the 
type system.

  - Gregor Richards



More information about the Digitalmars-d mailing list