Bug #6495
openSpurious warning for xs:integer
0%
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.
Updated by Michael Kay 4 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.
Updated by Norm Tovey-Walsh 4 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