-
Notifications
You must be signed in to change notification settings - Fork 790
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
Named integer literals are not allowed in enum type definition #12896
Comments
Please add this to https://github.com/fsharp/fslang-suggestions. We can mark it as approved-in-principle. However note the natural completion is to allow |
Closing as should be tracked by a language suggestion |
Thanks for confirming that this is expected behavior! I will file a feature request there shortly and will link it here. Thanks! |
Hello, |
@vincentremond, there's an older suggestion and an RFC with implementation in progress, which aim to allow arithmetics (a set of constant expressions) in literals and attributes. It's sort of a prerequisite for what is requested here. I'm sure enums will then follow sooner rather than later. |
Repro steps
I am writing custom bindings for the GLFW library in F#. In doing so, I want to define modules that map as closely as possible to the exported DLL functions, macros, and typedefs. As such, I want to define named integer literals for the various errors that can be returned as:
That works fine. I then want to define an idiomatic F# module that wraps all of the bindings and creates a more native F# experience but still closely tied to the bindings. So I would like to define an error enum for pattern matching purposes, such as:
However, this is not allowed for some reason. The error is
FS0010: Unexpected identifier in union case
. According to the documentation for literal attributes, the named literals are compiled to constants. It isn't clear if the above enum error is expected or not, but given that the named literals are compiled to integer constants, I don't currently see a reason why this limitation should be in place.Expected behavior
I am not entirely sure what the F# compiler's expectation is, but from a user's perspective, I expected this to just work. In that, I expected something like the above to be identical to the case where if I defined the enum with the direct integer literals.
Actual behavior
Error
FS0010: Unexpected identifier in union case
is given.Known workarounds
Define the enum with integer literals and not named integer literals. However, I find this to be unsatisfactory from a design perspective.
Related information
Provide any related information (optional):
The text was updated successfully, but these errors were encountered: