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

Incomplete pattern matching in nested patterns #1412

Closed
tknawara opened this issue Feb 26, 2025 · 2 comments
Closed

Incomplete pattern matching in nested patterns #1412

tknawara opened this issue Feb 26, 2025 · 2 comments

Comments

@tknawara
Copy link

Hi team,

I'm new to F#, so apologies if this was raised before or if I'm doing something wrong in the pattern matching construction.

I have a simple AST for expressions. Nothing fancy, Binary/Unary expressions and each expression has an operator and operands.
Now, I'm attempting a pattern match, where I want to match on binary expressions where the operand is say Divide and remainder, I'm doing something like this

Image

Now op in this branch should only be Divide or Remainder, so further matching on it should be exhaustive, but for some reason I'm getting a warning about incomplete pattern.

@brianrourkeboll
Copy link

Hi, welcome to F#! This isn't the right place for this issue, though. (This repository is for suggesting new language features.)

For compiler bugs, you want https://github.com/dotnet/fsharp/issues.

For questions/discussion, you want Discord, Slack, or perhaps https://github.com/dotnet/fsharp/discussions.

I would need to see the definition of IR_Ast.BinaryOperator, but if it has more cases than just Divide and Remainder, then that explains what you are seeing. If you are expecting the outer match on (Divide | Remainder) to narrow the typing for the inner match, F# does not do that (unlike, say, TypeScript). Any given match on a union will need to handle all cases.

@T-Gro T-Gro closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2025
@tknawara
Copy link
Author

tknawara commented Feb 28, 2025

@brianrourkeboll Thanks for the links and apologies for opening the issue in the wrong repository. Your explanation make sense.

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

No branches or pull requests

3 participants