Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TymurGubayev opened this issue Dec 19, 2023 · 0 comments
Open
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@TymurGubayev
Copy link
Contributor

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 (dd3edd8)
  • 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 #1052 (comment)

@TymurGubayev TymurGubayev added the VB -> C# Specific to VB -> C# conversion label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

1 participant