This question is clearly off-topic on Code Review. However, it did receive an answer which essentially points out the problem and makes some suggestions. The problem this potentially causes is that it somewhat encourages users to ask off-topic questions anyway since they may just receive a useful answer. Should we actively discourage (i.e. down-voting or flagging for deletion) answers to such clearly off-topic questions?
No, we shouldn't encourage this. Broken code is broken code, and we're not Stack Overflow.
I left this comment on the answer:
Please note, questions involving code that's not working as intended, are off-topic on this site. If OP edits their post to address the problem and make their post on-topic, they make your answer moot. Protip: There are tons of on-topic questions to answer; you'll make more rep faster if you review code in questions that will get higher view counts for being on-topic. ;-) – Mat's Mug♦ 34 secs ago
Should we actively discourage answers to such clearly off-topic questions?
We should discourage those in the process of reviewing from posting answers to questions going to be closed, and discourage it in future practice (tell the user who has just done so that it's best not to in future)
If you've just spent X minutes writing up a really neat review, only to be told something like:
Can you delete this please? the question is off-topic and we want to close it.
However, something like:
Nice review! In future can you try to avoid posting on off-topic questions? We try to close and finish those questions and answers really just slow it down, and are probably likely to be ignored with the post anyway.
Would be much more civil, and avoiding conflict etc
Should we actively discourage (i.e. down-voting or flagging for deletion)
Don't go and downvote or flag for deletion answers to off-topic questions just because they answered an off-topic question, it's not necessarily the reviewers' fault/s for answering.
In the question you linked, the reviewer had a low reputation, so low in fact, that they wouldn't have seen the close votes, and probably even didn't particularly understand what SirPython's comment meant.