[BOUNTY #53563] Fix CS0660 false positive for partial classes with source-generated members on Linux#53568
Open
zhaog100 wants to merge 1 commit intodotnet:mainfrom
Open
Conversation
…embers on Linux - Remove IsInSource check in diagnostic filtering to properly handle partial classes with source-generated members - This fixes incorrect CS0660 warnings when using source generators like OneOf with partial classes on Linux - The IsInSource check was causing diagnostics from source-generated partial class members to be incorrectly filtered Fixes dotnet#53563
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.
Description
This PR fixes issue #53563 where
dotnet formaton Linux incorrectly reports CS0660 warning for generic types when using source generators with partial classes.Problem
When using source generators like OneOf's
[GenerateOneOf]with partial classes that implementIEquatable<T>,dotnet formaton Linux incorrectly reports:error CS0660: 'MyClass' defines operator == or operator != but does not override Object.Equals(object o)This issue does not occur on Windows.
Root Cause
The diagnostic filtering logic in
AnalyzerRunner.cswas usingdiagnostic.Location.IsInSourcecheck, which was causing diagnostics from source-generated partial class members to be incorrectly filtered on Linux.Solution
Remove the
IsInSourcecheck in diagnostic filtering to properly handle partial classes with source-generated members. TheSourceTree != nullcheck is sufficient to ensure we only process diagnostics from source files.Changes
src/Dotnet.Format/dotnet-format/Analyzers/AnalyzerRunner.csdiagnostic.Location.IsInSourcecheck from diagnostic filtering logicCloses #53563