Quiz of the day: Why does this not work?

Steven Schveighoffer schveiguy at yahoo.com
Thu Nov 6 13:23:09 PST 2008


"Sean Kelly" wrote
> TomD wrote:
>> Hi,
>> this is about dmd and DLLs.
>>
>> Given a simple object hierachy in myclasses.d:
>> module myclasses;
>> class base{ char[] toString(){ return "I am base";} }
>> class c1: base{ char[] toString(){ return "I am c1";} }
>> class c2: base{ char[] toString(){ return "I am c2";} }
> ...
>>   assert( cast(c1) instances[1] !is null);
>>   assert( cast(c2) instances[2] !is null);
>>
>>   return 0;
>> }
>
> I think this is a bug in the runtime.  Look like 116 of:
>
> http://dsource.org/projects/tango/browser/trunk/lib/compiler/dmd/cast.d
>
> In your example, I'm pretty sure that the DLLs ClassInfo instance of c1 
> will be passed into _d_isbaseof2 while the ClassInfo obtained from the 
> object to be cast will come from the object's memory space (ie. from the 
> app).  Since an 'is' comparison is taking place and these are distinct 
> objects, the cast will fail.  Try changing the 'is' comparisons at lines 
> 105, 109, 116, 150, and 176 (I think that's all of them) to '==' and see 
> if that does the trick.

Won't make a difference.  ClassInfo does not override the default opEquals, 
which does an is compare.

-Steve 





More information about the Digitalmars-d mailing list