The problem is not calling Matches . It is in a CallTo call that expects an Expression<Action> .
Apparently, Expression not only cannot be a lambda expression with the operator body, but also cannot contain a lambda expression with the operator body.
(I'm not sure if your "put lambda in local variable" solution will work, or if it just fools the compiler and won't work at runtime.)
In this test, I compiled:
static void Overloaded(Action a, string param) { } static void Overloaded(Expression<Action> e) { } static void CallToAction(Action a) { } static void CallToExprAc(Expression<Action> a) { } static void Main(string[] args) {
Does your "placed in the lambda kernel in local" work, as implemented by FakeItEasy. I suspect that it will work here, but something similar, for example, LINQ-to-SQL will not - it will simply fail at runtime, and not at compile time.
I am not sure if this is a compiler error, specification error or desired behavior. In section 6.5 of the C # specification, we have
Some lambda expressions cannot be converted to expression tree types. Although the conversion exists, it does not run at compile time. This is the case if the lambda expression is:
• Has a block body
• Contains simple or complex assignment operators
• Contains a dynamically linked expression
• is async
which does not say "contains a lambda expression that cannot be converted to an expression tree type."
Rawling
source share