Thread overview | |||||
---|---|---|---|---|---|
|
February 28, 2005 AA with an keytype of interface segfaults | ||||
---|---|---|---|---|
| ||||
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 |
February 28, 2005 Re: AA with an keytype of interface segfaults | ||||
---|---|---|---|---|
| ||||
Posted in reply to brad beveridge | 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. |
February 28, 2005 Re: AA with an keytype of interface segfaults | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund |
> PS. Bugs go in the bugs group.
Doh! I'll try to remember next time. Thanks for posting to there also.
Brad
|
Copyright © 1999-2021 by the D Language Foundation