-
Notifications
You must be signed in to change notification settings - Fork 13.3k
RFC: "don't omit me!" attribute for variants #2388
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
Hokey but potentially useful. I assume this would be integrated into the lint pass somehow. |
I guess this is ok, but I think it's better to just not use |
Well, I was never in favor of |
Since this is mostly for refactoring maybe it could be part of a tool that just tells you all the patterns that fail to mention a certain variant. There have been some other queries I've wanted to make about the code base, like 'what are the dependencies of this module?' |
@brson True, but IMO, it would be nice to know that right off the bat and not have to remember to invoke a separate tool (and yes, you still have to remember to put in the attribute, but that seems like less overhead than having to invoke a tool). Otherwise, I would probably forget to run the tool, and then I would still not discover the missing case until I saw it as a runtime error. |
I don't mean eliminating |
That works fine for a single-person project, but not for one where some people don't use |
In other words, it really means "don't let someone else's code shoot me in the foot". |
I don't agree that an attribute is less work than a tool; you don't want to check in the attribute, so you need to remember to remove it after you add it. A tool is more foolproof that way. We're basically talking about static analyses here; simple one-time static analyses shouldn't require modification of the code. |
Add a lint pass: Lint pass was made for this kind of thing. Also do one for unsafe and another for unadorned fail while you're in there :) |
It seems that this is still relevant in the presence of |
I'm not sure. since all matches are exhaustive now, is this really more of a "don't use wildcards on this enum" lint? |
Or, more of a "don't consider this variant for wildcarding". Not sure this would be very useful, but a lint wouldn't be bad. |
Removing the E-easy label because it's not quite clear where to go with this after its aged so much. I personally feel like exhaustiveness checks supersedes this and that a more appropriate lint would be about not allowing wildcards, but even that's a little difficult to implement. |
If someone is still interested in a feature like this, I think a new proposal should be done based on the current language design. |
Upgrade CBMC version to 5.81.0.
I just ran into a variation on the following problem: Suppose I have a data type
enum A { B, C}
and some code somewhere else like:
This says "I know that
foo
can't be in variantC
". But what if I add a new variantD
toA
? Perhaps I really should add a case to thealt
forD
(sincefoo
could now be in variantD
), but the compiler gives me zero help in this case.I propose an attribute called
no_omit
(actually, I don't really care what it's called) to be used like:enum A { B, C, #[no_omit] D}
which has the effect of generating a warning if any
alt check
expressions omit the case forD
. (I'm not too opinionated about whether it should be a lint warning or an error, so long as there's some way to enable it.) I expect the attribute would be used temporarily, during development, and then removed once the refactor that introducesD
is completed.The text was updated successfully, but these errors were encountered: