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 10978 - [XQuery10] External variable declaration in main module with same name as another external variable in a library module
Summary: [XQuery10] External variable declaration in main module with same name as ano...
Status: RESOLVED INVALID
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 1.0 (show other bugs)
Version: Recommendation
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-05 15:50 UTC by Henry Zongaro
Modified: 2010-10-06 14:51 UTC (History)
1 user (show)

See Also:


Attachments

Description Henry Zongaro 2010-10-05 15:50:52 UTC
Consider the following modules.  Will the result of this query always be true?

(: Module A :)
module namespace a = "http://example.org/a";
declare variable $a:ext external;

(: Module B :)
module namespace b= "http://example.org/b";
import module namespace a = "http://example.org/a";
declare variable $b:var := $a:ext;

(: Main module :)
import module namespace b = "http://example.org/b" at "moduleB.xq";
declare namespace a = "http://example.org/a";
declare variable $a:ext external;

declare function local:identical($arg1, $arg2) {
  if (empty($arg1)) then
     empty($arg2)
  else if (empty($arg2)) then
     false()
  else
    ((let $f1 := $arg1[1], $f2 := $arg2[1]
      return
        if ($f1 instance of node()) then
          if ($f2 instance of node()) then
            ($f1 is $f2)
          else
            false()
        else
          ($f1 eq $f2))
     and local:identical($arg1[position() gt 1], $arg2[position() gt 1]))
};

local:identical($a:ext, $b:var)


Notice that the main module declares an external variable, a:ext, with the same expanded name as a variable in library module A.  My understanding is that this is not an error.  According to section 4.11 of XQuery 1.0,[1] "It is a static error if the expanded QName of a variable declared in an imported module is equal (as defined by the eq operator) to the expanded QName of a variable declared in the importing module or in another imported module (even if the declarations are consistent) [err:XQST0049]."  The main module does not import library module A, so that rule is not contravened.  However, there are two external variables in the query as a whole whose expanded names are identical.

I can imagine two reasonable implementation strategies for supplying the value of an external variable:  1) the implementation defines a mechanism for supplying the value of a variable, identifying it by means of its expanded name; or 2) the implementation defines a mechanism for supplying the value of a variable, identifying it by means of its expanded name along with its module namespace URI, if any.  This by no means exhausts all the possibilities.

Given the first implementation strategy, the result of the query will always be true.  Right now, both of those implementation strategies seem to be permitted.  However it seems like an interoperability problem not to improve upon this by doing one of the following:

1) Make it clear that the two declarations declare the same variable, though possibly with cumulative type requirements.
2) Make it absolutely clear that they are distinct variables, and that implementations should enable users to set them independent of one another.
3) Make it an error (or perhaps a violation of a consistency constraint).


Note that external function declarations have the same issue.

[1] http://www.w3.org/TR/xquery/#id-module-import
Comment 1 Michael Kay 2010-10-06 08:23:55 UTC
Note that although we didn't make it normative, we did decide to supply guidance on this question in Appendix J.2: 

"Although other interpretations are possible, it is suggested that in such cases implementations should require the names of global variables and functions to be unique within the query as a whole: that is, if two modules with the same module URI participate in a query, the names of their global variables and functions should not overlap."

(The "that is" should really be a "for example", since you have shown a different way whereby two global variables can have the same name.)
Comment 2 Henry Zongaro 2010-10-06 14:51:53 UTC
I missed the advice in J.2.  I will withdraw the bug report.