Bug in evaluating conditionals? Not short-circuiting?

Saturday, 21 March 2015 · 2 messages · last reply 24 Mar 2015
MG
Marc van Grootel21 Mar 2015 15:12 #
Hi, I think I found a bug in 8.0.3 (and earlier)
declare function local:shortcircuit($a) {
  if ($a castable as xs:double
      and xs:double($a) gt 0) then
      $a
  else ()
};

local:shortcircuit('foo')
=> [FORG0001] Cannot cast to xs:double: "foo". In http://www.w3.org/TR/xpath/#booleans "An and expression is evaluated by evaluating each operand and converting its value to a boolean as if by a call to the boolean function. The result is true if both values are true and false otherwise. The right operand is not evaluated if the left operand evaluates to false." Haven't tested it for other conditionals. --Marc
LW
Leonard Wörteler24 Mar 2015 00:59 #
Hi Marc,
Quoted text · Marc van Grootel · 13 lines
Am 21.03.2015 um 15:12 schrieb Marc van Grootel: > I think I found a bug in 8.0.3 (and earlier) > > declare function local:shortcircuit($a) { > if ($a castable as xs:double > and xs:double($a) gt 0) then > $a > else () > }; > > local:shortcircuit('foo') > > => [FORG0001] Cannot cast to xs:double: "foo".
thanks! This is a bug in the code implementing variable inlining for the and and or expression. I opened an issue [1] and submitted a fix [2] to GitHub, which Christian will surely merge as soon as he is back from his business trip. Cheers, Leo [1] https://github.com/BaseXdb/basex/issues/1108 [2] https://github.com/BaseXdb/basex/pull/1109

⚡Generated with XQuery