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 13303 - [XPath30] editorial: "in scope"
Summary: [XPath30] editorial: "in scope"
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XPath 3.0 (show other bugs)
Version: Working drafts
Hardware: All All
: P2 minor
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: 2011-07-19 20:32 UTC by Michael Dyck
Modified: 2011-09-12 20:26 UTC (History)
0 users

See Also:


Attachments

Description Michael Dyck 2011-07-19 20:32:25 UTC
There's an inconsistency re the meaning of "in scope".
Consider the example:

   for $v as xs:integer in (1,2) return
       for $v as xs:string in ("a", "b") return
           $v

At the point where the variable reference appears, what variables
are "in scope"? (Note that there's no question that the variable
reference refers to the xs:string variable.)

In one interpretation of the phrase, both $v variables are "in scope".
This interpretation is clearly the one in use in section 3.1.2:

    If a variable is bound in the static context for an expression,
    that variable is in scope for the entire expression. ...
    If a variable reference matches two or more variable bindings
    that are in scope, then the reference is taken as referring to
    the inner binding, that is, the one whose scope is smaller.

However, this interpretation has two problems:

(1)
It makes variable resolution dependent on information (size or
nestedness of scopes) that isn't present in the static context
(as defined).

(2)
It conflicts (more or less) with other passages in the spec:

(2a)
2.1.1 Static Context says:

    [Definition: In-scope variables. This is a mapping from expanded
    QName to type.]

where the word "mapping" presumably excludes the possibility that the
in-scope variables could contain two entries with the same expanded
QName. Mind you, this is a recent change. It used to say:
    This is a set of (expanded QName, type) pairs.


(2b)
2.2.5 Consistency Constraints says:

    For each (variable, type) pair in in-scope variables and
    the corresponding (variable, value) pair in variable values
    such that the variable names are equal, the value must match
    the type ...

If in-scope variables contains entries for both variables:
    ('v', xs:integer) ('v', xs:string)
then variable values must also have entries for both, e.g.:
    ('v', 1)          ('v', "a")
but then the consistency constraint might be taken to apply to all
four combinations, some of which violate the constraint. (You might
point out that only two of those combinations involve "corresponding"
pairs, but then if "corresponding" is so smart, why do we need to say
"such that the variable names are equal"?)

I'm not saying that the latter would be a reasonable stance, but
just that 2.1.1 and 2.2.5 appear to assume (and would certainly be
happier with) an interpretation in which *only* the xs:string variable
is "in scope" at the point of the variable reference.

---

Anyhow, I think the wording re "in scope" should be made more
consistent. As to which way, I think it would be simpler to change
the wording in 3.1.2 to use the interpretation that 2.1.1 and 2.2.5
appear to assume.
Comment 1 Jonathan Robie 2011-09-10 21:27:27 UTC
Very useful feedback. And I agree with the direction you suggest.

I added this phrase:

<quote>
If a variable is bound in the static context for an expression, that variable is in scope for the entire expression <phrase diff="add">unless it is occluded by another binding that uses the same name within that scope</phrase>
</quote>

The word "occluded" is used in this way several times in the section on FLWOR Expressions, so I thought using it here would be helpful.

I deleted this phrase:

<quote>
<phrase diff="del">If a variable reference matches two or more variable bindings that are in scope, then the reference is taken as referring to the inner binding, that is, the one whose scope is smaller.</phrase>
</quote>
Comment 2 Michael Dyck 2011-09-12 20:26:33 UTC
Instead of the phrase
    "unless it is occluded", 
I think
    "except where it is occluded"
might be more informative.

But your changes are sufficient for me to close this issue.