This is an automated email from the ASF dual-hosted git repository. henrib pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push: new 0e18632 JEXL-358: correct closure evaluator; - add test; 0e18632 is described below commit 0e186325b2ee03dcc3e5d96aafff1f70b276ccd6 Author: henrib <hen...@apache.org> AuthorDate: Wed Jan 26 18:59:35 2022 +0100 JEXL-358: correct closure evaluator; - add test; --- .../apache/commons/jexl3/internal/Interpreter.java | 9 +++++++- .../java/org/apache/commons/jexl3/LambdaTest.java | 24 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java index 9d262db..fbd47a4 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java @@ -1005,9 +1005,16 @@ public class Interpreter extends InterpreterBase { */ protected Object runClosure(final Closure closure, final Object data) { final ASTJexlScript script = closure.getScript(); + // if empty script, nothing to evaluate + final int numChildren = script.jjtGetNumChildren(); + if (numChildren == 0) { + return null; + } block = new LexicalFrame(frame, block).defineArgs(); try { - final JexlNode body = script.jjtGetChild(script.jjtGetNumChildren() - 1); + final JexlNode body = script instanceof ASTJexlLambda + ? script.jjtGetChild(numChildren - 1) + : script; return interpret(body); } finally { block = block.pop(); diff --git a/src/test/java/org/apache/commons/jexl3/LambdaTest.java b/src/test/java/org/apache/commons/jexl3/LambdaTest.java index b696b31..328e89b 100644 --- a/src/test/java/org/apache/commons/jexl3/LambdaTest.java +++ b/src/test/java/org/apache/commons/jexl3/LambdaTest.java @@ -298,6 +298,30 @@ public class LambdaTest extends JexlTestCase { } @Test + public void testCurry4() throws Exception { + final JexlEngine jexl = createEngine(); + JexlScript script; + Object result; + + final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }"); + script = base.curry(5); + result = script.execute(null, 15, 22); + Assert.assertEquals(42, result); + } + + @Test + public void testCurry5() throws Exception { + final JexlEngine jexl = createEngine(); + JexlScript script; + Object result; + + final JexlScript base = jexl.createScript("var t = x + y + z; return t", "x", "y", "z"); + script = base.curry(5); + result = script.execute(null, 15, 22); + Assert.assertEquals(42, result); + } + + @Test public void test270() throws Exception { final JexlEngine jexl = createEngine(); final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");