icsharpcode / CodeConverter

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

VB -> C#: OmittedArgumentSyntax isn't converted into temporary variable for ByRef parameters causing error CS7036 #1107

Closed TymurGubayev closed 2 months ago

TymurGubayev commented 4 months ago

VB.Net input code

Sub M(Optional a As String = "a", ByRef Optional b As String = "b")
    Dim s As String = ""

    M() 'omitted implicitely
    M(,) 'omitted explicitely

    M(s) 'omitted implicitely
    M(s,) 'omitted explicitely

    M(a:=s) 'omitted implicitely
    M(a:=s, ) 'omitted explicitely
End Sub

Erroneous output

public void M([Optional, DefaultParameterValue("a")] string a, [Optional, DefaultParameterValue("b")] ref string b)
{
    string s = "";

    string argb = "b";
    M(b: ref argb); // omitted implicitely
    this.M(); // omitted explicitely --- error CS7036

    string argb1 = "b";
    M(s, b: ref argb1); // omitted implicitely
    this.M(s); // omitted explicitely --- error CS7036

    string argb2 = "b";
    M(a: s, b: ref argb2); // omitted implicitely
    this.M(a: s); // omitted explicitely --- error CS7036
}

Expected output

public void M([Optional, DefaultParameterValue("a")] string a, [Optional, DefaultParameterValue("b")] ref string b)
{
    string s = "";

    string argb = "b";
    M(b: ref argb); // omitted implicitely
    M(b: ref argb); // omitted explicitely

    string argb1 = "b";
    M(s, b: ref argb1); // omitted implicitely
    M(s, b: ref argb1); // omitted explicitely

    string argb2 = "b";
    M(a: s, b: ref argb2); // omitted implicitely
    M(a: s, b: ref argb2); // omitted explicitely
}

Details

TymurGubayev commented 2 months ago

fixed in #1121