-
Notifications
You must be signed in to change notification settings - Fork 818
open type
does not bring enum cases into scope in patterns
#17630
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
Comments
|
Weirdly enough the Technically a breaking change so we should at least add a warning together with a fix. edit: actually should add a warning regardless of the fix |
Enum types are considered to have |
They are? I mean, I guess they were before For what it's worth, |
Right. But enums don't have that attribute.
It was updated to apply to unions as well (except of course those with
@abelbraaksma did question the application to enums here: fsharp/fslang-design#352 (comment). But it doesn't look like anything was recorded in the RFC itself about enums specifically. |
They do, as per 8.9 in the language spec:
|
Oh, interesting. § 8.9
The compiler doesn't actually emit the Does that really mean "Each enum type declaration [behaves as though it were] implicitly annotated with the The funny thing is that I would seldom match on F#-defined enums; I would normally just use a union instead. It would normally be a C#-defined enum that I'd want to pattern-match on, anyway, and potentially open using |
Yeah, I think the wording is not accurate. I think it's just implicit behaviour for enums rather than implicitly emitting it |
I meant to open this years ago, but I guess I never did.
Repro steps
Expected behavior
Enum cases brought into scope with an
open type
declaration (or anAutoOpen
on the enum definition) should be in scope in pattern matching as unqualified literals, just like union cases or active pattern cases.E.g., if you change the enum in the example above to a union type,
A
is brought into scope in something like this:Actual behavior
Enum cases brought into scope with an
open type
declaration (or anAutoOpen
on the enum definition) are not in scope in pattern matching as unqualified literals.Known workarounds
N/A.
Related information
.NET 8, 9.
Note
I guess this probably can't be fixed, since there may now be existing code that relies on the current behavior — although it is quite possible that some of that existing code is wrong, because it was written with the understanding that
open type
would behave the same for enums as it does for unions, etc.The text was updated successfully, but these errors were encountered: