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

Nested Calls with Lambda Parameters Throwing NotSupportedExpressionException #443

Closed
MattEdwardsWaggleBee opened this issue Dec 16, 2024 · 3 comments
Assignees
Labels
Milestone

Comments

@MattEdwardsWaggleBee
Copy link
Contributor

This might be related to #295, but if not, I figured I would open an issue and give a test case.
I'll add a PR with this falling test for you too look at.

public class TestClass
{
    public static int ExecuteDelegate( Func<int> action ) => action();
}

var executeDelegate = typeof( TestClass ).GetMethod( nameof( TestClass.ExecuteDelegate ) );
var local = Variable( typeof( int ), "local" );

var innerLambda = 
    Lambda<Func<int>>(
        Block(
            [local],
            Assign( local, Constant( 42 ) ),

            // Invoke works
            //Invoke( Lambda<Func<int>>( local ) )

            // Call does not work
            Call( executeDelegate, Lambda<Func<int>>( local ) )
        )
    );

var body = Lambda<Func<int>>( 
    Call( executeDelegate, innerLambda )
);

var compiledLambda = body.Compile( compiler );

var result = compiledLambda();

Assert.AreEqual( 42, result );
MattEdwardsWaggleBee added a commit to Stillpoint-Software/FastExpressionCompiler that referenced this issue Dec 16, 2024
MattEdwardsWaggleBee added a commit to Stillpoint-Software/hyperbee.expressions that referenced this issue Dec 16, 2024
dadhi added a commit that referenced this issue Dec 17, 2024
@dadhi
Copy link
Owner

dadhi commented Dec 17, 2024

@MattEdwardsWaggleBee I wanted to highlight (in case you don't know that already) that in Invoke(Lambda(...)) the lambda is inlined. This is the default behavior of the System Compile, and so is the same for the FEC. That's why Invoke(Lambda(...)) and Call(method, Lambda(...)) will produce drastically different IL, and face the different issues.

In FEC you may avoid the default inlining with CompilerFlags.NoInvocationLambdaInlining, e.g. lambda.CompileFast(false, CompilerFlags.NoInvocationLambdaInlining).

dadhi added a commit that referenced this issue Dec 18, 2024
@dadhi dadhi closed this as completed in 0534d97 Dec 18, 2024
@dadhi
Copy link
Owner

dadhi commented Dec 18, 2024

@MattEdwardsWaggleBee It's fixed.

@MattEdwardsWaggleBee
Copy link
Contributor Author

Nice! Thank you so much.

@dadhi dadhi self-assigned this Dec 18, 2024
@dadhi dadhi added the bug label Dec 18, 2024
@dadhi dadhi added this to the v5.0.1 milestone Dec 18, 2024
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