Symptom: "*** Internal Saxon error: local variable encountered whose binding has been deleted ", with a variable name such as saxon:dot1111763.
The problem is caused by an optimizer rewrite that extracts subexpressions dependent on the context item from the "return" clause of a "for" expression in XPath or XQuery. The optimizer rewrite fails to reset the cached properties of all containing expressions affected by the change, with the effect that a subsequent optimization on the same part of the tree is misled into thinking that such an expression has no dependencies on local variables. This can cause a variable reference within the subtree to remain in the subtree when the corresponding declaration is removed on the false assumption that it is unreferenced.
A patch is being raised: affects method factorOutDot() in module ExpressionTool, in the 9.2 branch only.