Fixed issue with lambdas and System.Action #995
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue when compiling lambda expressions that need to be assigned to
System.Action<...>
. It is also necessary for the type inference feature #936.Current state
If user defines a lambda in a binding whose expected type is
Action<...>
, current implementation fails for all non-void
expressions. DotVVM throws compilation exception because it is unable to find an implicit conversion to convert fromFunc<...>
toAction<...>
. This is due to the fact that every expression that has non-void
return type gets compiled into aFunc<...>
.This is different from C#, where it is possible to have the following:
The expression above would be compiled into
Func<string, string>
in DotVVM because the assignment gets evaluated to a string.Proposed solution
It is necessary to propagate information about expected types to the
BindingExpressionBuilder
. This type information can be then used insideExpressionBuildingVisitor
to validate that the body is a valid statement and if so, make sure to generateAction<...>
if required.Breaking change
Interface
IBindingExpressionBuilder
was altered by adding an optional parameter to itsParse
method. Regardless, I do not think that this change could actually break someone.