Consider the following test case:
let $fn := function($trigger as xs:boolean, $arg as array(*)) { if ($trigger) then ($arg[1]) else () } return $fn(true(), ())
This should (and does) throw an error XPTY0004 as the $arg argument is the empty sequence, not an array. However, now consider what happens if we set $trigger to false():
let $fn := function($trigger as xs:boolean, $arg as array(*)) { if ($trigger) then ($arg[1]) else () } return $fn(false(), ())
This technically does not use the $arg argument, so I'm not sure if it's required to throw here? Unfortunately though, the behavior is different depending on the value of the debug option. Worse, it throws only if debug is off, leading to errors that typically only occur in production setups.
With debug: true: returns "" (assuming evaluation to STRING)
With debug: false: throws Uncaught Error: XPTY0004: Multiplicity of function argument of type array(*) for dynamic-function is incorrect. Expected exactly one
Consider the following test case:
This should (and does) throw an error XPTY0004 as the
$argargument is the empty sequence, not an array. However, now consider what happens if we set$triggertofalse():This technically does not use the
$argargument, so I'm not sure if it's required to throw here? Unfortunately though, the behavior is different depending on the value of thedebugoption. Worse, it throws only ifdebugis off, leading to errors that typically only occur in production setups.With
debug: true: returns""(assuming evaluation to STRING)With
debug: false: throwsUncaught Error: XPTY0004: Multiplicity of function argument of type array(*) for dynamic-function is incorrect. Expected exactly one