Skip to content
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

Add support for exhaustive matching on records #41

Open
abiratur opened this issue Mar 27, 2022 · 1 comment
Open

Add support for exhaustive matching on records #41

abiratur opened this issue Mar 27, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@abiratur
Copy link

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 !

@WalkerCodeRanger WalkerCodeRanger added the enhancement New feature or request label Mar 27, 2022
@csharper2010
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants