← Back to team overview

zorba-coders team mailing list archive

[Bug 868640] Re: Node lifetime is shorter than expected due to let variable inlining

 

** Changed in: zorba
    Milestone: None => 2.7

-- 
You received this bug notification because you are a member of Zorba
Coders, which is the registrant for Zorba.
https://bugs.launchpad.net/bugs/868640

Title:
  Node lifetime is shorter than expected due to let variable inlining

Status in Zorba - The XQuery Processor:
  New

Bug description:
  A query like
  let $x:=<a/>
  return by-ref(ref($x))

  gets rewritten (in some case, depending on the complexity of the expression and number of references to the variable) as:
  by-ref(ref(<a/>))

  Thus the node has been destroyed when by-ref is called.

  The following test named reference_5.xq:
  import module namespace idd = "http://www.zorba-xquery.com/reference"; at "reference.xqlib";
  import module namespace id = "http://www.zorba-xquery.com/modules/node-reference";;
  import module namespace doc = "http://www.zorba-xquery.com/modules/store/dynamic/documents";;

  variable $node:=<root>global</root>;

  fn:put(<root>doc</root>,"doc");

  
  <result>
  <temporary-variable-in-scope>{let $temp:=<root>temp</root> return id:node-by-reference(id:node-reference($temp))}</temporary-variable-in-scope>
  <temporary-variable-in-scope>{
  let $temp:=<root>temp</root> 
  return
  let $ref:=id:node-reference($temp)
  return
  id:node-by-reference($ref)
  }</temporary-variable-in-scope>
  <temporary-variable-in-scope>{
  for $i in (1 to 3)
  let $temp:=<root>temp</root> 
  let $ref:=id:node-reference($temp)
  return
  id:node-by-reference($ref)
  }</temporary-variable-in-scope>

  <temporary-variable-in-scope>{let $temp:=<root>temp</root> return id
  :node-by-reference(id:node-reference($temp))}</temporary-variable-in-
  scope>

  </result>

  Should return:
  <?xml version="1.0" encoding="UTF-8"?>
  <result>
    <temporary-variable-in-scope>
      <root>temp</root>
    </temporary-variable-in-scope>
    <temporary-variable-in-scope>
      <root>temp</root>
    </temporary-variable-in-scope>
    <temporary-variable-in-scope>
      <root>temp</root>
      <root>temp</root>
      <root>temp</root>
    </temporary-variable-in-scope>
    <temporary-variable-in-scope>
      <root>temp</root>
    </temporary-variable-in-scope>
  </result>

  Instead it returns:
  <?xml version="1.0" encoding="UTF-8"?>
  <result>
    <temporary-variable-in-scope/>
    <temporary-variable-in-scope/>
    <temporary-variable-in-scope/>
    <temporary-variable-in-scope/>
  </result>

To manage notifications about this bug go to:
https://bugs.launchpad.net/zorba/+bug/868640/+subscriptions


References