[FIX] XQuery, GH-1023: Do not optimize at run-time.

Please review before merging. Open questions:

 * Is this too much logic for run-time code?
 * Should `function() as item()+ { () }` be a *create-time* or a *call-time* error (if it is not caught statically)?
True; however, I think that it makes sense to enforce correct return types here, even if the code won’t be called.