-
Notifications
You must be signed in to change notification settings - Fork 388
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
Wrong coverage for "await foreach" when method is generic #1210
Comments
Thanks for reporting this. |
@MarcoRossignoli this is still the case with 3.1.1 |
We need a repro to find out why/when that branch is emitted by the compiler, to repro you should create the same method using mocked object, but the "shape" needs to be "identical" to mimic the same context for the compiler. |
Any hints/idea what could cause this i.e. Why my repro doesnt work? |
The code in the repro and the code that is failing are a lot different from compiler perspective, state machine are built in a different way because different object structure are involved(different nesting, visibility, different relationship between objects...different optimization)...you should create the same classes, mock those and retry. Try to compare those with ILSpy and you'll see that the emitted IL is different. |
Seems like it doesn't work if the method takes a type-parameter. public class AwaitForeachReproductionFixture2
{
[Fact]
public async Task Execute_ShouldWork()
{
// Arrange
var sut = new AwaitForeachReproduction2();
// Act
await sut.Execute<object>(RangeAsync(1, 3));
}
static async IAsyncEnumerable<int> RangeAsync(int start, int count)
{
for (int i = 0; i < count; i++)
{
await Task.Delay(i);
yield return start + i;
}
}
} public class AwaitForeachReproduction2
{
public virtual async Task Execute<T>(IAsyncEnumerable<int> messages)
{
await foreach (int obj in messages)
{
await Task.Delay(1);
}
}
} |
See https://github.com/meggima/coverlet-reproductions AwaitForeachReproduction2.cs & AwaitForeachReproductionFixture2.cs |
I started working on this issue. |
I'm using coverlet.msbuild v3.1.0 (and tried also with the current nightly build) and there is an uncovered statement reported.
I tried to reproduce it but I didn't managed to get an reproduction.
Any ideas what the problem could be and how I can provide an reproduction?
The text was updated successfully, but these errors were encountered: