offer.containingExpression = replacement;
Expression newTerm = term.promote(offer, this);
if (newTerm != null && offer.accepted) {
Expression predicate = visitor.typeCheck(newTerm, sequence.getItemType(th));
// If the result of the predicate might be a number, wrap it in a call of boolean()
int rel = th.relationship(predicate.getItemType(th), BuiltInAtomicType.INTEGER);
if (rel != TypeHierarchy.DISJOINT) {
predicate = SystemFunction.makeSystemFunction("boolean", new Expression[]{predicate});
}
selection = new FilterExpression(selection, predicate);
ExpressionTool.copyLocationInfo(this, selection);