Project

Profile

Help

Bug #6332

closed

Local variable depending on current-output-uri may be evaluated with the wrong context

Added by Michael Kay 3 months ago. Updated 3 months ago.

Status:
Resolved
Priority:
Low
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
2024-01-29
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
12, trunk
Fix Committed on Branch:
12, trunk
Fixed in Maintenance Release:
Platforms:

Description

If a local variable is bound to the value of current-output-uri() or current-output-uri#0, and there is only a single reference to the variable, the variable reference might be inlined even though it appears within an xsl:result-document instruction where the current output URI has changed.

Revealed by XSLT 4.0 test case current-output-uri-402.

In LetExpression.optimize(), line 333 (if (ExpressionTool.changesXsltContext(getSequence())) {...} is designed to prevent this, and it does so for dependencies on other parts of the XSLT dynamic context such as regex groups; but it doesn't take current output URI into account.

Actions #1

Updated by Michael Kay 3 months ago

Test current-output-uri-011 shows that this is working OK for an actual function call on current-output-uri(). The very similar test current-output-uri-402 demonstrates that it is failing for a named function reference current-output-uri#0.

The reason that the first test succeeds is that the call on current-output-uri() is (rather spuriously) given the special property HAS_SIDE_EFFECTS.

The reason that the similar test analyse-string-403 works (using regex-group rather than current-output-uri) is that the variable in question is not inlined because the instruction that changes the dynamic context (xsl:analyze-string) is classified as a looping instruction, which prevents the variable being inlined.

Actions #2

Updated by Michael Kay 3 months ago

Fixed by changing ExpressionTool.changesXsltContext() to return true for a DynamicFunctionCall - for the same reasons as we do so for things like xsl:apply-templates; we don't know what it will do, so we are conservative.

Actions #3

Updated by Michael Kay 3 months ago

  • Status changed from New to Resolved
  • Applies to branch 12, trunk added
  • Fix Committed on Branch 12, trunk added

Please register to edit this issue

Also available in: Atom PDF