Bug 14941 – dmd rejects op assignment to opIndex expression

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-08-20T15:58:00Z
Last change time
2015-08-20T21:43:16Z
Keywords
rejects-valid
Assigned to
nobody
Creator
ag0aep6g

Comments

Comment #0 by ag0aep6g — 2015-08-20T15:58:10Z
Found by Ryuichi OHORI, see issue 14935. ---- struct V { void opOpAssign(string op)(int x) {} } struct S { V opIndex() {return V();} } void main() { S s; auto v = s[]; v += 2; /* no error */ s.opIndex() += 2; /* no error */ s[] += 2; /* Error: S cannot be sliced with [] */ } ---- Clearly, S can be sliced with []. And a V can be add-assigned. The compiler seems to give up when there's opIndexOpAssign for S, but it should try opIndex+opOpAssign, too. Also fails in the same manner when S.opIndex returns e.g. `ref int`. If nothing else, the error message should be improved.
Comment #1 by k.hara.pg — 2015-08-20T21:43:16Z
*** This issue has been marked as a duplicate of issue 14624 ***