[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)?