#982 Internal Error when variable used with Unary Minus operator

Michael Kay

The error message "Saxon Internal Error: local variable whose binding has been deleted" may appear when a variable reference appears within the operand of a unary minus operator (for example -$count) if this is the only reference to the variable.

Explanation: every expression is responsible in its typeCheck() method for ensuring that visitor.typeCheck() is
called on its operand expressions. This has always been true; but 9.2 is a bit more inclined to crash if an
expression fails to do this, because the typeCheck() pass is now responsible for counting how many references
there are to local variables. Previously this was done in a separate pass which sometimes led to very bad
compile-time performance. The NegateExpression is failing to do this, which means at the level of the
LetExpression the code thinks that the variable is unreferenced and it is therefore deleted from the expression tree.

The code for NegateExpression.typeCheck() contains a comment claiming that the operand does not need to be type-checked because this has already been done by the caller (ArithmeticExpression). However, in XSLT each expression is subjected to typeCheck() twice, first at the level of a single XPath expression, then at the level of an XSLT template or function. In the second pass, NegateExpression.typeCheck() is not called from ArithmeticExpression, so the operand will not have been type-checked on this pass, and it is on this pass that the references to the local variable are counted (in the first pass, the reference has not yet been bound to the containing LetExpression).

A patch (to net.sf.saxon.expr.NegateExpression) is being committed on both the 9.1 and 9.2 branches.


  • Michael Kay

    Michael Kay - 2009-10-22

    Fixed in

  • Michael Kay

    Michael Kay - 2009-10-29

    Also fixed in