Of course it's a good idea to fix your answer if there is a mistake in it, whether it's a mistake you noticed or a mistake that someone else noticed.
If you point out a mistake in someone's answer you should want them to fix it; that should be a goal of you pointing out their mistake. You shouldn't be calling someone out just to shame them without any expectation of them fixing the error.
Fixing the answer ensures that the highly upvoted answer at the top of the list is correct; rather than forcing viewers to read several answers down the list, or to read through a bunch of comments, in order to find out that it's not working or how to fix it. Remember that the primary goal here at SO/SE is creating a useful repository of information; editing the answer as was done here absolutely helps accomplish that.