Bug 12770 – Array operation result assignment to static arrays is complicated
Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-20T05:31:00Z
Last change time
2014-09-21T03:52:51Z
Assigned to
nobody
Creator
turkeyman
Comments
Comment #0 by turkeyman — 2014-05-20T05:31:08Z
I think this should work:
float[4] f(float[4] a)
{
return (-a[])[0..$];
}
Error: cannot implicitly convert expression ((-a[])[0..__dollar]) of type float[] to float[4]
What I was actually trying to do, is perform array operations on static arrays. I'd like to think this should work:
float[4] f(float[4] a)
{
return -a;
}
I tend not to think of static arrays like arrays, they're more like a discreet object.
Requiring a[] causes a to become a dynamic array, and then it can't be assigned back to a static array anymore. It all goes south for array operations on static arrays with [].
At very least, this should probably work:
float[4] f(float[4] a)
{
return -a[];
}
Comment #1 by k.hara.pg — 2014-09-21T03:52:51Z
*** This issue has been marked as a duplicate of issue 12648 ***