A fix and a test case for gh-300

A fix and a test case for gh-300: misleading error message for a
non-existing function.

First, check that a function exists. Then check access rights
to the function.