opSlice Bug?
Ali Çehreli
acehreli at yahoo.com
Thu Nov 29 09:39:01 PST 2012
On 11/29/2012 08:15 AM, Namespace wrote:
> Why I have to write
> arr2[] += arr[][]
> instead of
> arr2[] += arr[]
> ? Bug or 'feature'? :P
>
> Code:
> http://dpaste.dzfl.pl/4c732f4c
Apparently, the array-wise operations require the following syntax:
a[] += b[];
In other words, the compiler wants to see [] on the right-hand side as
well. The following does not work with the same error message that you get:
int[] a, b;
a[] += b;
Error: invalid array operation a[] += b (did you forget a [] ?)
It is the same in your case. You have a function that returns a slice
but the compiler still wants to see [] on the rigth-hand side:
int[] foo()
{
int[] b;
return b;
}
void main()
{
int[] a;
a[] += foo(); // <-- Same compilation error
}
That's why you need to put the [] after it:
a[] += foo()[];
I think it is just the requirement of the syntax. (?)
Ali
More information about the Digitalmars-d-learn
mailing list