www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - T[n] a; immutable(T)[n] b = a; // error

reply Peter Alexander <peter.alexander.au gmail.com> writes:
int[2] a;
immutable(int)[2] b = a;

I get "Error: cannot implicitly convert expression (a) of type int[2u] 
to immutable(int)[]"

Is there are reason for disallowing this, or is it a bug?
Oct 01 2011
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
Peter Alexander:

 int[2] a;
 immutable(int)[2] b = a;
 
 I get "Error: cannot implicitly convert expression (a) of type int[2u] 
 to immutable(int)[]"
 
 Is there are reason for disallowing this, or is it a bug?
It's a bug. And I think the error message too is wrong, it prints "immutable(int)[]" instead of "immutable(int)[2]". Bye, bearophile
Oct 01 2011
prev sibling parent reply mta`chrono <chrono mta-international.net> writes:
int[2] a;
immutable(int)[2] b = a.idup;

Am 01.10.2011 13:00, schrieb Peter Alexander:
 int[2] a;
 immutable(int)[2] b = a;
 
 I get "Error: cannot implicitly convert expression (a) of type int[2u]
 to immutable(int)[]"
 
 Is there are reason for disallowing this, or is it a bug?
Oct 01 2011
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Sat, 01 Oct 2011 08:32:56 -0400, mta`chrono  
<chrono mta-international.net> wrote:

 int[2] a;
 immutable(int)[2] b = a.idup;
That should not be necessary. There's no reason to allocate a heap array in order to copy data that implicitly casts to immutable. Definitely a bug. -Steve
Oct 01 2011
parent Peter Alexander <peter.alexander.au gmail.com> writes:
On 2/10/11 12:44 AM, Steven Schveighoffer wrote:
 On Sat, 01 Oct 2011 08:32:56 -0400, mta`chrono
 <chrono mta-international.net> wrote:

 int[2] a;
 immutable(int)[2] b = a.idup;
That should not be necessary. There's no reason to allocate a heap array in order to copy data that implicitly casts to immutable. Definitely a bug. -Steve
Yep. Looks like dsimcha beat me to the bug report: http://d.puremagic.com/issues/show_bug.cgi?id=4454 Up-voted!
Oct 02 2011