Add analyzer warning for duplicate enum case labels (NEEG003)#162
Merged
andrewlock merged 7 commits intomainfrom Jul 19, 2025
Merged
Add analyzer warning for duplicate enum case labels (NEEG003)#162andrewlock merged 7 commits intomainfrom
andrewlock merged 7 commits intomainfrom
Conversation
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
…ation Co-authored-by: andrewlock <18755388+andrewlock@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add analyzer warning for duplicate case label
Add analyzer warning for duplicate enum case labels (NEEG003)
Jul 18, 2025
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.
Adds a new analyzer
DuplicateEnumValueAnalyzerthat warns developers when enum members have duplicate values and will be excluded from generated switch statements.Background
Issue #66 highlighted that the generator creates compiler warnings when generating
ToStringFast()methods for enums with duplicate values. PR #143 addressed this by using aHashSet<object>to track enum values and only creating switch cases for the first occurrence of each value. However, this means that duplicate enum members are silently excluded from the generated code, which can be confusing for developers.Changes
DuplicateEnumValueAnalyzer(diagnostic ID: NEEG003)[EnumExtensions]attributeDiagnosticSeverity.Infoto provide helpful warnings without breaking buildsExample
The analyzer will warn about
Errorsince it has the same value asFailedand will not be included in the generatedToStringFast(),IsDefined(), and other switch-based methods.Test Coverage
Added comprehensive test suite with 9 test cases covering:
[EnumExtensions]attribute (ignored)Validation
This provides developers with early visibility into which enum members will be excluded from generated code, complementing the fix in PR #143.
Fixes #161.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.