Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda parsing can fail for generics and multi-parameter indexers #294

Open
Pentiva opened this issue Jul 27, 2023 · 1 comment
Open

Lambda parsing can fail for generics and multi-parameter indexers #294

Pentiva opened this issue Jul 27, 2023 · 1 comment
Labels

Comments

@Pentiva
Copy link
Contributor

Pentiva commented Jul 27, 2023

Similar to #259, square and angle brackets are not currently used to decide when the body of a lambda stops.

var intList = new List<int> { 1, 2 };
target.SetVariable("intList", intList);
var results = target.Eval<IEnumerable<Dictionary<string, int>>>("intList.Select(a => new Dictionary<string, int>())");

DynamicExpresso.Exceptions.ParseException : '.' or '(' expected (at index 46).

var intMultiArray = new int[2, 3];
target.SetVariable("intMultiArray", intMultiArray);
var results = target.Eval<int[,]>("intMultiArray.MultiArrayTest(t => t[0, 0])")

public static int[,] MultiArrayTest(this int[,] source, Func<int[,], int> func) {
    func(source);
    return source;
}

DynamicExpresso.Exceptions.ParseException : ')' or ',' expected (at index 40).

This should be an easy fix for the multi-dimensional arrays (basically another extension of #260 ), but I'm struggling to figure out how it would be done for generics, as the left angle bracket could easily be used as less than instead meaning there wouldn't be a closing one.

.Where(a => a < variable)
.Select(a => new A < TypeName >()) // I wouldn't expect anyone to do this, but I hope it helps illustrate my point.

I discovered this on purpose, while trying to explicitly find bugs with the lambda parsing. As such it is not urgent, and you can also work around it by putting the whole expression after the Lambda Arrow in parentheses.

@metoule metoule added the bug label Jul 27, 2023
@metoule
Copy link
Contributor

metoule commented Jul 27, 2023

Thanks for the report! It's indeed similar to #259. Good catch for the angle brackets.. I'll add this to my TODO list :)

metoule added a commit to metoule/DynamicExpresso that referenced this issue Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants