icsharpcode / CodeConverter

Convert code from C# to VB.NET and vice versa using Roslyn
https://icsharpcode.github.io/CodeConverter/
MIT License
795 stars 207 forks source link

VB -> C#: ByRef temporary variable is assigned back into a constant #1106

Open TymurGubayev opened 1 month ago

TymurGubayev commented 1 month ago

VB.Net input code

Public Class ByRefConstArgument
    Public Const i As Integer = 0

    Public Sub M(ByRef o As Object)
        M(i)
    End Sub
End Class

Erroneous output

public class ByRefConstArgument
{
    public const int i = 0;

    public void M(ref object o)
    {
        object argo = i;
        M(ref argo);
        ByRefConstArgument.i = Conversions.ToInteger(argo); // can't do this
    }
}

Expected output

public class ByRefConstArgument
{
    public const int i = 0;

    public void M(ref object o)
    {
        object argo = i;
        M(ref argo);
    }
}

Details