MarkLogic not enforcing function signature

Viewed 45

I'm getting surprising behavior when passing an empty sequence to a function when the function signature doesn't allow it. Example in Query Console:

declare function local:test($in as xs:string) { "Tested" };
local:test( () )

This returns an empty sequence instead of the string "Tested" as if the function didn't actually run at all. Shouldn't the XQuery processor throw an error because the function signature specifies exactly one xs:string value? By contrast, if I add a question mark to make xs:string zero or one, the function returns "Tested" as expected:

declare function local:test($in as xs:string?) { "Tested" };
local:test( () )

Why isn't the function signature being enforced in the first code example?

1 Answers

Congrats, you've earned your "Bit By Function Mapping" badge! We all get bit once.

https://docs.marklogic.com/guide/xquery/enhanced#id_55459

The example there exactly covers your case. So now with the "BBFM" badge proudly adorning your chest, you can decide to use this feature to your advantage, or turn it off in your headers as below:

declare option xdmp:mapping "false";
Related