Bug 4993 – Temporary values and opIndexAssign

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-10-04T13:14:00Z
Last change time
2012-03-17T21:55:22Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
simen.kjaras

Comments

Comment #0 by simen.kjaras — 2010-10-04T13:14:44Z
The following code does not compile. Note that the exact same functions are present in both the inner and outer structs, and that opIndex works for both. struct Foo{ struct Bar { int opIndex( size_t index ) { return 3; } void opIndexAssign( int value, size_t index ) { } } @property auto bar( ) { return Bar( ); } int opIndex( size_t index ) { return 3; } void opIndexAssign( int value, size_t index ) { } } void main( ) { Foo f; f[3] = f[2]; Foo.Bar b; b[3] = b[2]; f.bar[3] = f.bar[2]; // Fails } foo.d(28): Error: f.bar()[3u] is not an lvalue
Comment #1 by alvaro.segura — 2012-03-05T13:56:35Z
Note that this works instead: f.bar()[3]= f.bar[2]; if @property is not enforced. It's the same temporary struct returned, but without properties. Fixing this would allow implementing "indexed properties" as long as D does not provide them natively. i.e, things like: image.pixels[x,y] = Rgb(0,0,0); treeViewItem.text[2] = "text for column 2 in this item";
Comment #2 by nilsbossung — 2012-03-06T23:34:22Z
*** Issue 5202 has been marked as a duplicate of this issue. ***
Comment #3 by nilsbossung — 2012-03-06T23:38:59Z
Comment #4 by nilsbossung — 2012-03-07T03:01:36Z