ExpressionEvaluator icon indicating copy to clipboard operation
ExpressionEvaluator copied to clipboard

Linq Select throws exception (ValueTuple?) issue?

Open yggdrasil-tynor opened this issue 3 years ago • 3 comments

context.AddVariable("list1", new int[] { 1, 2, 3, 8 });
context.AddVariable("list2", new int[] { 4, 5, 6, 7 });
var test = context.Evaluate("list1.Cast<int>().Select<int, int>((item, i) => item - list1[i]).Cast<int>().Sum()");

throws:

ExpressionEvaluatorSyntaxErrorException : The call of the method "Sum" on type [System.Linq.Enumerable+SelectArrayIterator`2[System.Int32,System.Int32]] generate this error : Index was outside the bounds of the array.

With Zip or EquiZip it works fine:

list1.Cast<int>().EquiZip<int, int, int>(list2, (l1, l2) => l1 + l2).Cast<int>().Sum()"

What is wrong with select?

yggdrasil-tynor avatar Jun 04 '22 19:06 yggdrasil-tynor

EDIT: Seems like it's an issue when using ValueTuple.... Maybe this is not supported?

Here is a simple .NET fiddle example which shows the unexpected behaviour:

yggdrasil-tynor avatar Jun 07 '22 15:06 yggdrasil-tynor

This line breaks it: https://github.com/codingseb/ExpressionEvaluator/blob/365551a87cda0de63a18d603f257354460b1f8c3/CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs#L3425

For some reason the internalDelegate args contains 1 item, and should contain 2 in this case... https://github.com/codingseb/ExpressionEvaluator/blob/365551a87cda0de63a18d603f257354460b1f8c3/CodingSeb.ExpressionEvaluator/ExpressionEvaluator.cs#L3504-L3516

I guess this overload requires some special handling?

yggdrasil-tynor avatar Jun 07 '22 19:06 yggdrasil-tynor

FYI this is still an issue in 1.5.0-alpha releases

yggdrasil-tynor avatar Sep 30 '22 12:09 yggdrasil-tynor