[Issue 7759] Inconsistencies with Array Operations

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 3 22:14:15 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=7759

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> ---
With 2.067:

(In reply to daniel from comment #1)
>         writeln(x[] + x[]); // error (Array operation v1[] + v1[] not
> implemented)
>         float[] t1 = x[] + x[]; // ""
>         float[] t2 = y[] + y[]; // ""
>         auto t3 = x[] + x[]; // ""

The produced error message is finally improved as:

 Error: array operation x[] + x[] without destination memory not allowed

In above code, you're trying to get "slice" of the result of array operations,
but array operations don't allocate new array to store the calculated elements.
Therefore such the impossible code will be rejected and error messages explain
the requirement.

>         float[3] t2b = y[] + y[]; // ok??? how does this even... appears to
> give a float[3] array with values of a [0..3] slice of y[] + y[]...
>         writeln(t2b);

The length of y will be asserted in runtime to fit to the result length of
array operation result. In this case it's 3, that's same with the destination
memory length.

(In reply to daniel from comment #2)
> 	int[] a = [3,3,3];
> 	int[2] y = a[] + a[]; // ok
> 	int[2] x = [3,3,3] + [3,3,3]; // error

Today both lines will fail at runtime. Maybe that was an already fixed druntime
bug.

(In reply to daniel from comment #3)
> If nothing else, the following must be a compiler bug, or otherwise a very
> unclear syntax;
> 
> int[2] fnc(int[2] a, int[2] b) {
> 	return a[] + b[]; // Error: cannot implicitly convert expression (a[] +
> b[]) of type int[] to int[2LU]
> }

It's a dupe of issue 12648.

Finally the "inconsistencies" are
- fixed as design
- fixed as a druntime bug
- remained bug 12648

So I close this issue as "fixed".

--


More information about the Digitalmars-d-bugs mailing list