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#: ref must be an assignable variable #264

Open
mrmonday opened this Issue Apr 5, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@mrmonday
Copy link
Contributor

mrmonday commented Apr 5, 2019

Input code

Public Class Class1
    Sub Foo()
        Bar(New Class1)
    End Sub

    Sub Bar(ByRef class1)
    End Sub
End Class

Erroneous output

public class Class1
{
    public void Foo()
    {
        Bar(ref new Class1());
    }

    public void Bar(ref object class1)
    {
    }
}

Expected output

public class Class1
{
    public void Foo()
    {
        var class1 = new Class1();
        Bar(ref class1);
    }

    public void Bar(ref object class1)
    {
    }
}

Details

Product in use: VS extension

Version in use: 6.6.0

VB allows passing ref values directly without first assigning to a variable.

@mrmonday

This comment has been minimized.

Copy link
Contributor Author

mrmonday commented Apr 5, 2019

There is a similar issue when using a property as the parameter - this needs to be assigned to a variable too.

@mrmonday

This comment has been minimized.

Copy link
Contributor Author

mrmonday commented Apr 5, 2019

Similar issue, though possibly different:

Public Class Class1
    Sub Foo()
        Using x = New SqlConnection
            Bar(x)
        End Using
    End Sub
    Sub Bar(ByRef x As SqlConnection)

    End Sub
End Class
using System.Data.SqlClient;

public class Class1
{
    public void Foo()
    {
        using (var x = new SqlConnection())
        {
            Bar(ref x);
        }
    }
    public void Bar(ref SqlConnection x)
    {
    }
}

Error:

CS1657	Cannot use 'x' as a ref or out value because it is a 'using variable'

@fabienDaou fabienDaou referenced a pull request that will close this issue Apr 8, 2019

Open

Fix byref parameter #204

@GrahamTheCoder

This comment has been minimized.

Copy link
Member

GrahamTheCoder commented Apr 8, 2019

I think the first bit is what PR #204 was trying to fix, though progress stalled.
The "using" case hadn't come up before though so it seems there's even more to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.