[fpc-devel] Assignment to for..in loop variable
Alexander Klenin
klenin at gmail.com
Sun Mar 13 14:02:22 CET 2011
Currently, this code:
var
i: Integer;
a: array [1..10] of Integer;
...
for i in a do i += 1;
Is compiled and silently does nothing.
Assignment to the for..in loop variable is currently not supported by
Delphi either:
http://docwiki.embarcadero.com/RADStudio/en/Declarations_and_Statements#Iteration_Over_Containers_Using_For_statements
however, there are some good use cases for this:
http://stackoverflow.com/questions/2246087/delphi-variable-used-in-the-for-in-cannot-be-assigned
So, I have a bug report/feature request:
1) In the current implementation, FPC should at least warn on attempt
to change for..in loop variable
(I assumed that since it compiles, it works, and it cost me much time
to debug this)
2) Ideally, FPC for loop variable should have the same semantics as
var parameter,
so changing it should change the underlying data.
--
Alexander S. Klenin
More information about the fpc-devel
mailing list