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
Analyzer incorrectly detects comment directives on nested switch statements #37
Comments
Thanks for the issue.
I think we should make the change to use If I understand correctly, doing so would be a breaking change such that:
this switch statement would no longer be ignored by the exhaustive program. We can adjust the tests accordingly, and mention this in the release notes. The suggested fix would be move the comment, like so:
I think making the above change to only considering
With the above change, this test case in the issue description should now pass too, I think. |
Problem
The analyzer seems to associate all comments within a switch statement with the switch statement. This seems to follow naturally from the definition of
ast.CommentMap.Filter
, which runsast.Inspect
on the specified node and grabs all comment groups from that recursive walk.Reproduction
Apply the following patch to the ignore comment test case file.
Tests will now fail because the ignore directive from the inner switch statement propagates to the outer switch statement.
Resolution
I'm not able to find anything in the AST package that satisfies the use case exactly. Using a direct
CommentMap[sw]
drops inline comments placed right after the switch token, since that comment is associated with the first case clause according to the AST. The easiest solution seems to be to walk from theswitchStmt
to the firstcaseStmt
and collect all comments associated with both of them before ending the walk.A rare edge case here: the switch variable could be an anonymous function invocation that itself contains a comment directive. The walk should therefore ignore any nodes deeper than the case statements of the top level switch.
The text was updated successfully, but these errors were encountered: