-
Notifications
You must be signed in to change notification settings - Fork 239
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
Match semantics re. pattern order #1186
Comments
Was having a look at the c/c++ switch statement which does allow the default to be anywhere. |
we can't really change the semantics of value matches unless we explicitly check for no overlaps, consider this:
this is valid, none of the match arms are the same constant (though it might make sense to disallow), but there's no real way to do a full overlap check on these. |
That seems okay, it can be that the order matters except for the else case that only matches if none of the other cases do. |
else has to always be treated as the last branch, wether enforced to be written so or not. nothing can come after it, so not ordering it last does not make any sense |
Following from #1183 (comment)
Currently match patterns do not care about the order, as the patterns cannot be overlapping (aside from
else
, which is currently defined as "all cases not mentioned in the match"), so pattern order is ignored in enum matches.Conversely, pattern order is significant in value matches, where we go down the list of values, checking for equality.
The first one allows matches like
to yield y for A, which is dissimilar to other languages.
The text was updated successfully, but these errors were encountered: