codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

`ref struct`s get code cleaned to `internal struct`, dropping the ref

Open lcsondes opened this issue 5 years ago • 10 comments
trafficstars

Environment

  • Visual Studio version: 2019 Community
  • CodeMaid version: 11.1
  • Code language: C#

Description

using System;

ref struct Bug // This will get code cleaned to internal struct, which won't compile
{
    private Span<int> x;
}

internal class Program
{
    public static void Main()
    {
    }
}

Steps to recreate

Code cleanup the above code snippet.

Current behavior

ref struct is changed to internal struct. This is a breaking change even if it didn't contain a Span<T>.

In the case of ref readonly struct it gets cleaned to ref readonly internal struct which does not compile either.

Expected behavior

Not breaking the code.

lcsondes avatar Feb 10 '20 10:02 lcsondes

Thanks for reporting the issue. I am unable to reproduce it placing that code inside an existing C# console application. Can you please provide a minimal solution that reproduces the issue for you, as well as your CodeMaid settings in case there is a combination that may be causing the issue?

codecadwallader avatar Feb 15 '20 20:02 codecadwallader

It's a fresh project. This is the csproj, have it next to the sample file above:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

</Project>

lcsondes avatar Feb 15 '20 21:02 lcsondes

I do have a .csproj that matches that configuration, but I'm still unable to reproduce it. To make sure there isn't some unexpected difference between our environments, can you please attach your minimal solution?

codecadwallader avatar Feb 22 '20 16:02 codecadwallader

Here: CsSandbox.zip

Clean up Program.cs and ref struct Test will become internal struct Test.

lcsondes avatar Feb 23 '20 18:02 lcsondes

Thanks for providing that example, I am able to reproduce it now. Interestingly enough, the difference of having the trailing comment // This will get code cleaned.. is what makes the bug occur or not occur.

The insert explicit access modifier logic uses the VS API to add the "current" access modifier if it's not found within the declaration. We previously found this would cause a similar issue with explicit interface implementations and had to make an exception case for it. I suspect we may need to do the same thing here and extend the unit tests to cover this scenario.

codecadwallader avatar Feb 29 '20 14:02 codecadwallader

Any updates? Issue still persists.

GeorgeAlexandria avatar Nov 13 '21 21:11 GeorgeAlexandria

I do not have much of an update other than I would recommend disabling the insert explicit access modifiers option at this time if you're encountering this issue. There are some new issues that have been registered that are also related to the explicit access modifier logic so perhaps this could be addressed as well if that feature gets some attention.

codecadwallader avatar Nov 16 '21 13:11 codecadwallader

This is still a problem

TheKayneGame avatar Dec 05 '22 13:12 TheKayneGame

Still a problem

maranmaran avatar Mar 16 '23 14:03 maranmaran

The problem still persists.

Sinus32 avatar Mar 06 '24 09:03 Sinus32