Project

Profile

Help

Bug #5205

Map → function argument

Added by Christian Grün 14 days ago. Updated 14 days ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2022-01-14
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
10
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Triggered by a Slack comment (https://app.slack.com/client/T011VK9115Z/C011NLXE4DU/thread/C011NLXE4DU-1641484160.002700):

The following expression returns 1:

declare function local:f($f as function(item()?) as item()) {
  1
};
local:f(map { })

I would have expected XPTY0004, as a map is no instance of function(item()?) as item(), and as the following expression yields an error:

map { } treat as
  function(item()?) as item()

History

#1 Updated by Michael Kay 14 days ago

I guess (without examining it in detail) that function inlining is probably removing the type check on the unused argument?

That's permitted under the infamous "errors and optimization" rules. I don't like relying on those rules, but sometimes we have to.

#2 Updated by Christian Grün 14 days ago

I’ve tried a recursive variant of the function, it seems to work as well:

declare function local:f(
  $f as function(item()?) as item(),
  $i as xs:integer
) {
  if ($i > 0) then local:f($f, $i - 1) else 1
};
local:f(map { }, 1000)

Please register to edit this issue

Also available in: Atom PDF