To make a compiler automatically handle all of the cases like that, you will need to do an extensive static analysis, which would make compiling take forever.
Maybe autofix as we type, or autofix when it save the document / advance to next line.