[Issue 14941] New: dmd rejects op assignment to opIndex expression
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Aug 20 08:58:10 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14941
Issue ID: 14941
Summary: dmd rejects op assignment to opIndex expression
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Keywords: rejects-valid
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: ag0aep6g at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list