Bug 5202 – opIndexAssign doesn't work on structs obtained via getters
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-11-11T12:05:00Z
Last change time
2012-03-06T23:34:22Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2010-11-11T12:05:54Z
Comment #1 by dsimcha — 2010-11-11T12:07:32Z
Argh, accidentally hit enter. Please disregard the blank first post.
struct OpIndexAssign {
void opIndexAssign(uint val, uint index) {}
uint opIndex(uint index) { return 42; }
}
struct Struct {
OpIndexAssign oas;
OpIndexAssign getter() @property {
return oas;
}
}
void main() {
Struct s;
s.oas[5] = 5; // Works
s.getter[5] = 5; // Fails
}
Error message:
test.d(17): Error: s.getter()[5u] is not an lvalue
Comment #2 by yebblies — 2010-11-13T03:13:46Z
Is this supposed to work?
It seems to me that this would require property rewriting, which is not supported.
What would you expect this to do if the compiler did accept it, considering that getter() does not return by ref?
Comment #3 by dransic — 2011-01-13T23:48:17Z
s.getter()[5] = 5; // Works
Comment #4 by nilsbossung — 2012-03-06T23:34:22Z
*** This issue has been marked as a duplicate of issue 4993 ***