Project

Profile

Help

Revision 508218de

Added by Michael Kay about 1 year ago

Fix bug #4537

View differences:

latest10/hej/net/sf/saxon/expr/Operand.java
27 27

  
28 28
public final class Operand implements Iterable<Operand>, ExpressionOwner {
29 29

  
30
    private Expression parentExpression;
30
    private final Expression parentExpression;
31 31
    private Expression childExpression;
32 32
    private OperandRole role;
33 33

  
......
81 81
        }
82 82
    }
83 83

  
84
    private static boolean DEBUG = false;
84
    private static final boolean DEBUG = false;
85 85
    public void detachChild() {
86 86
        if (DEBUG) {
87 87
            childExpression.setParentExpression(null);
......
196 196
     */
197 197

  
198 198
    public Iterator<Operand> iterator() {
199
        return new MonoIterator<Operand>(this);
199
        return new MonoIterator<>(this);
200 200
    }
201 201

  
202 202
    public void typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException {
latest10/hej/net/sf/saxon/expr/instruct/Choose.java
392 392
        // type of the top-level expression. It's important with tail recursion not to wrap a tail call in a type checking
393 393
        // expression just because a dynamic type check is needed on a different branch of the choice.
394 394
        for (int i = 0; i < size(); i++) {
395
            if (Literal.hasEffectiveBooleanValue(getCondition(i), false)) {
396
                // Don't do any checking if we know statically the condition will be false, because it could
397
                // result in spurious warnings: bug 4537
398
                continue;
399
            }
395 400
            try {
396 401
                actionOps[i].typeCheck(visitor, contextInfo);
397 402
            } catch (XPathException err) {
......
415 420
                    setAction(i, new ErrorExpression(new XmlProcessingException(err)));
416 421
                }
417 422
            }
423
            if (Literal.hasEffectiveBooleanValue(getCondition(i), true)) {
424
                break;
425
            }
418 426
        }
419 427
        Optimizer opt = visitor.obtainOptimizer();
420 428
        if (opt.isOptionSet(OptimizerOptions.CONSTANT_FOLDING)) {
......
523 531
            }
524 532
        }
525 533
        for (int i = 0; i < size; i++) {
534
            if (Literal.hasEffectiveBooleanValue(getCondition(i), false)) {
535
                // Don't bother with optimisation if the code won't be executed: bug 4537
536
                continue;
537
            }
526 538
            try {
527 539
                actionOps[i].optimize(visitor, contextItemType);
528 540
            } catch (XPathException err) {
......
543 555
                visitor.issueWarning("Branch " + (i + 1) + " of conditional will fail with a type error if executed. "
544 556
                        + ((ErrorExpression) getAction(i)).getMessage(), getAction(i).getLocation());
545 557
            }
558
            if (Literal.hasEffectiveBooleanValue(getCondition(i), true)) {
559
                // Don't bother with optimisation of subsequent branches if the code won't be executed: bug 4537
560
                break;
561
            }
546 562
        }
547 563

  
548 564
        if (size == 0) {

Also available in: Unified diff