var code =
"""
using Rocks;
using System.Diagnostics.CodeAnalysis;
[assembly: RockMake<INotNull>]
public interface INotNull
{
[MemberNotNullWhen(false, nameof(Error))]
bool IsSuccess { get; }
string Error { get; }
}
""";
Expected behavior
The mock is made.
Actual behavior
An error occurs:
error CS8775: Member 'Error' must have a non-null value when exiting with 'false'.
Additional context
This occurs because the attribute says that another member should not return null when the marked member returns false. However, because of the way a make is made, default! is always returned, and this messes with the expectation of the attribute.
This is just a diagnostic warning, so the easiest thing to do would be to wrap every make with a #pragma disable/restore pair with CS8775, so it'll never show up.
To Reproduce
Expected behavior The mock is made.
Actual behavior An error occurs:
Additional context This occurs because the attribute says that another member should not return null when the marked member returns
false
. However, because of the way a make is made,default!
is always returned, and this messes with the expectation of the attribute.This is just a diagnostic warning, so the easiest thing to do would be to wrap every make with a
#pragma disable/restore
pair withCS8775
, so it'll never show up.This was found on
Refit.IApiResponse