diff --git a/exist-core/pom.xml b/exist-core/pom.xml
index 5a8a49665f..72ce32c864 100644
--- a/exist-core/pom.xml
+++ b/exist-core/pom.xml
@@ -1215,6 +1215,7 @@
src/test/java/org/exist/xquery/ForwardReferenceTest.java
src/main/java/org/exist/xquery/Function.java
src/main/java/org/exist/xquery/FunctionFactory.java
+ src/main/java/org/exist/xquery/InlineFunction.java
src/main/java/org/exist/xquery/Intersect.java
src/test/java/org/exist/xquery/LexerTest.java
src/main/java/org/exist/xquery/LocationStep.java
@@ -2014,6 +2015,7 @@
src/test/resources-filtered/org/exist/xquery/import-from-pkg-test.conf.xml
src/test/java/org/exist/xquery/ImportFromPkgTest.java
src/test/java/org/exist/xquery/ImportModuleTest.java
+ src/main/java/org/exist/xquery/InlineFunction.java
src/main/java/org/exist/xquery/Intersect.java
src/main/java/org/exist/xquery/JavaBinding.java
src/test/resources-filtered/org/exist/xquery/JavaBindingTest.conf.xml
diff --git a/exist-core/src/main/java/org/exist/xquery/InlineFunction.java b/exist-core/src/main/java/org/exist/xquery/InlineFunction.java
index 415b0f58b4..849865e1db 100644
--- a/exist-core/src/main/java/org/exist/xquery/InlineFunction.java
+++ b/exist-core/src/main/java/org/exist/xquery/InlineFunction.java
@@ -1,4 +1,28 @@
/*
+ * Elemental
+ * Copyright (C) 2024, Evolved Binary Ltd
+ *
+ * admin@evolvedbinary.com
+ * https://www.evolvedbinary.com | https://www.elemental.xyz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; version 2.1.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * NOTE: Parts of this file contain code from 'The eXist-db Authors'.
+ * The original license header is included below.
+ *
+ * =====================================================================
+ *
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
@@ -21,7 +45,6 @@
*/
package org.exist.xquery;
-import java.util.ArrayDeque;
import java.util.List;
import org.exist.dom.QName;
@@ -33,69 +56,67 @@
/**
* An XQuery 3.0 inline function expression.
- *
- * @author wolf
*
+ * @author wolf
+ * @author Adam Retter
*/
public class InlineFunction extends AbstractExpression {
- public final static QName INLINE_FUNCTION_QNAME = QName.EMPTY_QNAME;
-
- private UserDefinedFunction function;
- private ArrayDeque calls = new ArrayDeque<>();
-
- private AnalyzeContextInfo cachedContextInfo;
+ public static final QName INLINE_FUNCTION_QNAME = QName.EMPTY_QNAME;
- public InlineFunction(XQueryContext context, UserDefinedFunction function) {
- super(context);
- this.function = function;
- }
+ private final UserDefinedFunction function;
- @Override
- public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
+ private AnalyzeContextInfo cachedContextInfo;
+
+ public InlineFunction(final XQueryContext context, final UserDefinedFunction function) {
+ super(context);
+ this.function = function;
+ }
+ @Override
+ public void analyze(final AnalyzeContextInfo contextInfo) throws XPathException {
cachedContextInfo = new AnalyzeContextInfo(contextInfo);
cachedContextInfo.addFlag(SINGLE_STEP_EXECUTION);
cachedContextInfo.setParent(this);
- }
-
- @Override
- public void dump(ExpressionDumper dumper) {
- dumper.display("function");
- function.dump(dumper);
- }
-
- /**
- * Wraps a function call around the function and returns a
- * reference to it. Make sure local variables in the context
- * are visible.
- */
- public Sequence eval(Sequence contextSequence, Item contextItem)
- throws XPathException {
- // local variable context is known within inline function
- final List closureVars = context.getLocalStack();
-
- final FunctionCall call = new FunctionCall(context, function);
- call.getFunction().setClosureVariables(closureVars);
- call.setLocation(function.getLine(), function.getColumn());
- call.analyze(new AnalyzeContextInfo(cachedContextInfo));
-
- // push the created function call to the stack so we can clear
- // it after execution
- calls.push(call);
-
- return new FunctionReference(this, call);
- }
-
- @Override
- public int returnsType() {
- return Type.FUNCTION;
- }
+ }
+
+ @Override
+ public void dump(final ExpressionDumper dumper) {
+ dumper.display("function");
+ function.dump(dumper);
+ }
+
+ /**
+ * Wraps a function call around the function and returns a
+ * reference to it. Make sure local variables in the context
+ * are visible.
+ */
+ @Override
+ public Sequence eval(final Sequence contextSequence, final Item contextItem) throws XPathException {
+ // local variable context is known within inline function
+ final List closureVars = context.getLocalStack();
+
+ final FunctionCall call = new FunctionCall(context, function);
+ call.getFunction().setClosureVariables(closureVars);
+ call.setLocation(function.getLine(), function.getColumn());
+ call.analyze(new AnalyzeContextInfo(cachedContextInfo));
+
+ return new FunctionReference(this, call);
+ }
@Override
- public void resetState(boolean postOptimization) {
+ public int returnsType() {
+ return Type.FUNCTION;
+ }
+
+ @Override
+ public void resetState(final boolean postOptimization) {
super.resetState(postOptimization);
- calls.clear();
+
+ if (!postOptimization) {
+ function.setClosureVariables(null);
+ }
+
function.resetState(postOptimization);
}
}
\ No newline at end of file