[Issue 5156] Wrong type inference for array literals containing classes

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=5156 Andrei Alexandrescu and...@erdani.com changed: What|Removed |Added Version|D1 D2 |D2 --

[Issue 5156] New: Wrong type inference for array literals containing classes

2010-11-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5156 Summary: Wrong type inference for array literals containing classes Product: D Version: D1 D2 Platform: Other OS/Version: Windows Status: NEW Keywords

[Issue 5156] Wrong type inference for array literals containing classes

2010-11-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5156 bearophile_h...@eml.cc changed: What|Removed |Added CC||bearophile_h...@eml.cc ---

[Issue 5156] Wrong type inference for array literals containing classes

2010-11-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5156 Simen Kjaeraas simen.kja...@gmail.com changed: What|Removed |Added Status|NEW |RESOLVED

Type inference in array literals

2010-08-28 Thread klickverbot
I was really surprised by the fact that the following code does not work (DMD 2.048 infers the type of the array literal to B[], not Object[]): --- class A {} class B {} void main() { Object[] foo = [ new A, new B ]; } --- Is this by design? If so, what are the reasons for not using the

Re: Type inference in array literals

2010-08-28 Thread Jesse Phillips
D uses the last element in the array literal to select the type. I think there was a discussion on why a common type wasn't used, but don't remember the conclusion. It would be nice if it used the item you are assigning to and check they can convert to it. klickverbot Wrote: I was really

Re: Type inference in array literals

2010-08-28 Thread Max Samukha
On 08/28/2010 07:19 PM, Jesse Phillips wrote: D uses the last element in the array literal to select the type. I think there was a discussion on why a common type wasn't used, but don't remember the conclusion. It would be nice if it used the item you are assigning to and check they can

Re: Type inference in array literals

2010-08-28 Thread bearophile
klickverbot: class A {} class B {} void main() { Object[] foo = [ new A, new B ]; } See also: http://d.puremagic.com/issues/show_bug.cgi?id=4030 Bye, bearophile

Re: Type inference in array literals

2010-08-28 Thread bearophile
Jesse Phillips: D uses the last element in the array literal to select the type. That's not true, this doesn't assert: import std.stdio: writeln; void main() { auto a = [1, 1.5, 2]; assert(is(typeof(a) == double[])); } I think it uses ?: on all elements, to infer the type. Bye,

Re: Type inference in array literals

2010-08-28 Thread Philippe Sigaud
On Sat, Aug 28, 2010 at 18:19, Jesse Phillips jessekphillip...@gmail.comjessekphillips%...@gmail.com wrote: D uses the last element in the array literal to select the type. I think there was a discussion on why a common type wasn't used, but don't remember the conclusion. It would be nice if