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
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";
*** Issue 5202 has been marked as a duplicate of this issue. ***
https://github.com/D-Programming-Language/dmd/pull/791
(In reply to comment #3) > https://github.com/D-Programming-Language/dmd/pull/791 That one has been superseded by https://github.com/D-Programming-Language/dmd/pull/763