-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Formally introduce a class of errors that can be automatically fixed #17584
Comments
I think autofmt for unused variables actually work pretty well, and am happy to see that the idea is to add autofix fixes for these issues before they become actual compile errors (if I understand you correctly). Things I just wanted to point out because I hit upon them from time to time:
I know it's been said before but to me a lot of the frustration from these issues comes from having made a temporary change to code that would still work if it would compile (i.e. it's not a "real" (super scare quotes) compile error), so I compile, only for me to have to look through the compile errors to see what the problem was, sigh, and remove some code that I've written that isn't really causing a problem, compile again, and then run it. Then, I need to do the whole thing backwards again. It not only increases the time it takes to code something to running the game from a second to dozens of seconds, it also makes me lose focus. But having autofix fix the code automatically is good enough! :) |
Which one is the mistake in all cases – the capture, or the mutation? I think it would be better if the error instead pointed to locations of all candidates for decision.
Now each location is clearly marked and you can jump to whichever you need to make the decision. |
I disagree. All it does is hide the problem (while adding clutter) without solving it. The problem is that your code declares a variable that is not used for anything meaningful. Autofix does not address that problem. The entire reason why an unused variable is a compile error is because it's a code smell that should be addressed. But instead of encouraging people to address the issue, it encourages people to spend their precious time developing a tool to trick the compiler. Now the problem is actually worse because it adds more meaningless code, and it is harder for a linting tool to detect it. In an attempt to force people to write higher quality code, a perverse incentive has been created, which could actually result in even lower quality code. Why don't we just let people compile their code when their priority is to compile the code, and lint their code when the priority is to lint their code? Conflating the two makes both less effective. |
We already have such a class of errors. Nearly every version of Zig has released with
zig fmt
having the capability to automatically convert old syntax to new syntax, for example renaming@fabs
to@abs
. Ifzig fmt
is not run on such source files, a compilation error would occur.This proposal is to embrace this concept and take it a step further. Here are some errors that I think belong in this category:
While a careful programmer might want to know about the occurrence of such problems, all of these do have an obvious solution that can be performed automatically.
Proposed action items:
--autofix
flag that opts into these fixups. When this flag is enabled, errors in this category do not cause compilation to halt. Instead, the source files of the compilation are mutated in place, and compilation proceeds as if the original input had the fixups applied. If any error occurs applying fixups, the compilation fails the same way as if the fixups were not applied.zig fmt
should ignore a subset of errors in this category, such as anything to do with invalid whitespace that will be fixed byzig fmt
itself.The text was updated successfully, but these errors were encountered: