Project

Profile

Help

Bug #6495

open

Spurious warning for xs:integer

Added by Norm Tovey-Walsh 3 months ago. Updated 3 months ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-08-07
Due date:
% Done:

0%

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

Description

On the xslt-list, Roger reports that this stylesheet generates a spurious warning:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xs"
                version="3.0">

<xsl:template match="/">
    <arcRadius>
        <xsl:variable name="legacy-ARINC-elmt-name" select="'ARC_Radius'" as="xs:string"/>
        <xsl:variable name="legacy-ARINC-elmt-value" select="'      '" as="xs:string"/>
        <xsl:variable name="whole-part" select="substring($legacy-ARINC-elmt-value,1,3)"/>
        <xsl:variable name="fraction-part" select="substring($legacy-ARINC-elmt-value,4,3)"/>
        <xsl:if test="$whole-part castable as xs:integer">
            <xsl:value-of select="concat(xs:string(xs:integer($whole-part)),'.',$fraction-part)"/>
        </xsl:if>
    </arcRadius>
</xsl:template>

</xsl:stylesheet>

And indeed it does:

Warning at char 29 in xsl:value-of/@select on line 14 column 99 of out.xsl:
  SXWN9027  Evaluation will always throw a dynamic error: Cannot convert zero-length string
  to an integer
<?xml version="1.0" encoding="UTF-8"?><arcRadius/>

This is a reported as a regression from 10.x EE to 12.5 EE.

Actions #1

Updated by Michael Kay 3 months ago

I think it's slightly unpredictable whether you get the warning or not, because there are two possible things that might happen first:

(a) we detect that $whole-part castable as xs:integer will always be false, and therefore ellminate the whole xsl:if instruction at compile time

(b) we detect that xs:string(xs:integer($whole-part)) will always fail if executed; expressions that can never succeed are always grounds for a warning.

So I suspect it's more a randomness than a regression.

We could try to control things so that (a) always happens first, but it's not easy - optimization happens incrementally in multiple phases.

IDEs like IntelliJ are pretty free about reporting warnings for such things these days, and I think it's entirely reasonable to do so.

Actions #2

Updated by Norm Tovey-Walsh 3 months ago

I think that's perfectly fine. But to be fair, warnings in the IDE aren't at all like warnings at runtime. In particular, because it's the user, not the developer, who is likely to see them.

Please register to edit this issue

Also available in: Atom PDF