ExhaustiveMatching icon indicating copy to clipboard operation
ExhaustiveMatching copied to clipboard

Support for switch patterns

Open thinker227 opened this issue 1 year ago • 1 comments

Background: I am writing a compiler in C#, and as such this project seemed like a literal gold mine since I'm using record inheritance for all my AST and other tree nodes. However, I was somewhat disappointed to see that the analyzer only seems to support type patterns, eg. case T x:/T x => and not complex patterns like deconstruction or or patterns.

This perhaps seems like an obvious suggestion, but it would be immensely useful to emulate the exhaustiveness checking which Roslyn performs but with the added constraint that the full set of possible types is known. I doubt the internal mechanisms Roslyn uses to perform exhaustiveness analysis is publicly exposed to the API, so I'm unsure of whether it'd be possible to leech off of the work Roslyn already does or whether the analyzer would have to implement almost the entirety of the functionality by itself. Either way, this would be immensely useful.

thinker227 avatar Sep 23 '24 15:09 thinker227

Support for or patterns and matching patterns without a variable (i.e., case T:/T =>) is planned. I can imagine how to do exhaustiveness checking on simple tuples of types. Are there other patterns you would want to see supported?

I'm not familiar with the Roslyn exhaustiveness checking. Do you have some links that I can learn more from?

WalkerCodeRanger avatar Sep 23 '24 18:09 WalkerCodeRanger