I do not think this is achievable or desirable. I will try to explain why.
I don’t think it’s possible, because you have to analyze both the comment (in natural language) and the code, and decide whether they describe the same behavior. Deriving code from static code analysis is much more complicated than you think (google for "stopping problem"). Natural language is even more complicated.
I do not think this is desirable, because if a comment can be “calculated” by checking the code, it will be redundant and, therefore, a violation of the principle of DRY (Do not Repeat Yourself). In this case, there should be no comments. This saves time (no need to write), clutter (it doesn't distract you from the code), and it also can't be wrong / misleading anymore.
Of course, there are exceptions when commenting code is required (for example, when you provide an API for a command elsewhere). But also in this situation, you better explain the non-obvious aspects of your code. In your example, I would warn about indexes based on 1, but I would not explain that the index is 0, since I consider this to be the default.
user180326
source share