-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Symbol autocasting flag enum #10680
Comments
Can't be done, sorry. What's the type of |
To explain a bit more, the compiler will first type-check a call's arguments. Once all types are defined it can start searching matches. In the case of a Symbol type, if the argument is a SymbolLiteral it will try to do autocasting. But here it would be different because there's no way the compiler can type |
I suppose technically, the compiler could get similar special handling for calls to That sounds feasible to me. Yet, I don't think it's high priority. Although I fully relate to the motivation for this, and it would be really nice to have. |
As a workaround for now, I recently discovered the |
As long as the first flag is properly typed as a flags enum member, all the following ones can be symbol literals because autocasting of Foo::One | :two This should work pretty well as a simplified workaround. You only need the full path once. Perhaps this could also help to implement proper autocasting for flags enum combinations. The expression The trouble with that is the order of typing: When you have a call |
With the introduction of #12900, would this feature even be worth it? |
I think yes, that is enough to close this off. The other approach is already there, is less hacky and indeed with this there would be too many ways to do this. |
One of the main features of symbols is the ability to auto cast into an enum member. However symbol auto casting does not currently support flag enums when more than 1 member is used. E.g.
I propose to expand the autocasting functionality to also support multiple members. This will ultimately need to be done if we want to move forward with removing manual symbols holistically, ref: #6736.
The main usecase for this is to just reduce the amount of typing when multiple members are needed. Currently the expression can be quite long, especially if the enum is namespaced.
The text was updated successfully, but these errors were encountered: