Assignment to (inherited Items[I]) is ignored
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
The attached source code contains a trivial descendant of TObjectList. It merely introduces new Items property, that typecasts items to TMyItem class, pretending that list can only keep TMyItem inside. (Of course, now it could be done much better and safer with generics.)
Implementing a setter like below works without problems:
procedure TMyList.SetItem(const I: Integer; const Item: TMyItem);
begin
inherited Items[I] := Item;
end;
But adding parenthesis around, like below, makes the code not working, that is the value stored in list is unchanged.
procedure TMyList.SetItem(const I: Integer; const Item: TMyItem);
begin
(inherited Items[I]) := Item;
end;
$ fpc -Sa -vwh inherited_items_set.pas
$ ./inherited_items_set
An unhandled exception occurred at $080A3603 :
EAssertionFailed : Assertion failed (inherited_items_set.pas, line 38)
$080A3603
At least a warning that compiler probably generates code that changes only some temporary value would be nice :)
Mantis conversion info:
- Mantis ID: 21087
- OS: Debian GNU/Linux
- OS Build: (testing)
- Platform: i386
- Fixed in revision: 20140 (#e5c097a6)