This is a dumb mistake:
List<Foo> fooList = new List<Foo>();
Foo f = new Foo();
while (something.Read()) {
f.Fill(something.GetRecord());
fooList.Add(f);
}
Of course, I should instantiate a new Foo inside the loop.
Can a compiler detect this kind of mistake at compile time?
To naïve eyes it looks like it should be able to detect this behavior (filling a List with instances of the same object in a loop). It should then issue a warning like "You are filling a container with the same instance more than once.".
So, how naïve am I being? Do you know of a language where something like this exists?