Project

Profile

Help

Bug #6232

closed

Error message: "An empty sequence is not allowed as the result of a call to map"

Added by Christian Grün about 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Low
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2023-10-25
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
12, trunk
Fix Committed on Branch:
12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

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?

Actions #1

Updated by Michael Kay about 1 year 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.

Actions #2

Updated by Michael Kay about 1 year 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".

Actions #3

Updated by Michael Kay about 1 year 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
Actions #4

Updated by O'Neil Delpratt about 1 year 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

Also available in: Atom PDF