Skip to content

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

Open
@Pentiva

Description

@Pentiva

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions