CodeConverter icon indicating copy to clipboard operation
CodeConverter copied to clipboard

VB -> C#: incorrect output code if ref return from a C# lib is involved

Open TymurGubayev opened this issue 6 months ago • 0 comments

VB.Net input code

We need a C#-project with a ref return first, f.e.

public class MySpecialList<T>
{
    private T dummy;
    public ref T this[int i]
    {
        get
        {
            return ref dummy;
        }
    }
}

Then in vb.net (array is for comparison)

Sub UseArr()
    Dim arr() As Object
    Modify(arr(0))
End Sub

Sub UseRefReturn()
    Dim lst As CSProj.MySpecialList(Of Object)
    Modify(lst(0))
End Sub

Sub Modify(ByRef o As Object)
End Sub

Erroneous output

public void UseArr()
{
    var arr = default(object[]);
    Modify(ref arr[0]);
}

public void UseRefReturn()
{
    var lst = default(CSProj.MySpecialList<object>);
    var tmp = lst;
    var argo = tmp[0];
    Modify(ref argo); //note the modified value never makes it back into the list
}

public void Modify(ref object o)
{
}

Expected output

public void UseArr()
{
    var arr = default(object[]);
    Modify(ref arr[0]);
}

public void UseRefReturn()
{
    var lst = default(CSProj.MySpecialList<object>);
    Modify(ref lst[0]);
}

public void Modify(ref object o)
{
}

Details

  • Product in use: VS extension
  • Version in use: 9.2.4 (dd3edd8862e6a743eca532c861145768c6601929)
  • Did you see it working in a previous version, which? No
  • Any other relevant information to the issue, or your interest in contributing a fix.

This is most probably related to https://github.com/icsharpcode/CodeConverter/issues/1052#issuecomment-1856145388

TymurGubayev avatar Dec 19 '23 15:12 TymurGubayev