The previous behaviour would do this:

1. Does the namespaced function exist?
2. If yes, jump to end
3. Does the fallback function exist?
4. If yes, jump to end (by skipping the if block below)
5. Try to load the original function

Instead the behaviour needs to be:

1. Does the original function exist?
2. If so, jump to end
3. Otherwise, try to load it
4. If it isn't loaded, does the fallback exist?
5. If so, jump to end,
6. Otherwise, try to load it.

The test actually breaks the behaviour slightly by preventing the namespaced version of the function being loaded if there is a global function that matches the fallback already known.

Looking at this diff fresh, I think there is some refactoring that could be done, as there is probably some redundant code being generated here, however the logic itself is fine.