Bug 655 – Operator overload uses opIndex instead of opIndexAssign
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2006-12-06T08:41:00Z
Last change time
2014-02-15T13:20:09Z
Keywords
accepts-invalid
Assigned to
bugzilla
Creator
bruno.do.medeiros+deebugz
Comments
Comment #0 by bruno.do.medeiros+deebugz — 2006-12-06T08:41:59Z
In an array assignment expression, operator overload uses opIndex instead of opIndexAssign.
----------
import std.stdio;
struct Moo {
void opIndex(int i, int i2) {
writefln("opIndex:", i, i2);
}
}
int main(char[][] args) {
Moo m = *new Moo();
m[0, 42]; // uses opIndex , ok
m[0] = 42; // uses opIndex instead of opAssign, not ok according to spec
return 0;
}
Comment #1 by bruno.do.medeiros+deebugz — 2006-12-06T08:43:25Z
Agh, read the comment above as:
m[0] = 42; // uses opIndex instead of opIndexAssign, not ok according to spec
Comment #2 by jarrett.billingsley — 2006-12-06T09:18:32Z
> import std.stdio;
>
> struct Moo {
> void opIndex(int i, int i2) {
> writefln("opIndex:", i, i2);
> }
> }
>
> int main(char[][] args) {
> Moo m = *new Moo();
> m[0, 42]; // uses opIndex , ok
> m[0] = 42; // uses opIndex instead of opAssign, not ok according to spec
>
> return 0;
> }
>
When I compile that snippet in 0.176, I get the error:
dtest.d(134): Error: operator [] assignment overload with opIndex(i, value) deprecated, use opIndexAssign(value, i)
Is that what you mean? Or does it compile for you?
I think it's a vestige of some _very_ old operator overloading behavior, Walter probably missed it.
Comment #3 by bruno.do.medeiros+deebugz — 2006-12-07T13:23:31Z
My mistake, I was compiling with -d (allow deprecated) and didn't notice it.