The implicit conversion to immutable is only possible inside strongly pure 
functions.  When the parameter is 'in int[]' foo cannot be strongly pure, 
only const pure.  As 'in int[2]' is a value type, the second foo can be 
strongly pure.

'new' expressions will hopefully be able to be converted to immutable 
eventually, along with array concatenation and array.dup.

It is also likely that the following will be valid code (const pure foo 
called with immutable arguments)

int[] foo(in int[] x) pure {
   return new int[1];
}

void main() {
  immutable x = foo([1, 2, 3].idup);
}

"bearophile" <bearophileh...@lycos.com> wrote in message 
news:j6iom9$2g1m$1...@digitalmars.com...
> Do you know why this program doesn't compile (with DMD 2.056head)?
>
>
> immutable(int[]) foo(in int[] x) pure {
>    return new int[1];
> }
> void main() {}
>
>
> It gives:
> test.d(2): Error: cannot implicitly convert expression (new int[](1u)) of 
> type int[] to immutable(int[])
>
> This program instead compiles (now x is int[2] instead of int[]):
>
> immutable(int[]) foo(in int[2] x) pure {
>    return new int[1];
> }
> void main() {}
>
>
> Bye and thank you,
> bearophile 


Reply via email to