Node lifetime is shorter than expected due to let variable inlining

Bug #868640 reported by Federico Cavalieri
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
Fix Released
High
Markos Zaharioudakis

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>

Changed in zorba:
assignee: nobody → Markos Zaharioudakis (markos-za)
importance: Undecided → Medium
Changed in zorba:
importance: Medium → High
Changed in zorba:
milestone: none → 2.7
Chris Hillery (ceejatec)
Changed in zorba:
milestone: 2.7 → 3.0
Changed in zorba:
milestone: 3.0 → 2.8
Changed in zorba:
status: New → Fix Committed
Changed in zorba:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.