ExhaustiveMatching
ExhaustiveMatching copied to clipboard
Add support for exhaustive matching on records
The analyzer does not handle record classes. for example :
[Closed(typeof(UserNotFound))]
public abstract record Response
{
public record UserNotFound : Response;
public record Success : Response;
}
class Controller
{
public int Get(Response response)
{
return response switch
{
Response.UserNotFound _ => -1,
_ => throw ExhaustiveMatch.Failed(response)
};
}
}
The analyzer doesn't detect that the "Success" class is needed to be added to the Closed attribute. The analyzer doesn't detect that the "Success" clause needs to be handled in the Get() method
Thanks for this library, really appreciate the effort !
If you don't provide all branchs in the ClosedAttribute, how should the analyzer know that Success is the only other subclass of the record. See my issue #44 on how the analyzer can detect the situation even for records without the attribute if the constructor is private. I have also provided a pull request and will try to use the modified version of the analyzer already in some of our projects.