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

Directly passing a method result to another method by ref, fails with InvalidProgramException #426

Closed
bfarmer67 opened this issue Oct 21, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@bfarmer67
Copy link

The following throws an InvalidProgramException

public static class Numbers
{
    public static int GetInt() => 40;
    public static int AddTwo(ref int value) => value + 2;
}

public class Program
{
    public static void Main()
    {
        var getIntMethod = typeof(Numbers).GetMethod(nameof(Numbers.GetInt));
        var addTwoMethod = typeof(Numbers).GetMethod(nameof(Numbers.AddTwo));
		
        var getIntCall = Expression.Call(getIntMethod);

        var expr = Expression.Call(addTwoMethod, getIntCall);
        
        var lambda = Expression.Lambda<Func<int>>(expr).CompileFast();
        var result = lambda();  
    }
}

Expression.Compile is fine with it, but FEC doesn't like it.

The issue is easy to work around by storing the result of the first method in a
variable and passing the variable to the second method, but I wanted to pass the
error along.

Here is a small dotnetfiddle https://dotnetfiddle.net/PWeV9P that demonstrates the issue.

Thank you for a really nice library.

@dadhi
Copy link
Owner

dadhi commented Oct 21, 2024

Thanks for the repro. I will look.

@dadhi dadhi self-assigned this Oct 22, 2024
@dadhi dadhi added this to the v4.3.0 milestone Oct 22, 2024
@dadhi dadhi added the bug label Oct 22, 2024
dadhi added a commit that referenced this issue Oct 22, 2024

Verified

This commit was signed with the committer’s verified signature.
Byron Sebastian Thiel
@dadhi dadhi closed this as completed in b1c35e2 Oct 22, 2024
@dadhi dadhi modified the milestones: v4.3.0, v5.0.0 Oct 24, 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