fix: false positive cycle detection for shared struct references#101
Open
fix: false positive cycle detection for shared struct references#101
Conversation
The visited map was never cleaned up after printing a struct, so when two sibling fields pointed to the same struct, the second reference was falsely flagged as a cyclic reference. Fix by deleting the visit entry after the struct is fully printed. This way only ancestors on the current path are tracked, not all previously seen nodes. Real cycles are still correctly detected because the entry exists while recursing into the struct's fields. Fixes kr#96
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #96
Problem
When two struct fields point to the same struct (shared reference, not a cycle), the second field is falsely flagged as
(CYCLIC REFERENCE):The
visitedmap tracks all previously seen pointer addresses globally, but never removes them. So when a sibling field refers to the same struct, it appears as if we're revisiting an ancestor.Fix
Delete the visit entry from
visitedafter the struct is fully printed. This way only ancestors on the current recursion path are tracked, correctly distinguishing:Verified both cases: