Bug report - argument = context item, param value several items

Wednesday, 9 April 2025 · 4 messages · last reply 10 Apr 2025
HR
Hans-Juergen Rennau9 Apr 2025 20:29 #
Dear BaseX people, I have encountered a bug (?). Please consider this code: = = = = = = = = = begin = = = declare namespace f="http://weatherreport.org/heavyweather"; declare function f:relatedNames($node, $relationship) as xs:string* { let $fnName := function($node) { let $_DEBUG := trace(count($node), '#node: ') return name($node)} let $items := switch($relationship) case 'child' return $node/* default return error() return $items/$fnName(.) => distinct-values() => sort() => string-join(', ')}; let $doc := <doc><a/><b/><c/></doc>return f:relatedNames($doc, 'child') = = = = = = = = = end = = = = = = = = = = = = output = = =#node: 3Stopped at C:/projects/foxpath-examples/pre-balisage/problem-basex2.xq, 15/25:[XPTY0004] Item expected, sequence found: (<a/>, <b/>, <c/>).= = = = = = = = = = = = = = = = The call $fnName(.) receives a single item, but three items arrive at the function item! With kind regards,Hans-Jürgen PS: The funny switch() seems to play a part in the game, when I removed it, the issue vanished.PPS: BaseX 11.8 [Standalone]
CG
Christian Grün9 Apr 2025 21:44 #
Hi Hans-Jürgen, Thanks for the observation. A simplified version of your query is:
let $a := 'x'
let $b := if($a) then (<a/>, <b/>) else error()
return $b/name()
The problem has been fixed in the latest snapshot [1]. Best, Christian [1] https://files.basex.org/releases/latest/
Quoted text · Hans-Juergen Rennau · 47 lines
On Wed, Apr 9, 2025 at 8:29 PM Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Dear BaseX people, > > I have encountered a bug (?). Please consider this code: > > = = = = = = = = = begin = = = > > declare namespace f="http://weatherreport.org/heavyweather"; > > declare function f:relatedNames($node, $relationship) as xs:string* { > let $fnName := > function($node) { > let $_DEBUG := trace(count($node), '#node: ') > return name($node)} > > let $items := > switch($relationship) > case 'child' return $node/* > default return error() > return > $items/$fnName(.) => distinct-values() => sort() => string-join(', > ') > }; > > let $doc := <doc><a/><b/><c/></doc> > return f:relatedNames($doc, 'child') > > = = = = = = = = = end = = = > > = = = = = = = = = output = = = > #node: 3 > Stopped at C:/projects/foxpath-examples/pre-balisage/problem-basex2.xq, > 15/25: > [XPTY0004] Item expected, sequence found: (<a/>, <b/>, <c/>). > = = = = = = = = = = = = = = = = > > The call $fnName(.) receives a single item, but three items arrive at the > function item! > > With kind regards, > Hans-Jürgen > > PS: The funny switch() seems to play a part in the game, when I removed > it, the issue vanished. > PPS: BaseX 11.8 [Standalone] > >
HR
Hans-Juergen Rennau9 Apr 2025 23:18 #
Simply phantastic! Simply ... BaseX! Thank you, greetings - Hans-Jürgen Am Mittwoch, 9. April 2025 um 21:44:11 MESZ hat Christian Grün <christian.gruen at gmail.com> Folgendes geschrieben: Hi Hans-Jürgen, Thanks for the observation. A simplified version of your query is:
let $a := 'x'
let $b := if($a) then (<a/>, <b/>) else error()
return $b/name()
The problem has been fixed in the latest snapshot [1]. Best, Christian [1] https://files.basex.org/releases/latest/
Quoted text · Hans-Juergen Rennau · 55 lines
On Wed, Apr 9, 2025 at 8:29 PM Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Dear BaseX people, > > > I have encountered a bug (?). Please consider this code: > > > = = = = = = = = = begin = = = > > > declare namespace f="http://weatherreport.org/heavyweather"; > > declare function f:relatedNames($node, $relationship) as xs:string* { > let $fnName := > function($node) { > let $_DEBUG := trace(count($node), '#node: ') > return name($node)} > > let $items := > switch($relationship) > case 'child' return $node/* > default return error() > return > $items/$fnName(.) => distinct-values() => sort() => string-join(', ') > }; > > > let $doc := <doc><a/><b/><c/></doc> > return f:relatedNames($doc, 'child') > > > > = = = = = = = = = end = = = > > > > = = = = = = = = = output = = = > #node: 3 > Stopped at C:/projects/foxpath-examples/pre-balisage/problem-basex2.xq, 15/25: > [XPTY0004] Item expected, sequence found: (<a/>, <b/>, <c/>). > > = = = = = = = = = = = = = = = = > > > > > The call $fnName(.) receives a single item, but three items arrive at the function item! > > > With kind regards, > Hans-Jürgen > > > PS: The funny switch() seems to play a part in the game, when I removed it, the issue vanished. > PPS: BaseX 11.8 [Standalone]
CG
Christian Grün10 Apr 2025 08:34 #
A little note:
  let $_DEBUG := trace(count($node), '#node: ')
  return name($node)}
With XQuery 4, you can use fn:message to avoid unused variables (the official successor of prof:dump) [1]:
  message(count($node), '#node: '),
  name($node)}
Quoted text · Hans-Juergen Rennau · 76 lines
On Wed, Apr 9, 2025 at 11:18 PM Hans-Juergen Rennau <hrennau at yahoo.de> wrote: > Simply phantastic! Simply ... BaseX! > > Thank you, greetings - > Hans-Jürgen > > Am Mittwoch, 9. April 2025 um 21:44:11 MESZ hat Christian Grün < > christian.gruen at gmail.com> Folgendes geschrieben: > > > Hi Hans-Jürgen, > > Thanks for the observation. A simplified version of your query is: > > let $a := 'x' > let $b := if($a) then (<a/>, <b/>) else error() > return $b/name() > > The problem has been fixed in the latest snapshot [1]. > > Best, > Christian > > [1] https://files.basex.org/releases/latest/ > > > On Wed, Apr 9, 2025 at 8:29 PM Hans-Juergen Rennau <hrennau at yahoo.de> > wrote: > > Dear BaseX people, > > I have encountered a bug (?). Please consider this code: > > = = = = = = = = = begin = = = > > declare namespace f="http://weatherreport.org/heavyweather"; > > declare function f:relatedNames($node, $relationship) as xs:string* { > let $fnName := > function($node) { > let $_DEBUG := trace(count($node), '#node: ') > return name($node)} > > let $items := > switch($relationship) > case 'child' return $node/* > default return error() > return > $items/$fnName(.) => distinct-values() => sort() => string-join(', > ') > }; > > let $doc := <doc><a/><b/><c/></doc> > return f:relatedNames($doc, 'child') > > = = = = = = = = = end = = = > > = = = = = = = = = output = = = > #node: 3 > Stopped at C:/projects/foxpath-examples/pre-balisage/problem-basex2.xq, > 15/25: > [XPTY0004] Item expected, sequence found: (<a/>, <b/>, <c/>). > = = = = = = = = = = = = = = = = > > The call $fnName(.) receives a single item, but three items arrive at the > function item! > > With kind regards, > Hans-Jürgen > > PS: The funny switch() seems to play a part in the game, when I removed > it, the issue vanished. > PPS: BaseX 11.8 [Standalone] > >

⚡Generated with XQuery