[Issue 11276] New: Possibly spurious (did you forget a [] ?) error message

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 15 14:32:04 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11276

           Summary: Possibly spurious (did you forget a [] ?) error
                    message
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-10-15 14:32:03 PDT ---
This could be a problem in DMD and one related but different in Phobos.

This used to work:


import std.algorithm: reduce;
struct Foo { int x, y; }
void main() {
    Foo[] data = [{10, 20}, {30, 40}];
    reduce!((a, b) => a[] += [b.x, b.y][])([0, 0], data);
}


Now it gives (dmd 2.064beta1):

test.d(5): Error: invalid array operation a[] += [b.x, b.y] (did you forget a
[] ?)
...\dmd2\src\phobos\std\algorithm.d(763): Error: template instance
test.main.__lambda1!(int[], Foo) error instantiating
test.d(5):        instantiated from here: reduce!(int[], Foo[])
test.d(5): Error: template instance test.main.reduce!((a, b) => a[] += [b.x,
b.y][]).reduce!(int[], Foo[]) error instantiating



Expanding the lambda doesn't fully solve the problem (now compiling with
"-wi"):

import std.algorithm: reduce;
struct Foo { int x, y; }
void main() {
    Foo[] data = [{10, 20}, {30, 40}];
    reduce!((a, b) { int[2] c = [b.x, b.y];
                     a[] += c[];
                     return c;})([0, 0], data);
}


Gives:

...\dmd2\src\phobos\std\algorithm.d(763): Warning: explicit slice assignment
result = (__lambda1(result, front(_param_1)))[] is better than result =
__lambda1(result, front(_param_1))

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


More information about the Digitalmars-d-bugs mailing list