This is indeed surprising the first time you see it. I think it is because the lookup rules are to first look for a matching name, and when it has found a matching name it starts to look at overloads in that scope without searching further.
In your case it finds a function named foo in B so it doesn't bother looking in A.