Skip to content

Commit c5ba8e6

Browse files
committed
Add regression tests for issue #557: char default value for string parameter
Two tests cover the fix for converting VB Optional string parameters with char default values: one using a const reference and one using an inline char literal. https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
1 parent 3026e66 commit c5ba8e6

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

Tests/CSharp/MemberTests/MemberTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,4 +1576,49 @@ private void OptionalByRefWithDefault([Optional][DefaultParameterValue(""a"")] r
15761576
CS7036: There is no argument given that corresponds to the required parameter 'str1' of 'MissingByRefArgumentWithNoExplicitDefaultValue.ByRefNoDefault(ref string)'
15771577
");
15781578
}
1579+
1580+
[Fact]
1581+
public async Task TestCharConstDefaultValueForStringParameterAsync()
1582+
{
1583+
// Issue #557: VB allows a Char constant as a default value for a String parameter, but C# does not.
1584+
// Replace the default with null and prepend a null-coalescing assignment in the method body.
1585+
await TestConversionVisualBasicToCSharpAsync(
1586+
@"Module TestModule
1587+
Friend Const DlM As Char = ""^""c
1588+
1589+
Friend Function LeftSideOf(Optional ByVal strDlM As String = DlM) As String
1590+
Return strDlM
1591+
End Function
1592+
End Module", @"
1593+
internal static partial class TestModule
1594+
{
1595+
internal const char DlM = '^';
1596+
1597+
internal static string LeftSideOf(string strDlM = null)
1598+
{
1599+
strDlM = strDlM ?? DlM.ToString();
1600+
return strDlM;
1601+
}
1602+
}");
1603+
}
1604+
1605+
[Fact]
1606+
public async Task TestCharLiteralDefaultValueForStringParameterAsync()
1607+
{
1608+
// Issue #557: inline char literal as default value for a String parameter.
1609+
await TestConversionVisualBasicToCSharpAsync(
1610+
@"Class TestClass
1611+
Friend Function Foo(Optional s As String = ""^""c) As String
1612+
Return s
1613+
End Function
1614+
End Class", @"
1615+
internal partial class TestClass
1616+
{
1617+
internal string Foo(string s = null)
1618+
{
1619+
s = s ?? '^'.ToString();
1620+
return s;
1621+
}
1622+
}");
1623+
}
15791624
}

0 commit comments

Comments
 (0)