brad beveridge wrote:
> The following code segfaults, it appears that you cannot use an interface as the key for an associative array.
>
> interface foo
> {
> void bar();
> }
>
> class MyClass : foo
> {
> void bar() {};
> }
>
> void main ()
> {
> int [foo] c;
> MyClass mc = new MyClass ();
> c[mc] = 0;
> }
Seems to be related to calling toHash() on an interface ?
(side note: on Mac, I get "illegal hardware instruction")
std.typeinfo.ti_C.d:
> class TypeInfo_C : TypeInfo
> uint getHash(void *p)
> {
> Object o = *cast(Object*)p;
> assert(o);
> return o.toHash();
> }
Because it crashes, even without involving the AA type :
(The actual crash seems to occur in object.Object.print ?)
> void main ()
> {
> MyClass mc = new MyClass ();
> foo mi = mc;
> Object* mp = cast(Object*)&mi;
> Object mo = *mp;
> debug printf("%d\n", mo.toHash());
> }
If one uses the class instead of the interface, it works...
> void main ()
> {
> MyClass mc = new MyClass ();
> Object* mp = cast(Object*)&mc;
> Object mo = *mp;
> debug printf("%d\n", mo.toHash());
> }
--anders
PS. Bugs go in the bugs group.
|