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
cmd/vet: add test for use of constraints package in way that is not forward compatible #48365
Comments
How would you detect that? That is, how can you tell that the user is trying to handle all types? |
Look for a type switch on a variable constrained by a constraint from the constraints package. Give an error if all the types in the current constraints implementation appear as cases and there is no |
What if there is a default case that panics? |
We can't be perfect, but we can do better than nothing. |
But vet needs to be close to perfect. "Better than nothing" is not good enough. |
My concern is that this vet checker would not find bugs in the user code per se, yet perhaps issues in the design. The current code is not buggy they way I see it. So the checker findings IMO could be interpreted as warnings saying |
Fair enough. We may have to drop the type switch part of this idea. |
@zpavlinovic I see this as similar to the current vet warning about using an unkeyed composite literal with a struct type defined in a different package. It warns about code that is correct at the moment but may break in the future. |
Moving to 1.19. |
Moving to Backlog. |
We decided against putting the constraints package into the standard library, so this issue is of little interest. Closing. |
In the discussion of the constraints package @benjaminjkraft raised an issue (#47319 (comment)). This kind of code:
will fail to compile if we add a new type to
constraints.Signed
, because the new type will not be accepted by theMySigned
constraint. However, we want to be able to add new types to the constraints package if we add new predeclared types to the language. That is, this bit of code is not forward compatible with possible future changes to the constraints package.We can avoid such difficulties by adding vet checks for the following:
any
and is not taken from the constraints package.This issue is to add those vet checks.
The text was updated successfully, but these errors were encountered: