Fix crash, false-positive in no-statement-after-end #316
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #315 by changing the way
no-statement-after-end
recordsCodePathSegment
s. The stack is used only to hold the in-progress segment in the outerCodePath
s. WhenCodePath
s begin or end, the current segment is pushed onto or popped from the stack. WhenCodePathSegment
s begin or end, the current segment is set or unset.When in unreachable code at the end of a path, the current segment is therefore undefined, rather than erroneously taken from the next-outermost path.
Checks whether the current segment is set before operating on it.
(Interestingly, this rule doesn't catch statements after
t.end()
in unreachable code, e.g.:This behavior predates this PR.)
While I believe this fixes the issue, I don't fully understand how this rule ought to handle its edge-cases nor why the codepath analysis system works this way. Please review carefully?