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 4551 - K-NormalizeUnicodeFunc-13
Summary: K-NormalizeUnicodeFunc-13
Status: RESOLVED FIXED
Alias: None
Product: XML Query Test Suite
Classification: Unclassified
Component: XML Query Test Suite (show other bugs)
Version: 1.0.2
Hardware: PC Windows NT
: P2 normal
Target Milestone: ---
Assignee: Frans Englich
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-10 16:58 UTC by Tim Mills
Modified: 2015-08-08 01:15 UTC (History)
3 users (show)

See Also:


Attachments

Description Tim Mills 2007-05-10 16:58:36 UTC
I'd be grateful if someone could offer some guidance as to whether it is permissable for this query to return without error.

This hinges on whether it is required that ("a string", error()) must evaluate the error() in the sequence.  From XQuery 1.0:

"The effect of these rules is that the processor is free to stop examining further items in a sequence as soon as it can establish that further items would not affect the result except possibly by causing an error."

"Another consequence of these rules is that where none of the items in a sequence contributes to the result of an expression, the processor is not obliged to evaluate any part of the sequence. Again, however, the processor cannot dispense with a required cardinality check:"

Since error() has type none, the sequence("a string", error()) has type xs:string, thus we know that the cardinality constaint is obeyed.  error() thus does not contribute to the result of the expression.

(:*******************************************************:)
(: Test: K-NormalizeUnicodeFunc-13                       :)
(: Written by: Frans Englich                             :)
(: Date: 2007-01-22T21:16:10+01:00                       :)
(: Purpose: A test whose essence is: `normalize-unicode(("a string", error()), "
NFC")`. :)
(:*******************************************************:)
normalize-unicode(("a string", error()), "NFC")
Comment 1 Andrew Eisenberg 2007-05-30 19:32:37 UTC
I believe that another paragraph from section 2.3.4, Errors and Optimization, must be considered:

"There is an exception to this rule: If a processor evaluates an operand E (wholly or in part), then it is required to establish that the actual value of the operand E does not violate any constraints on its cardinality. For example, the expression $e eq 0 results in a type error if the value of $e contains two or more items. A processor is not allowed to decide, after evaluating the first item in the value of $e and finding it equal to zero, that the only possible outcomes are the value true or a type error caused by the cardinality violation. It must establish that the value of $e contains no more than one item."


The first parameter of normalize-unicode is of type string?. The operands of the sequence constructor that makes up the first argument must be evaluated to ensure that the sequence does not contain more than one item.

For this reason, I believe that the query cannot return a value other than an error. Frans, do you agree with this?
Comment 2 Michael Kay 2007-05-30 20:34:45 UTC
I'm puzzled by your reasoning, Andrew. The paragraph you quote says that "it is required to establish that the actual value of the operand E does not violate any constraints on its cardinality". But Tim asserts (and no doubt he is right) that this has already been done during static analysis, which determined the cardinality of ("a string", error()) to be (1,1). 

This seems like an absurd and undesirable result, but it's hard to argue with the logic that the spec allows it.

Or perhaps it's not so absurd after all: the only reason we have the rule that you can't do early-exit until you've established the cardinality is to outlaw the XPath 1.0 "use first item, ignore rest of sequence" semantics, because we think that's error-prone. Here, if you carried on evaluating the sequence, you would not get a cardinality error but whatever error is thrown by error(), so it doesn't fall into this category and shouldn't be caught by this rule.
Comment 3 Tim Mills 2007-05-31 09:32:09 UTC
I'm now less convinced that

("a string", error())

is of type xs:string.  In FS 8.4

quantifier(none) = 1

The type none matches no values, therefore from the FS rules in 8.3.1 Matches and 8.3.2 Subtyping (<:) there is no rule:

--------------------------------
statEnv |-  error() matches none

therefore we can't apply:

statEnv |-  Value1 matches Type1
statEnv |-  Value2 matches Type2
---------------------------------------------
statEnv |-  Value1,Value2 matches Type1,Type2

so we have to deduce that whatever type (xs:string, none) is, it certainly isn't a subtype of xs:string.  All we can say is that it is of type (xs:string, none), which is roughly xs:string+.

Therefore this test should allow for a type checking error as well as the error thrown by error().  Quite a few of the tests use a similar construct, so will also need to permit a type check error.

As an aside, I do find it a little strange that (Type|none) = Type _and_ quantifier(none) = 1.  It almost seems as if a type which matches no values should have the unusual quantifier of zero.
Comment 4 Michael Kay 2007-05-31 10:01:07 UTC
>It almost seems as if a type which matches no values should have the unusual quantifier of zero.

I handled it that way at one time but it caused too many problems. I now type error() as item(), which works for optimistic typing - it means that error() will never cause a static type error, except in the pathological case where the required type is empty-sequence(), because item() overlaps every other type. (Perhaps I should have chosen item()? which would work for empty-sequence() as well...)
Comment 5 Frans Englich 2007-06-13 11:22:43 UTC
Being more or less incapable to comment on FS, I gladly trusted Tim and added XPTY0004 to the baseline. XQTS_current.zip is updated in CVS.
Comment 6 Tim Mills 2007-06-13 11:44:19 UTC
Thanks.
Comment 7 Josh Spiegel 2009-07-22 23:25:08 UTC
I think this should be reopened to update the following tests as well:

K-NumericAdd-34 
   (4, error()) + 3

K-NumericAdd-35 
   3 + (4, error())

K-ValCompTypeChecking-39
   3 eq (3, error())

K-ValCompTypeChecking-41
   (3, error()) eq 3

Thanks,
Josh
Comment 8 Michael Kay 2009-07-23 08:34:07 UTC
I think these are simply bad tests. They are testing an area where the spec is fuzzy and where we have in effect chosen to leave it fuzzy; so the outcome of the test tells us very little.

It would be much more useful to replace the call on error() with something like

if (doc-available('unavailable.xml')) then () else error()

to remove the effect of static type inferencing.
Comment 9 Tim Mills 2009-07-23 08:39:55 UTC
if (doc-available('unavailable.xml')) then () else error()

has static type 'empty | none' which is equivalent to 'empty' according to the Formal Semantics.





Comment 10 Frans Englich 2009-10-14 13:36:34 UTC
Fixed in CVS by adding XPST0005 to tests mentioned in comment #7.
Comment 11 Tim Mills 2009-10-14 15:39:11 UTC
Thanks.
Comment 12 Josh Spiegel 2010-11-30 01:24:24 UTC
I think this fix is incomplete.  

I can see that XPST0005 was added for K-NumericAdd-34 and K-NumericAdd-35 but the tests themselves seem unchanged.  I don't think adding XPST0005 makes sense unless you also change the tests as described in comment #8.  

I don't see any changes for K-ValCompTypeChecking-39 or K-ValCompTypeChecking-41 even though comment #10 indicates they have changed.

If K-NormalizeUnicodeFunc-13 accepts XPTY0004 as a valid result, it seems odd to me if the tests in comment #7 do not accept XPTY0004 as well. i.e. isn't Tim's analysis in comment #3 valid for the comment #7 tests as well - "(integer, none) isn't a subtype of integer"? I expected the fix to be adding XPTY0004 as a valid result for each of the comment #7 tests (not XPST0005).
Comment 13 O'Neil Delpratt 2013-06-11 14:43:34 UTC
I believe this bug has been addressed in QT3.
Comment 14 Josh Spiegel 2015-08-08 01:15:41 UTC
I have updated K-NumericAdd-34 and K-NumericAdd-35 so they are consistent with K-ValCompTypeChecking-39 and K-ValCompTypeChecking-41.  The tests now accept XPTY0004 as well as FOER0000 (and not XPST0005) which is justified by the analysis in comment 3.  See also bug 26860.