digitalmars.D - AA with an keytype of interface segfaults
- brad beveridge (17/17) Feb 28 2005 The following code segfaults, it appears that you cannot use an
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (9/50) Feb 28 2005 Seems to be related to calling toHash() on an interface ?
- brad beveridge (2/3) Feb 28 2005 Doh! I'll try to remember next time. Thanks for posting to there also.
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; } Brad
Feb 28 2005
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 : TypeInfouint 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.
Feb 28 2005
PS. Bugs go in the bugs group.Doh! I'll try to remember next time. Thanks for posting to there also. Brad
Feb 28 2005