Thread overview
[Issue 3066] New: Array operation without a slice as the lvalue accepted, bad codegen
Jul 15, 2009
Kyle Foley
Jan 18, 2010
Hoenir
Feb 18, 2010
Matti Niemenmaa
Apr 29, 2010
Don
Apr 30, 2010
Walter Bright
May 06, 2010
Don
June 13, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3066

           Summary: Array operation without a slice as the lvalue
                    accepted, bad codegen
           Product: D
           Version: 1.045
          Platform: x86_64
               URL: http://www.digitalmars.com/d/1.0/arrays.html
        OS/Version: Linux
            Status: NEW
          Keywords: accepts-invalid, diagnostic, spec, wrong-code
          Severity: major
          Priority: P3
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: matti.niemenmaa+dbugzilla@iki.fi


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 pointer.

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 implemented.

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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 15, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3066


Kyle Foley <k-foley@onu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k-foley@onu.edu




--- Comment #1 from Kyle Foley <k-foley@onu.edu>  2009-07-15 06:51:21 PDT ---
I have recently discovered some bugs that are related to this

---

import std.stdio;

int main()
{
    int[] a = [1, 2, 3][];

    int[] b = a[] + 4;
    writeln("-> ", b); // -> 1 2 3 0 1935766371 1768515939 1764585331

    int[] c;
    c[] = a[] + 4;
    writeln("-> ", c); // ->

    c = [1, 1, 1][];
    c[] = a[] + 4;
    writeln("-> ", c); // -> 5 6 7

    c = [0][];
    c[] = a[] + 4;
    writeln("-> ", c); // -> 5

    c = a[] + 4;
    writeln("-> ", c); // -> 1 2 3 0 1935766371 1768515939 1764585331

    int[3] d = a[] + 4; // this is ok
    writeln("-> ", d); // -> 5 6 7

    int[3] e = [1, 2, 3];
    int[3] f = [5, 6, 7];
    //writeln( "-> ", e[] + f[] ); // Compile Error -- Error: Array operation
e[] + f[] not implemented
    // yet, this works:
    writeln( "-> ", e.dup[] += f[] ); // -> 6 8 10

    return 0;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 18, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3066



--- Comment #2 from Hoenir <mrmocool@gmx.de> 2010-01-17 17:32:31 PST ---
Also see
http://d.puremagic.com/issues/show_bug.cgi?id=2549

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 18, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3066


Matti Niemenmaa <matti.niemenmaa+dbugzilla@iki.fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from Matti Niemenmaa <matti.niemenmaa+dbugzilla@iki.fi> 2010-02-18 11:20:29 PST ---
*** Issue 3815 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3066


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-04-28 21:21:03 PDT ---
The patch for bug 3522 fixes this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3066


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> 2010-04-29 21:06:13 PDT ---
Changeset 460

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 06, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3066


Don <clugdbug@yahoo.com.au> changed:

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


--- Comment #6 from Don <clugdbug@yahoo.com.au> 2010-05-05 19:06:00 PDT ---
Fixed DMD2.044

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------