UserFunctionCall ufc = (UserFunctionCall)unboundFunctionCalls.get(i);
QueryModule importingModule = (QueryModule)correspondingStaticContext.get(i);
correspondingStaticContext.set(i, null); // for garbage collection purposes
// The original UserFunctionCall is effectively a dummy: we weren't able to find a function
// definition at the time. So we try again.
final StructuredQName q = ufc.getFunctionName();
final int arity = ufc.getNumberOfArguments();
XQueryFunction fd = lib.getDeclaration(q, ufc.getArguments());
if (fd != null) {
fd.registerReference(ufc);
ufc.setStaticType(fd.getResultType());
ufc.setConfirmed(true);
// Check that the result type and all the argument types are in the static context of the
// calling module
importingModule.checkImportedFunctionSignature(fd);
} else {
String msg = "Cannot find a matching " + arity +
"-argument function named " + q.getClarkName() + "()";
if (!config.isAllowExternalFunctions()) {
msg += ". Note: external function calls have been disabled";
}
XPathException err = new XPathException(msg, ufc);
err.setErrorCode("XPST0017");