Skip to content

[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
zhaog100:fix/cs0660-partial-class-source-generator
Open

[BOUNTY #53563] Fix CS0660 false positive for partial classes with source-generated members on Linux#53568
zhaog100 wants to merge 1 commit intodotnet:mainfrom
zhaog100:fix/cs0660-partial-class-source-generator

Conversation

@zhaog100
Copy link
Copy Markdown

Description

This PR fixes issue #53563 where dotnet format on 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 implement IEquatable<T>, dotnet format on 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.cs was using diagnostic.Location.IsInSource check, which was causing diagnostics from source-generated partial class members to be incorrectly filtered on Linux.

Solution

Remove the IsInSource check in diagnostic filtering to properly handle partial classes with source-generated members. The SourceTree != null check is sufficient to ensure we only process diagnostics from source files.

Changes

  • Modified src/Dotnet.Format/dotnet-format/Analyzers/AnalyzerRunner.cs
  • Removed diagnostic.Location.IsInSource check from diagnostic filtering logic
  • Added comment explaining the fix

Closes #53563

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet format on Linux incorrectly reports CS0660 warning for generated partial class with IEquatable<> implementation

1 participant