basex icon indicating copy to clipboard operation
basex copied to clipboard

Function coercion: Methods

Open ChristianGruen opened this issue 8 months ago • 1 comments

The following code raises .: Context value is undefined.:

declare record basex:r(
  f as fn() as item()
); 
basex:r(%method fn() { . })?f()

It works if the function signature is simplified:

declare record basex:r(
  f as fn(*)
); 
basex:r(%method fn() { . })?f()

ChristianGruen avatar Apr 18 '25 06:04 ChristianGruen

An interesting test case, indeed! This is caused by function coercion, which effecively wraps the method invocation in a new function item. This is then is subject to receiving the method context item, but does not propagate it when calling the original function. I tend to believe that this the correct behavior in accordance to the current state of the spec, because I am not aware of any regulation for this special case, nor of any propagation of context items as would be needed here. Yet I find it counter-intuitive.

I have a possible fix in branch coerced-methods, but it introduces context item propagation for coerced function items, which to the best of my knowledge is not covered by the spec. I have thus raised qt4cg/qtspecs#1938 in order to ask for clarification.

GuntherRademacher avatar Apr 18 '25 20:04 GuntherRademacher

The %method annotation may be dropped (https://github.com/qt4cg/qtspecs/pull/2147).

ChristianGruen avatar Aug 11 '25 07:08 ChristianGruen