https://issues.dlang.org/show_bug.cgi?id=5156
Andrei Alexandrescu and...@erdani.com changed:
What|Removed |Added
Version|D1 D2 |D2
--
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
http://d.puremagic.com/issues/show_bug.cgi?id=5156
bearophile_h...@eml.cc changed:
What|Removed |Added
CC||bearophile_h...@eml.cc
---
http://d.puremagic.com/issues/show_bug.cgi?id=5156
Simen Kjaeraas simen.kja...@gmail.com changed:
What|Removed |Added
Status|NEW |RESOLVED
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
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
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
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
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,
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
10 matches
Mail list logo