Summary: Array operation without a slice as the lvalue
                    accepted, bad codegen
           Product: D
           Version: 1.045
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid, diagnostic, spec, wrong-code
          Severity: major
          Priority: P3
         Component: DMD

The below code compiles, but shouldn't: array operations can't be used as
initializers according to the spec, they need a slice as the lvalue.

void main() {
    auto x = [2,3,4];
    auto y = [1,1,1];
    auto z = x[] - y[];
    assert (z == [1,2,3]);

The assertion fails: z becomes a dynamic array with length 0 and an invalid

A similarly incorrect array results with most other operators. Using +,
however, gives the following strange diagnostic:

foo.d(5): Error: Array operation x[] + y[] not implemented

This makes no sense, since x[] + y[] itself is perfectly fine as well as

Replacing 'auto z' with 'int[3] z' makes all cases succeed, but that
contradicts the spec. IMHO there's no reason why using array operations as
initializers should be invalid but that's what the spec currently says; added
the 'spec' keyword to this in the hopes that this is legalized.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to