Type inference error with DI

Salih Dincer salihdb at hotmail.com
Mon Sep 27 19:36:04 UTC 2021


```d
interface ICon
{
   string Str();
}

class Foo : ICon
{
   string Str() {
     return "Foo";
   }
}

class Bar : ICon
{
   string Str() {
     return "Bar";
   }
}

import std.stdio;

void main()
{
   auto foo = new Foo();
   ICon bar = new Bar();
   /* replace ICon with auto,
    * please...*/
   auto test =
   [
     foo, bar
   ];
   foreach(t; test)
   {
     t.Str.writeln;
   }
}
```

It is thrown an error* because of type object.Object[].

(*) DIsampleFoo.d(34): Error: no property `Str` for type 
`object.Object`


More information about the Digitalmars-d mailing list