digitalmars.D - Implicit conversion to base interface doesn't work inside
- Uranuz (35/35) Jul 17 2014 Seems that I saw similar post but about plain arrays somewhere
- Uranuz (3/3) Jul 17 2014 Actualy I found this bug report, but I don't know if there
- bearophile (26/29) Jul 17 2014 I think it's a bug. Issue 5498 it's better left closed. Search if
- bearophile (12/12) Jul 17 2014 Reduced:
- bearophile (4/11) Jul 17 2014 I have added a note:
- Uranuz (4/15) Jul 17 2014 OK. Thanks. Using casts everywhere for such case us quite
- bearophile (5/8) Jul 17 2014 It's not exactly the same issue. Issue 3543 seems more fitting.
Seems that I saw similar post but about plain arrays somewhere but currently I can't find it. The topic is that when I initialize associative array of interfaces with AA-literal consisting of derived class objects I get compiler error. import std.stdio; interface IBase { } class Impl(T): IBase { T value; } void main() { IBase[string] fldFormats = [ "Key": new Impl!(uint), "Name": new Impl!(string), "Percent": new Impl!(double) ]; } As a result I get this interesting error message: Compilation output: /d780/f916.d(22): Error: cannot implicitly convert expression (new Impl) of type object.Object to f916.Impl!(double).Impl /d780/f916.d(22): Error: cannot implicitly convert expression (new Impl) of type object.Object to f916.Impl!(double).Impl /d780/f916.d(18): Error: cannot implicitly convert expression (["Key":(__error),"Name":(__error),"Percent":new Impl]) of type Impl[string] to IBase[string] I'm very glad that compiler now can implicitly infer some immutable, shared modifiers in initializers, but I think that cases like this are important too. Should I file an issue or it already exists, or it doesn't matter, or etc? Thanks for attention
Jul 17 2014
Actualy I found this bug report, but I don't know if there suggested something around associative arrays https://issues.dlang.org/show_bug.cgi?id=5498
Jul 17 2014
Uranuz:Actualy I found this bug report, but I don't know if there suggested something around associative arrays https://issues.dlang.org/show_bug.cgi?id=5498I think it's a bug. Issue 5498 it's better left closed. Search if another more specific bug is open on this, or open a new one otherwise: interface IBase {} class Impl(T): IBase { T value; } void main() { IBase x = new Impl!uint; IBase y = new Impl!string; IBase z = new Impl!double; IBase[string] fldFormats1 = [ "Key": x, "Name": y, "Percent": z ]; IBase[string] fldFormats2 = [ "Key": new Impl!uint, "Name": new Impl!string, "Percent": new Impl!double ]; } Kenji fixes two similar bugs before breakfast ;-) Bye, bearophile
Jul 17 2014
Reduced: interface IBase {} class Impl(T): IBase { T value; } void main() { IBase a = true ? (new Impl!uint) : (new Impl!string); } test.d(6,23): Error: cannot implicitly convert expression (new Impl!uint) of type object.Object to test.IBase Bye, bearophile
Jul 17 2014
interface IBase {} class Impl(T): IBase { T value; } void main() { IBase a = true ? (new Impl!uint) : (new Impl!string); }I have added a note: https://issues.dlang.org/show_bug.cgi?id=3543 Bye, bearophile
Jul 17 2014
On Thursday, 17 July 2014 at 17:15:54 UTC, bearophile wrote:OK. Thanks. Using casts everywhere for such case us quite annoying. I've tested it for plain array it doesn't work too. However issue is marked as solved for it.interface IBase {} class Impl(T): IBase { T value; } void main() { IBase a = true ? (new Impl!uint) : (new Impl!string); }I have added a note: https://issues.dlang.org/show_bug.cgi?id=3543 Bye, bearophile
Jul 17 2014
Uranuz:OK. Thanks. Using casts everywhere for such case us quite annoying. I've tested it for plain array it doesn't work too. However issue is marked as solved for it.It's not exactly the same issue. Issue 3543 seems more fitting. In D interfaces and classes are not the same thing. Bye, bearophile
Jul 17 2014
On Thursday, 17 July 2014 at 17:27:37 UTC, bearophile wrote:Uranuz:OK. I'll try to use beta version of 2.066 until release happensOK. Thanks. Using casts everywhere for such case us quite annoying. I've tested it for plain array it doesn't work too. However issue is marked as solved for it.It's not exactly the same issue. Issue 3543 seems more fitting. In D interfaces and classes are not the same thing. Bye, bearophile
Jul 20 2014