Open line-o opened 3 years ago
And as the below test indicates @adamretter was right that the type-checks are not enforced at compile time
declare
%test:assertXPath("/error")
function t:compile-my-hof() {
util:compile-query(``[
declare function local:my-apply($item, $f as function(*)) {
$f($item)
};
local:my-apply(1, function ($item as xs:string) { $item })
]``, "xmldb:exist://")
};
Describe the bug
When a function parameter is typed, the type must be enforced. That is why the example above will throw
err:XPTY0004
"xs:integer(1) is not a sub-type of xs:string".The parameter types of arguments of Higher-order-functions however are not enforced.
returns xs:integer(1)
does throw on the other hand. So return types are enforced.
This seems to be a known issue, see https://github.com/eXist-db/exist/issues/3382#issuecomment-617155618 A clear and concise description of what the bug is.
Interestingly, user defined higher order functions are not affected. That is a clear hint that the underlying implementation of higher order functions in Java needs to be changed.
Expected behavior
The parameter types of arguments of Higher-order-functions however are enforced and err:XPTY0004 is raised whenever a value of a type is passed to a function parameter that does not match the expected type.
To Reproduce
Context (please always complete the following information):
Additional context
conf.xml
? none