Closed metagn closed 2 years ago
The problem with this proposal is that it keeps two distinct forms of enum
in Nim. Ideally there is only one enum
construct that just works.
Should these tests be removed then? Keeping the tests means we would need to keep some way to opt in/out of overloadableEnums, meaning there would still be 2 enum constructs.
I dislike this proposal. Overloadable enums looks like a proper way enums should work. It should not need any annotations, it should just work, by default.
Should these tests be removed then?
Yes.
Should these tests be removed then?
Yes.
Abstract
Require an annotation/pragma (preferably a repurposed/renamed
{.pure.}
) on enum types to be able to use their fields as overloads.Motivation
The following code works without, but breaks with
--experimental:overloadableEnums
(https://github.com/nim-lang/Nim/issues/20077):A more important version of this problem is with imports. There are multiple tests for this, both without and with imports.
However, this is mostly intended behavior of overloadableEnums. Consider the following:
An ambiguity error is the most sensible outcome here; with
--experimental:overloadableEnums
there is an ambiguity error, without it,what
has typeC
. So the behavior ofoverloadableEnums
here is preferred.The difference between the example code and the test cases is that in the example case, the enums would normally have the
{.pure.}
annotation, while other enums may not necessarily need fancy behavior like this. So maybe the best solution is to restrict this overloading behavior to pure enums, while also removing any remaining need for qualification of pure enums.Description
pure
as is is generally regarded to be useless and deserving deprecation because of it not working as documented, so giving it new meaning that is compatible with its common/intended use is acceptable. If a new name for this is used instead ofpure
, thenpure
can be deprecated and alias to the new name.This will make the transition to
--experimental:overloadableEnums
easier for normal projects, as they can gradually enable certain enums to work this way. Projects already using--experimental:overloadableEnums
will have to annotate their enums withpure
. We could makepure
the default somehow but this doesn't fit the narrative of them being "fancy" enums.Code Examples
Backwards Compatibility
Backwards incompatible for projects already using
overloadableEnums
however the fix is extremely adaptable and simple.If
pure
is used, the behavior of the oldpure
would be removed, but this can still only be under--experimental:overloadableEnums
.