Hi Christian,
First of all best wishes for the next year, may it be an interesting one. Having said that, I encountered this 'interesting' issue. I vagely think to remember something lijke this is adressed before but I'm not sure.
I hereby send you a self containing application: 'nastyIssueTest2.xq', that triggers the error. I've made the code as small as possible, but since the occurrence of the error very much depends on the context, some context code is necessary. ( I don't think the context code triggers the error but more suppresses it, adding a trace somewhere could make the error just disappear)
I suspect that the first function in the app: 'local:for-each-component#4', is the culprit, but I can't really tell. I've also added a workaround in the app: 'local:for-each-component2#2', which seems a stable solution.
The issue looks like something like 'https://github.com/BaseXdb/basex/issues/909' of march 2014.
Btw. I used version 11.3. Updating to version 11.6 triggers a different error when code of function: 'local:folderDialog.new#2', is activated. When deactivated it triggers the above mentioned error.
I hope this helps.
mvgr.
Rob Stapper