Bug 5044 – opIndexUnary not working for post++

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-10-11T17:44:11Z
Last change time
2024-12-13T17:53:56Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Austin Hastings
Moved to GitHub: dmd#17518 →

Comments

Comment #0 by ah08010-d — 2010-10-11T17:44:11Z
This code: ========== module scratch; class C( element_t ) { element_t [] contents; element_t opIndex( int index ) { return contents[ index ]; } element_t opIndexUnary( string op )( int index ) { static if( op == "++" ) { return ++contents[ index ]; } else { static assert( false ); } } } unittest { auto c = new C!int(); c[0]++; } ========== Produces this output: ========== $ dmd -c -unittest scratch.d scratch.d(42): Error: c.opIndex(0) is not an lvalue ========== But if the penultimate line: "c[0]++" is replaced by "++c[0]", there is no problem. And finally, if the opIndex is changed to return a 'ref', there is not problem, but the opIndexUnary operator is not called - the reference is incremented as an int, I think.
Comment #1 by monarchdodra — 2012-07-26T01:28:56Z
*** Issue 7733 has been marked as a duplicate of this issue. ***
Comment #2 by robert.schadek — 2024-12-13T17:53:56Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17518 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB