Bug #6232
closed![Author: Christian Grün](https://www.gravatar.com/avatar/f478199302482ac716114176a7149f11?rating=PG&size=50&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
![Assignee: Michael Kay](https://www.gravatar.com/avatar/db6526d63053f09b62e52c2da8b2230a?rating=PG&size=22&default=https%3A%2F%2Fassets.plan.io%2Fimages%2Fdefault_avatar.png)
Error message: "An empty sequence is not allowed as the result of a call to map"
100%
Description
When running…
filter(1, map { })
…I get the misleading error message “An empty sequence is not allowed as the result of a call to map”. I would claim it’s even wrong, because map:get(map{}, 1)
or map {}?1
both return an empty sequence.
I assume the hidden message here is that the predicate function of fn:filter
must return a boolean value?
Updated by Michael Kay 10 months ago
Indeed, the error is that the function supplied as the second argument of the call to filter must not return an empty sequence.
A map of course is a function, and when it's supplied to fn:filter, function coercion happens, so the call on the map function gets wrapped in an anonymous function that checks the result. On this occasion the check fails, and the challenge is how to interpret this in terms that the user might understand.
Updated by Michael Kay 10 months ago
The relevant code is at CoercedFunction#194
Supplier<RoleDiagnostic> role =
() -> new RoleDiagnostic(RoleDiagnostic.FUNCTION_RESULT, targetFunction.getDescription(), 0);
Instead of using targetFunction.getDescription()
we should construct a more detailed description.
A bit of tweaking gives the message
XPTY0004 An empty sequence is not allowed as the result of a call to map{} (used where
the required type is (function(item()) as xs:boolean))
The changes made are:
(1) CoercedFunction.getDescription() changed to return
return targetFunction.getDescription() + " (used where the required type is " + requiredType + ")";
(2) the code shown above changed to return getDescription()
rather than targetFunction.getDescription()
(3) MapItem.getDescription chaged to return toShortString()
rather than "map".
Updated by Michael Kay 10 months ago
- Category set to Diagnostics
- Status changed from New to Resolved
- Assignee set to Michael Kay
- Applies to branch 12, trunk added
- Fix Committed on Branch 12, trunk added
- Platforms .NET, Java added
Updated by O'Neil Delpratt 9 months ago
- Status changed from Resolved to Closed
- % Done changed from 0 to 100
- Fixed in Maintenance Release 12.4 added
Bug fix applied in the Saxon 12.4 maintenance release
Please register to edit this issue