This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29173 - [QT3TS] xs-error tests expecting XPTY0004
Summary: [QT3TS] xs-error tests expecting XPTY0004
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 3 & XPath 3 Test Suite (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Tim Mills
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-02 14:56 UTC by Debbie Lockett
Modified: 2015-10-14 13:13 UTC (History)
3 users (show)

See Also:


Attachments

Description Debbie Lockett 2015-10-02 14:56:13 UTC
The following tests expect error code XPTY0004, but should the error be FORG0001?

xs-error-009   xs:error(xs:untypedAtomic(""))

xs-error-010   xs:error("")

xs-error-011   xs:error(1.0)

xs-error-012   xs:error(1e0)

xs-error-013   xs:error(1)

xs-error-014   xs:error(1) instance of xs:error

xs-error-032   xs:error(1) castable as xs:error

xs-error-033   xs:error(1) castable as xs:integer

xs-error-039   xs:error(1) cast as xs:error

xs-error-043   xs:error(1) instance of xs:error

xs-error-045   typeswitch (xs:error(1)) 
               case xs:error return fn:true()
               default return false()
Comment 1 Michael Kay 2015-10-02 15:08:26 UTC
Rationale on this: the xs:error function is defined to be equivalent to casting to a union type with no member types. This takes you to 19.3 (casting to union types), which takes you to 19.2.2. This defines the cast in terms of validation. Validation fails, because the value space is empty. Except where otherwise specified, validation failures result in FORG0001.

The significance of this is that calling xs:error() produces a dynamic error rather than a type error, which makes it safe to use for deliberate signalling of a dynamic error in a branch of a conditional. Indeed F+O section 18.4 explicitly says that casting to xs:error will always fail with a *dynamic* error.
Comment 2 Michael Kay 2015-10-02 15:16:37 UTC
The above rationale applies when the supplied value is a string or untypedAtomic. When it is any other type, e.g. integer, the relevant rule is in 19.3.5 casting to a union type: 

"If none of these conditions applies, the cast fails with a dynamic error [err:FORG0001]."
Comment 3 Tim Mills 2015-10-12 09:23:15 UTC
Could you please confirm which of the rules under point 5 of 3.18.3 Cast?

I can see that 

(c) cast is supported if the target type is a non-primitive atomic type and the input type is xs:string or xs:untypedAtomic.

applies in some of these cases, but not (for example) in xs-error-011.
Comment 4 Michael Kay 2015-10-12 09:42:50 UTC
XQuery 3.18.3 refers to F+O section 19 as the normative specification, so I tend to largely ignore it. It doesn't seem to handle the case of casting to a union type from a type other than string/untypedAtomic. I'll raise a bug on that.
Comment 5 Michael Kay 2015-10-12 09:49:13 UTC
I have raised bug #29192 against the XPath and XQuery specs: their non-normative summary of the casting rules is incomplete.
Comment 6 Tim Mills 2015-10-13 11:51:51 UTC
Test cases updated.

BTW, it would be nice to add a dependency other than XSD 1.1 for this, in view of the note:

   <!-- NOTE: An implementation supporting XSD 1.1 must support xs:error,
              however it is not an error for an implementation not supporting 
              XSD 1.1 to support xs:error. -->


Please mark as CLOSED if you agree with the resolution.  Otherwise, REOPEN.
Comment 7 Debbie Lockett 2015-10-14 13:13:49 UTC
Thanks, closing.