checker: Detection of circular type references#26162
Merged
Merged
Conversation
1. vlib/v/checker/checker.v Added cycle detection for sum types: - Added an else if branch to check when a variant is itself a sum type - Added a new helper function sumtype_has_circular_ref() that recursively traverses sum type variants to detect cycles - Uses a visited map to prevent infinite recursion during cycle detection 2. New test files: - vlib/v/checker/tests/sumtype_circular_reference_err.vv - Test case with circular reference - vlib/v/checker/tests/sumtype_circular_reference_err.out - Expected error output
Contributor
|
(rebased over current master, to force a recheck in the CI jobs running on windows) |
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.
Issue: V incorrectly permitted circular type references in sum types like:
type Type6 = Type7 | int
type Type7 = Type6 | string
Root Cause: The checker only detected direct self-references (type A = A | int) but not indirect cycles through other sum types.
Fix:
Added cycle detection for sum types:
Verification:
The fix correctly detects:
Non-circular sum types that reference other sum types still work correctly.
Fixes #24511