Interface Covariance Bug?

John C johnch_atms at hotmail.com
Sun Mar 26 01:45:47 PST 2006


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? 





More information about the Digitalmars-d-bugs mailing list