digitalmars.D.bugs - Implicit array conversions - something rotten
- Mike Capp (66/66) Aug 07 2005 I was reading the "Implicit Conversions" section of arrays and did a
- Ben Hinkle (7/80) Aug 07 2005 I agree http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/36...
- Mike Capp (6/12) Aug 07 2005 But D uses reference semantics for all objects of class type, so Object[...
I was reading the "Implicit Conversions" section of arrays and did a double-take; several of the conversions listed looked flat-out wrong. A bit of experimentation muddied the waters further - several documented conversions don't work, and several documented conversions that I was convinced had to be typos do. Most importantly, D really will implicitly cast from a Derived[] to a Base[]. This is a huge hole in type-safety - it lets you put an object of ANY class into an array of ANY class type without ever writing an explicit cast. I don't know of any other statically-typed OO language that allows it. #class Base {} #class Derived : Base {} #void main()
Aug 07 2005
"Mike Capp" <mike.capp gmail.com> wrote in message news:dd5v4m$vk2$1 digitaldaemon.com...I was reading the "Implicit Conversions" section of arrays and did a double-take; several of the conversions listed looked flat-out wrong. A bit of experimentation muddied the waters further - several documented conversions don't work, and several documented conversions that I was convinced had to be typos do. Most importantly, D really will implicitly cast from a Derived[] to a Base[]. This is a huge hole in type-safety - it lets you put an object of ANY class into an array of ANY class type without ever writing an explicit cast.I agree http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/3681I don't know of any other statically-typed OO language that allows it.C++ allows it because C++ is C++ (by which I mean arrays are pointers). assigning into the array to make sure the the array type is compatible with the element being inserted.#class Base {} #class Derived : Base {} #void main()
Aug 07 2005
In article <dd625n$11rs$1 digitaldaemon.com>, Ben Hinkle says..."Mike Capp" <mike.capp gmail.com> wrote in message news:dd5v4m$vk2$1 digitaldaemon.com...But D uses reference semantics for all objects of class type, so Object[] in D corresponds to Object** in C++, not to Object*. And there's no implicit Derived** to Base** conversion in C++. cheers MikeMost importantly, D really will implicitly cast from a Derived[] to a Base[]. [...] I don't know of any other statically-typed OO language that allows it.C++ allows it because C++ is C++ (by which I mean arrays are pointers).
Aug 07 2005