Is the compiler able to give warnings that an iterator's internal state modified?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Is the compiler able to give warnings that an iterator's internal state modified?

FANG Colin
I guess the following is buggy code

   dict = Dict(x=>x for x in 1:100);
    for x in keys(dict)
            delete!(dict, x)
    end


As we need to `collect(keys(...))` to make a copy.

However the code above still runs with correct results. Even when it fails to return correct results, no error would be thrown. 

Just wondering in the language design point of view if the compiler or runtime can detect this sort of behaviour always?
Loading...