Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
March 26, 2006 Interface Covariance Bug? | ||||
---|---|---|---|---|
| ||||
This compiles, but produces some strange output on the cmd line (DMD 0.150, Windows XP SP2): interface ICollection(T) { int length(); } interface IMap(TKey, TValue) { ICollection!(TKey) keys(); } class Map(TKey, TValue) : IMap!(TKey, TValue) { KeyCollection keys() { return new KeyCollection; } class KeyCollection : ICollection!(TKey) { int length() { return 5; } } } void main() { IMap!(int, int) map = new Map!(int, int); writefln(map.keys.length); } Output: KeyCollection 10227584 Why does it output "KeyCollection"? Is it some kind of runtime error? And why is map.keys.length not 5? |
March 28, 2006 Re: Interface Covariance Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | It's a forward reference problem. Try reversing the declarations of keys() and KeyCollection. |
March 28, 2006 Re: Interface Covariance Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | "Walter Bright" <newshound@digitalmars.com> wrote in message news:e09vmu$2ubc$1@digitaldaemon.com... > It's a forward reference problem. Try reversing the declarations of keys() and KeyCollection. Thanks - that fixed it. But surely it highlights a separate bug: forward referencing isn't supposed to be an issue in D, is it? John. |
March 28, 2006 Re: Interface Covariance Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | John C wrote: > "Walter Bright" <newshound@digitalmars.com> wrote in message news:e09vmu$2ubc$1@digitaldaemon.com... >> It's a forward reference problem. Try reversing the declarations of keys() and KeyCollection. > > Thanks - that fixed it. > > But surely it highlights a separate bug: forward referencing isn't supposed to be an issue in D, is it? Correct. You'll notice that many forward reference bugs have been filed both here and in DStress. But a forward reference bug that leads to bad code generation is a new one on me. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
March 28, 2006 Re: Interface Covariance Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | John C wrote: > "Walter Bright" <newshound@digitalmars.com> wrote in message news:e09vmu$2ubc$1@digitaldaemon.com... >> It's a forward reference problem. Try reversing the declarations of keys() and KeyCollection. > > Thanks - that fixed it. > > But surely it highlights a separate bug: forward referencing isn't supposed to be an issue in D, is it? Looking at your code again, it appears to be a case of http://d.puremagic.com/bugzilla/show_bug.cgi?id=65 I've just noticed that my testcase contains a forward reference as well. Guess I'll have to try rewriting it without the forward reference and see what happens. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
March 28, 2006 Re: Interface Covariance Bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to John C | "John C" <johnch_atms@hotmail.com> wrote in message news:e0avij$1bpj$1@digitaldaemon.com... > But surely it highlights a separate bug: forward referencing isn't supposed to be an issue in D, is it? Generally, it isn't. But the internal semantic routines need to be reorganized/reimplemented to do this better, and I'm not up for that right now. |
Copyright © 1999-2021 by the D Language Foundation