Function coercion: Methods
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()
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.
The %method annotation may be dropped (https://github.com/qt4cg/qtspecs/pull/2147).