www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11244] New: Invalid warning about slice assignment

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11244

           Summary: Invalid warning about slice assignment
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: code benjamin-thaut.de


--- Comment #0 from Benjamin Thaut <code benjamin-thaut.de> 2013-10-13 09:11:32
PDT ---
Created an attachment (id=1261)
repro case

Starting with dmd 2.063 it is no longer possible to create user defined types
that behave exactly like build in types when it comes to slice assignment.

Creating a user defined type with a propper slice operator which returns the
slice of an array and then assignen that slice to an array will result in a
warning:
repro.d(20): Warning: explicit element-wise assignment copy[] = (s.opSlice())[]
is better than copy[] = s.opSlice()

The compiler does not seem to recognize the use of the slice operator here
because tha analysis is done after rewriting the slice operator into the call
to opSlice. This is especially anoying in generic code where a workaround like
this has to be used to avoid the warning:

static if(isArray!typeof(a))
  copy[] = a[];
else 
  copy[] = a[][];

See attached repro case.

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


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com


--- Comment #1 from monarchdodra gmail.com 2013-10-13 13:21:59 PDT ---
Probably related:
http://d.puremagic.com/issues/show_bug.cgi?id=11244

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


9999 <mailnew4ster gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mailnew4ster gmail.com


--- Comment #2 from 9999 <mailnew4ster gmail.com> 2013-10-13 13:26:49 PDT ---
(In reply to comment #1)
 Probably related:
 http://d.puremagic.com/issues/show_bug.cgi?id=11244
You put me in an infinite loop. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11244



--- Comment #3 from monarchdodra gmail.com 2013-10-13 14:16:43 PDT ---
(In reply to comment #2)
 (In reply to comment #1)
 Probably related:
 http://d.puremagic.com/issues/show_bug.cgi?id=11244
You put me in an infinite loop.
(In reply to comment #2)
 (In reply to comment #1)
 Probably related:
 http://d.puremagic.com/issues/show_bug.cgi?id=11244
You put me in an infinite loop.
I meant: http://d.puremagic.com/issues/show_bug.cgi?id=11228 Sorry. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 13 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11244


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #4 from Walter Bright <bugzilla digitalmars.com> 2013-10-14
15:17:19 PDT ---
The repro case:
-------------------------
struct SimpleWrapper
{
    int[] m_data;

    this(int[] data)
    {
        m_data = data;
    }

    ref int[] opSlice()
    {
        return m_data;
    }
}

void main(string[] args)
{
    auto s = SimpleWrapper([1, 2, 3, 4]);
    auto copy = new int[4];
    copy[] = s[];
}

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


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:26 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 parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11244


Walter Bright <bugzilla digitalmars.com> changed:

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


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