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

Analyse dependencies of async lambdas #230

Open
penenkel opened this issue Mar 14, 2024 · 0 comments
Open

Analyse dependencies of async lambdas #230

penenkel opened this issue Mar 14, 2024 · 0 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@penenkel
Copy link

Summary

It seems as if the dependencies of async lambda functions are not enumerated correctly.

Scenario

Consider a class C2 that calls a method on class C1 and passes a lambda function which calls a method on class C3.

    class C1 { 
        public void Register(Func<Task> action) { } 
    }
    class C2 { 
        void Foo(C1 b1) { 
            b1.Register(() => { C3.Bar1(); return Task.CompletedTask; });
            b1.Register(async () => { C3.Bar2(); await Task.CompletedTask; });
        } 
    }
    class C3 { 
        public static void Bar1() { }
        public static void Bar2() { }
    }

I encountered this in the context of AspNetCore MinimalApi endpoint registrations thus the convoluted example. It is probable that the problem could be reproduced with a simpler example.

Expectation

Then I would expect the following test to successfully verify that both methods C3.Bar1 and C3.Bar2 are called from within C2.

    [Fact]
    public void ShouldDetectCallsInLambdas()
    {
        var architecture = new ArchLoader().LoadAssemblies([GetType().Assembly]).Build();

        var rule1 = Types().That().Are(typeof(C2)).Should().CallAny("C3::Bar1", true);
        var rule2 = Types().That().Are(typeof(C2)).Should().CallAny("C3::Bar2", true);
        var rule = rule1.And(rule2);

        rule.Check(architecture);
    }

Actual result

But it fails to do so for Bar2 which is called from an async lambda. This probably due to the compiler generated state-machine, similar to #138.

@alexanderlinne alexanderlinne added the kind/bug Categorizes issue or PR as related to a bug. label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

No branches or pull requests

2 participants