Skip to content

VB -> C#: wrong conversion of optional struct or decimal ref parameter #886

@KunzeAndreas

Description

@KunzeAndreas

VB.Net input code

Private Shared Sub OptionalParams()
    FunctionWithOptionalParams()
End Sub

 Private Shared Sub FunctionWithOptionalParams(Optional ByRef structParam As TestStruct = Nothing, Optional ByRef decimalParam As Decimal = 0)
    structParam = New TestStruct
    decimalParam = 0
 End Sub

Friend Structure TestStruct
    Friend A As Boolean
End Structure

Erroneous output

 private static void OptionalParams()
 {
      TestStruct argstructParam = null;
      decimal argdecimalParam = 0m;
      FunctionWithOptionalParams(structParam: ref argstructParam, decimalParam: ref argdecimalParam);
 }

private static void FunctionWithOptionalParams([Optional, DefaultParameterValue(default(TestStruct))] ref TestStruct structParam, [Optional, DefaultParameterValue(0m)] ref decimal decimalParam)

Expected output

private static void OptionalParams()
{
    TestStruct argstructParam = default;
}

private static void FunctionWithOptionalParams([Optional] ref TestStruct structParam, [Optional, DefaultParameterValue(0)] ref decimal decimalParam)

Details

  • Product in use: VS extension
  • Version in use: 9.0.0.0
  • Did you see it working in a previous version, which? no
  • may be, there is a better way to express DefaultParameterValue for a structure

Metadata

Metadata

Assignees

No one assigned

    Labels

    Good for coding agentCoding agent might get it in one - small change with reproVB -> C#Specific to VB -> C# conversioncompilation errorA bug where the converted output won't compile

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions