Bug 12985 – Better error message for not supported array operation
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-06-24T21:35:00Z
Last change time
2015-02-18T03:37:53Z
Keywords
diagnostic, pull
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2014-06-24T21:35:22Z
void foo(int[] b) {}
void main() {
int[2] a = [1, 2];
foo(a[] * 2);
}
dmd 2.066alpha gives:
test.d(4,9): Error: array operation a[] * 2 without assignment not implemented
I suggest a better error message like:
test.d(4,9): Error: array operations that allocate memory are not supported for performance reasons
See also issue 10307
Comment #1 by k.hara.pg — 2014-09-21T16:12:05Z
From https://issues.dlang.org/show_bug.cgi?id=12179#c7
> The error message for the original code is:
>
> test.d(4,6): Error: array operation a[] * a[] without assignment not
> implemented
>
> But perhaps a better error message is related to this:
>
> test.d(4,6): Error: array operation a[] * a[] without explicit destination
> memory not allowed
>
> Because I think not allocating memory from array ops is a design decision,
> and it will not be implemented.
I think "without destination memory not allowed" would be better.
Comment #2 by bearophile_hugs — 2014-09-21T16:43:13Z
(In reply to Kenji Hara from comment #1)
> I think "without destination memory not allowed" would be better.
I am not a native English speaker, we need one to find the best phrasing :-)
Comment #3 by bearophile_hugs — 2014-09-21T17:59:20Z
Currently this case gets refused, but here the result of the array operation has a memory zone to go (the stack, inside the variable f):
struct Foo { int[3] a; }
void main() {
int[3] b;
auto f = Foo(b[] / 2);
}