I did a quick search to see if this has been asked, but it didn't seem to be. The intent behind this question is from how this question was handled, but is not limited to it.
The situation is an asker posts broken code. It gets an answer. (Question may get closed as 'off-topic broken code'). OP fixes their code to make it on-topic.
This is directly addressed in the following meta questions:
Should you refrain from answering questions that are likely to get closed?
Where answers should refrain from answering these questions.
Our close reason meta thread for broken code.
Where it says we close your question to prevent answers. And that you should edit the code to not be broken.
For an iterative review, is it okay to edit my own question to include revised code?
Which says OP shouldn't edit code into the question.
I think that the sentiment of the question Preventing the ability to re-open off-topic questions by explaining how it's broken in an answer can come into play here too. Where Mat's Mug's last paragraph explains why we could allow these edits:
If OP wants a peer review and edits their question with the working code, IMO it's the hasty FGITW (fastest gun in the west) non-review answer that should be removed; OP is entitled to have a chance to fix their post and their standing, without having to create a new question (heck, what if they're Q-banned by then?) - it's a matter of fairness.
How should we deal with questions that are edited to become on-topic, if there is already an answer to the question? As there seems to be conflicting information above, should we allow the asker to edit them?