Global functions chained with linq causes parse exceptions from 2.5.0
See original GitHub issueSo in these days, I’ve updated from 2.3.1 to 2.6.0 and some specific test cases in my own test suite started failing.
Upon bisecting it seems 2.5.0 is causing those test cases to fail so I made a test unit and tried it on both 2.4.1 and 2.5.0 and I can reliably see it failing due to a parse exception in 2.5.0 while it worked fine in 2.4.1.
From a c# standpoint, the syntax is correct, though.
This is the test case that can show the wrong behaviour and it seems likely related to #144
[Test]
public void Func_Global_Invocation()
{
Func<object[], double, double, object[]> subArray = (entries, skipFirst, skipLast) => entries.Take(entries.Length - (int)skipLast).Skip((int)skipFirst).ToArray();
var target = new Interpreter();
target.SetVariable("arr1", new object[] { 1d, 2d, 3d });
target.SetFunction("SubArray", subArray);
Assert.AreEqual(2, target.Eval("SubArray(arr1, 1, 1).First()"));
}
On 2.4.1 this works fine the eval returns 2 and the test succeeds. in 2.5.0 upward this will return a parse exception (for note this is a checkout of the current master to have a recollection of lines references)
Message:
DynamicExpresso.Exceptions.ParseException : Syntax error (at index 20).
Stack Trace:
Parser.ValidateToken(TokenId t, String errorMessage) line 2474
Parser.Parse() line 68
Parser.Parse(ParserArguments arguments) line 24
Interpreter.ParseAsLambda(String expressionText, Type expressionType, Parameter[] parameters) line 443
Interpreter.Parse(String expressionText, Type expressionType, Parameter[] parameters) line 343
Interpreter.Eval(String expressionText, Type expressionType, Parameter[] parameters) line 420
Interpreter.Eval(String expressionText, Parameter[] parameters) line 397
OtherTests.Func_Global_Invocation() line 104
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Throw error when parsing the method with default ...
Throw error when parsing the method with default parameters in ... Global functions chained with linq causes parse exceptions from 2.5.0 # ...
Read more >Int.Parse in Linq Expression
Entity Framework will generate proper CAST functions in SQL. EF 6: Short answer: youEntity.Where(c=>SqlFunctions.StringConvert((decimal?)c.
Read more >ethereumjs-vm | Yarn - Package Manager
Implements Ethereum's VM in Javascript. Fork Support. The VM currently supports the following hardfork rules: Byzantium; Constantinople; Petersburg (default) ...
Read more >Packages - opam
Name Latest version Description
0install 2.18 Decentralised installation system
0install‑gtk 2.18 Decentralised installation system ‑ GTK UI
0install‑solver 2.18 Package dependency solver
Read more >Unity 2023.1.0
Asset Pipeline: Fixed an issue with async unloading which could cause errors and crashes in AssetDatabase.CreateAsset(). (UUM-20313).
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The fix was an easy one: the parsing was stopped after a call to the registered function (i.e. the
.First()
part was ignored). That triggered aParserException
, because the parser expects the expression to have reached the end.Version 2.6.1 released with the fix! Thank you @metoule for the fix and @weltall for bug report!