[dmd-beta] D2 2.058 beta 3

Mike Wey mike at mikewey.eu
Mon Feb 13 13:36:39 PST 2012

On 02/12/2012 09:56 PM, Mike Wey wrote:
> On 02/12/2012 09:08 PM, Walter Bright wrote:
>> It's a Base, not an Object. It can be converted to an Object. 
> Doesn't that break Polymorphism?
> You should be able to use Base as if it is an Object without a cast.
> _______________________________________________
> dmd-beta mailing list
> dmd-beta at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-beta

According to the documentation a == b is rewritten to 
.object.opEquals(a, b); if a  and b are both objects.
And while .object.opEquals(new Base(), new Base()); compiles without an 
error, and gives the expected result at runtime. using == is an 
compiletime error when a opCast is supplied without adding one for Object.

Base being derived from Object there would be no need for a cast when 
you want to use it as an Object.

Adding an opCast overload for Object solves the compiletime error but, 
the added opCast doesn't do anything:

Base opCast(T)()
     if ( is(T == Object) )
     return this;

Yes i used Base as the return type, that works because base is derived 
from Object.

Is the behavior of the beta really correct?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-beta/attachments/20120213/5046af9a/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug.d
Type: text/x-dsrc
Size: 445 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/dmd-beta/attachments/20120213/5046af9a/attachment-0001.d>

More information about the dmd-beta mailing list