Sitelet https://github.com/coverlet-coverage/coverlet/issues/1490
Skip to content

Incorrect branch coverage with await using in generic methods #1490

Description

@arseni-mourzenko

Hi.

Using coverlet.msbuild.6.0.0, I noticed an issue with code coverage in generic methods that contain await using.

Here's a short example which reproduces the issue:

public static class A
{
    public static async Task<int> Demo()
    {
        await using var example = new DisposableExample<int>();
        var result = await Task.FromResult(42);
        return result;
    }

    public static async Task<T> Demo<T>()
    {
        await using var example = new DisposableExample<T>();
        var result = await Task.FromResult(default(T));
        return result;
    }
}

public class DisposableExample<T> : IAsyncDisposable
{
    public ValueTask DisposeAsync()
    {
        GC.SuppressFinalize(this);
        return ValueTask.CompletedTask;
    }
}

Given the following tests:

[Fact] public async Task One() => Assert.Equal(42, await A.Demo());
[Fact] public async Task Two() => Assert.Null(await A.Demo<string>());

the first, non-generic method Demo() will have a 100% branch coverage. The branch coverage of generic method, Demo<T>(), will show a missing branch on line return result; (1 visits, 3 of 4 branches are covered).

Unless I missed something, I would expect the branch coverage to be 100% in both cases.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existsstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions