Thread overview
[Issue 21881] Array operation fails to compile even though it really should
Apr 30, 2021
Blatnik
Apr 30, 2021
Blatnik
Apr 30, 2021
Blatnik
Apr 30, 2021
Ketmar Dark
Apr 30, 2021
Imperatorn
Dec 17, 2022
Iain Buclaw
April 30, 2021
https://issues.dlang.org/show_bug.cgi?id=21881

Blatnik <blatblatnik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Array operation fails to    |Array operation fails to
                   |compile even though it      |compile even though it
                   |really shouldn'             |really should

--- Comment #1 from Blatnik <blatblatnik@gmail.com> ---
float[3] add42(float[3] a)
{
    return a[] + 42;
}

Fails to compile with "Error: array operation `a[] + cast(float)3` without destination memory not allowed."

But

float[3] add42(float[3] a)
{
    float[3] result = a[] + 42;
    return result;
}

compiles just fine. I'm not sure if this is a bug, but if it was intended, I don't see a reason why we couldn't do that.

--
April 30, 2021
https://issues.dlang.org/show_bug.cgi?id=21881

--- Comment #2 from Blatnik <blatblatnik@gmail.com> ---
I also don't understand why the error message I get from that is different from other useless statements. For example:

1 + 1; // Error: `1 + 1` has no effect

int[1] i = [1];
i[] + i[]; // Error: array operation `i[] + i[]` without destination memory not
allowed.

I would have expected the same error message for both of these. It just seems like an inconsistency though, and not an actual problem.

--
April 30, 2021
https://issues.dlang.org/show_bug.cgi?id=21881

--- Comment #3 from Blatnik <blatblatnik@gmail.com> ---
I just realized that this is especially annoying when dealing with multi-dimensional arrays.

float[2] row0 = [1, 2];
float[2] row1 = [3, 4];

float[2][2] matrix = [
  row0[] + row0[], // Error: array operation without destination memory not
allowed.
  row1[] + row1[]  // Error: array operation without destination memory not
allowed.
];

The error message says there is no destination memory even though there clearly is.

--
April 30, 2021
https://issues.dlang.org/show_bug.cgi?id=21881

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org

--
April 30, 2021
https://issues.dlang.org/show_bug.cgi?id=21881

Imperatorn <johan_forsberg_86@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johan_forsberg_86@hotmail.c
                   |                            |om

--- Comment #4 from Imperatorn <johan_forsberg_86@hotmail.com> ---
This one is annoying. Also, imo we should allow these kinds of operations using temporaries.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=21881

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
December 13
https://issues.dlang.org/show_bug.cgi?id=21881

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19914

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--