codecadwallader / codemaid

CodeMaid is an open source Visual Studio extension to cleanup and simplify our C#, C++, F#, VB, PHP, PowerShell, JSON, XAML, XML, ASP, HTML, CSS, LESS, SCSS, JavaScript and TypeScript coding.
http://www.codemaid.net
GNU Lesser General Public License v3.0
1.89k stars 356 forks source link

Conflicting modifiers on partial classes #917

Open HugoRoss opened 2 years ago

HugoRoss commented 2 years ago

Environment

Description

When having a partial class over 2 files and in one file the class is defined as public and in the other it does not have an accessibility modifier, CodeMaid adds an internal modifier, which results in a compile error CS2062 "Partial declarations of '' have conflicting accessibility modifiers"

Steps to recreate

public partial class Foo {
}

partial class Foo {
}

Current behavior

CodeMaid changes the accessibility modifier of the class that is not declaring any accessibility modifiers to internal, which is incorrect and leads to a compile error:

public partial class Foo {
}

internal partial class Foo {
}

Expected behavior

CodeMaid should respect the already on any partial class part defined accessibility modifier and use that instead of internal:

public partial class Foo {
}

public partial class Foo {
}

or, as a quick fix, ignore adding accessibility modifiers to partial classes.

codecadwallader commented 2 years ago

Thanks for reporting the issue. I am able to reproduce it.

We do have explicit logic to handle this scenario (see https://github.com/codecadwallader/codemaid/blob/dev/CodeMaidShared/Logic/Cleaning/InsertExplicitAccessModifierLogic.cs#L61-L65)

However I think this is being impacted by the known SDK issue with access modifiers. Please see #879 for more information as well as a link to the Roslyn SDK issue.