ExpressionTreeVisualizer icon indicating copy to clipboard operation
ExpressionTreeVisualizer copied to clipboard

Distinguish parameters from different lambdas in the end-nodes pane

Open zspitz opened this issue 7 years ago • 1 comments

If there are nested lambdas, currently all their parameters are in a single list.

image

zspitz avatar Jan 27 '19 01:01 zspitz

The C# compiler allows lambda syntax to have the same name for the inner and outer lambda, for both expressions and delegates:

Expression<Func<int, Expression<Func<int, int>>>> expr = i => i => i*i;
Func<int, Func<int, int>> fn = i => i => i*i;

However, the i is understood as referring to the parameter of the inner lambda:

Console.WriteLine(fn(5)(6));
// prints: 36, not 30 or 25

The VB compiler doesn't allow it:

Dim expr As Expression(Of Func(Of Integer, Expression(Of Func(Of Integer, Integer)))) 
expr = Function(i) Function(i) i*i
Dim fn As Func(Of Integer, Func(Of Integer, Integer)) = Function(i) Function(i) i*i

doesn't compile with:

Lambda parameter 'i' hides a variable in an enclosing block, a previously defined range variable, or an implicitly declared variable in a query expression.

Since we now auto-generate names, we could perhaps add a Declared in column to the parameters data grid.

This would require exposing a Dictionary<object, string> of names in ExpressionTreeToString.

zspitz avatar Nov 06 '20 08:11 zspitz