During expression parsing the first stage of rewriting an expression is called "simplification". One of the things that happens during this stage is that functions that take a default argument have the default expanded, for example name() is rewritten as name(.). The code for each expression is responsible for ensuring that its subexpressions are simplified, recursively.
The error() function, in an attempt to avoid early evaluation at compile time, is not simplifying its arguments. This can cause an internal exception: in the example above it leads to the stack trace
caused by the fact that subsequent stages of processing expect the name() function to have an argument.
A patch (to net.sf.saxon.functions.Error) is in Subversion.