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 2692 - for $p at $p in EXP return $p
Summary: for $p at $p in EXP return $p
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 1.0 (show other bugs)
Version: Candidate Recommendation
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Don Chamberlin
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-11 13:06 UTC by Michael Kay
Modified: 2006-03-28 17:40 UTC (History)
0 users

See Also:


Attachments

Description Michael Kay 2006-01-11 13:06:43 UTC
(previously raised in WG email at
http://lists.w3.org/Archives/Member/w3c-xml-query-wg/2005Nov/0001.html -
transferred here by virtue of action A-281-01)

The expression

for $p at $p in EXP return $p

is not currently an error; it seems that the $p in the return clause is bound to
the second of the two declared variables, and that the first one is inaccessible.

This doesn't seem a useful thing to allow.

Discussion in the Working Group suggested a variety of positions on this. These
can be summarised by the following options:

A. Do nothing; the above construct remains allowed.

B. Introduce a rule that says the two iteration variables associated with the
same ExprSingle in a ForClause must have distinct names. (So the above construct
is prohibited, but "for $p in X, $p in Y return $p*$p" remains allowed.)

C. Introduce a rule that requires all the variables bound in a single FLWOR
expression to have distinct names

D. Disallow all shadowing of local variables.

In discussion, several people pointed to the common beginner's mistake of writing

let $x := 0
for $i in //item
  let $x := $x + $i/@price
  return $x

which is currently permitted, but does not do what this user expected. There is
a case for tightening the rules to catch this error. This would be achieved by
option C. On the other hand, the slight variant

let $x := 0
for $i in //item return
  let $x := $x + $i/@price
  return $x

would only be caught by option D.

There was some discussion of process/policy. Should we be making design changes
at this late stage of development? Perhaps we should, because it's only at this
late stage that we are able to collect real usability feedback.
Comment 1 Don Chamberlin 2006-01-23 17:20:34 UTC
Michael,
The Query and XSLT working groups discussed this issue at their meeting on 
January 17, 2006, and agreed to adopt Alternative "B" as described above. In 
XQuery, in a for-clause of a FLWOR expression, each positional variable must be 
distinct from the iteration variable with which it is paired (that is, the 
variables on the left and right of an "as" keyword must have distinct names). 
This change does not affect XPath. The XQuery specification will be edited to 
include this new rule. Since you were present for the discussion of this issue, 
I am marking this bug report "closed".
Regards,
Don Chamberlin
Comment 2 Michael Kay 2006-03-28 15:06:48 UTC
Could the editor please let us know what the new error code will be?
Comment 3 Don Chamberlin 2006-03-28 17:40:56 UTC
Sure. Here are the new error code and message:

XQST0089: It is a static error if a variable bound in a for clause of a FLWOR expression, and its associated positional variable, do not have distinct names (expanded QNames).