www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11276] New: Possibly spurious (did you forget a [] ?) error message

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs 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: -------
Oct 15 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-10-15
14:34:34 PDT ---
W.r.t. diagnostics, I've ran into the following when compiling msgpack-d:

-----
C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(453): Warning:
explicit element-wise assign
ment (this._expand_field_3)[] = (another._expand_field_3)[] is better than
this._expand_field_3 = anoth
er._expand_field_3
C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(453): Warning:
explicit element-wise assign
ment (this._expand_field_4)[] = (another._expand_field_4)[] is better than
this._expand_field_4 = anoth
er._expand_field_4
-----

It's again an odd diagnostic inside of Phobos. The issue and compile flags are
reported here:
https://github.com/msgpack/msgpack-d/issues/15

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276



--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-10-16 01:34:41 PDT ---
(In reply to comment #0)
 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
This is a duplicate issue of bug 10684. I'll increased importance of the issue. (In reply to comment #0)
 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))
This is a regression caused by implementing issue 7444. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
          Component|DMD                         |Phobos
            Summary|Possibly spurious (did you  |Spurious "explicit slice
                   |forget a [] ?) error        |assignment ...[] is better"
                   |message                     |warning message in Phobos


--- Comment #3 from bearophile_hugs eml.cc 2013-10-16 02:49:12 PDT ---
(In reply to comment #2)

 This is a duplicate issue of bug 10684. I'll increased importance of the issue.
 ...
 This is a regression caused by implementing issue 7444.
Then I have renamed and modified this issue, now it's just about the Phobos warning problem. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276



--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2013-10-16 04:30:57 PDT ---
(In reply to comment #3)
 (In reply to comment #2)
 
 This is a duplicate issue of bug 10684. I'll increased importance of the issue.
 ...
 This is a regression caused by implementing issue 7444.
Then I have renamed and modified this issue, now it's just about the Phobos warning problem.
I think the enh 7444 may not be usable in generic code. Maybe we need to disable 7444 for 2.064 release... -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2013-10-16 07:17:11 PDT ---
PR to disable the feature that had proposed and implemented by issue 7444.
https://github.com/D-Programming-Language/dmd/pull/2673

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276



--- Comment #6 from bearophile_hugs eml.cc 2013-10-16 07:27:40 PDT ---
(In reply to comment #4)

 I think the enh 7444 may not be usable in generic code. Maybe we need to
 disable 7444 for 2.064 release...
Do you plan in restoring 7444 for 2.065? Do you have ideas regarding how to fix this situation and save the 7444? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276



--- Comment #7 from Kenji Hara <k.hara.pg gmail.com> 2013-10-16 07:44:26 PDT ---
(In reply to comment #6)
 (In reply to comment #4)
 
 I think the enh 7444 may not be usable in generic code. Maybe we need to
 disable 7444 for 2.064 release...
Do you plan in restoring 7444 for 2.065? Do you have ideas regarding how to fix this situation and save the 7444?
If the code is in template instance, compiler can stop warning. It would save the generic code case in this issue. However, currently I have no idea for issue 11244. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 16 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11276


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


--- Comment #8 from Walter Bright <bugzilla digitalmars.com> 2013-10-20
09:39:45 PDT ---
https://github.com/D-Programming-Language/dmd/pull/2673

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