Bug 11244 – Invalid warning about slice assignment

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-13T09:11:00Z
Last change time
2013-10-20T09:40:12Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
code

Attachments

IDFilenameSummaryContent-TypeSize
1261repro.drepro casetext/x-dsrc257

Comments

Comment #0 by code — 2013-10-13T09:11:32Z
Created attachment 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.
Comment #1 by monarchdodra — 2013-10-13T13:21:59Z
Comment #2 by mailnew4ster — 2013-10-13T13:26:49Z
(In reply to comment #1) > Probably related: > http://d.puremagic.com/issues/show_bug.cgi?id=11244 You put me in an infinite loop.
Comment #3 by monarchdodra — 2013-10-13T14:16:43Z
(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.
Comment #4 by bugzilla — 2013-10-14T15:17:19Z
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[]; }
Comment #5 by k.hara.pg — 2013-10-16T07:17:26Z
PR to disable the feature that had proposed and implemented by issue 7444. https://github.com/D-Programming-Language/dmd/pull/2673