You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
After ensuring that an instance of Nullable<T> is not null via .HasValue, coverlet still assumes the instance to be nullable and therefore the branch coverage indicates a missing test branch.
I don't think this is a bug in Coverlet. By not using the .Value property when reading the value of timeFromService, the C# generated during the lowering process adds an additional check to ensure that it has a value when it is used. As you have already checked that it has a value, the branch that exists where it does not have a value at this later point is never covered.
Using timeFromService.Value rather than timeFromService can be used as a workaround.
Am I missing something or what is the difference between your suggested workaround and what I already wrote in the question? 🤔
I don't think this is a bug in Coverlet.
One may have different opinions about that, but I do understand that as a maintainer, one tends to not see it as a bug, whereas as a user I perceive it as a problem. Maybe we can agree that the null check has already been done before, so calling up .Value is actually unnecessary and we call it an unpleasantness? Maybe a Roslyn check/fix provided by coverlet would be an option here to check for such patterns?
Describe the bug
After ensuring that an instance of
Nullable<T>
is notnull
via.HasValue
, coverlet still assumes the instance to be nullable and therefore the branch coverage indicates a missing test branch.To Reproduce
Here you find a complete repro case.
Expected behavior
Branch coverage is 100% for the line
var isInPast = timeFromService < TimeOnly.FromDateTime(DateTime.UtcNow);
.Actual behavior
Coverlet complains that only 1 out of 2 branches is tested as it assumes that
timeFromService
can still benull
:Configuration (please complete the following information):
Please provide more information on your .NET configuration:
coverlet.msbuild v6.0.2
Additional context
Using
timeFromService.Value
rather thantimeFromService
can be used as a workaround.The text was updated successfully, but these errors were encountered: