[Issue 11244] New: Invalid warning about slice assignment

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 13 09:11:33 PDT 2013


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 at puremagic.com
        ReportedBy: code at benjamin-thaut.de


--- Comment #0 from Benjamin Thaut <code at 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: -------


More information about the Digitalmars-d-bugs mailing list