From a22c24cafb785ae1c37d8d6abb8a95bfc4465a7c Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Mon, 22 Jul 2024 16:06:22 +0200 Subject: [PATCH 1/3] add a test for ByRef const argument --- Tests/CSharp/MemberTests/MemberTests.cs | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Tests/CSharp/MemberTests/MemberTests.cs b/Tests/CSharp/MemberTests/MemberTests.cs index 148aa6a5..bbb4389c 100644 --- a/Tests/CSharp/MemberTests/MemberTests.cs +++ b/Tests/CSharp/MemberTests/MemberTests.cs @@ -4047,6 +4047,40 @@ public static int StaticTestProperty return _StaticTestProperty_sPrevPosition + 1; } } +}"); + } + + [Fact] + public async Task TestRefConstArgumentAsync() + { + await TestConversionVisualBasicToCSharpAsync( + @"Class RefConstArgument + Const a As String = ""a"" + Sub S() + Const b As String = ""b"" + MO(a) + MS(b) + End Sub + Sub MO(ByRef s As Object) : End Sub + Sub MS(ByRef s As String) : End Sub +End Class", @" +internal partial class RefConstArgument +{ + private const string a = ""a""; + public void S() + { + const string b = ""b""; + object args = a; + MO(ref args); + string args1 = b; + MS(ref args1); + } + public void MO(ref object s) + { + } + public void MS(ref string s) + { + } }"); } } \ No newline at end of file From a265518b683a8c807e537cc4ef4db47da723758b Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Mon, 22 Jul 2024 16:07:36 +0200 Subject: [PATCH 2/3] GetRefConversion: for const fields and locals always return RefConversion.PreAssigment --- CodeConverter/CSharp/ExpressionNodeVisitor.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CodeConverter/CSharp/ExpressionNodeVisitor.cs b/CodeConverter/CSharp/ExpressionNodeVisitor.cs index 1084ed19..43bb546e 100644 --- a/CodeConverter/CSharp/ExpressionNodeVisitor.cs +++ b/CodeConverter/CSharp/ExpressionNodeVisitor.cs @@ -1836,6 +1836,9 @@ RefConversion GetRefConversion(VBSyntax.ExpressionSyntax expression) if (symbolInfo is IPropertySymbol propertySymbol) { return propertySymbol.IsReadOnly ? RefConversion.PreAssigment : RefConversion.PreAndPostAssignment; } + else if (symbolInfo is IFieldSymbol { IsConst: true } || symbolInfo is ILocalSymbol { IsConst: true }) { + return RefConversion.PreAssigment; + } if (DeclaredInUsing(symbolInfo)) return RefConversion.PreAssigment; From 19b0a5c5eea42f887b1d6cb4b02f00fe68c12dd3 Mon Sep 17 00:00:00 2001 From: Timur Kelman Date: Mon, 22 Jul 2024 16:13:59 +0200 Subject: [PATCH 3/3] use tighter pattern matching syntax --- CodeConverter/CSharp/ExpressionNodeVisitor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CodeConverter/CSharp/ExpressionNodeVisitor.cs b/CodeConverter/CSharp/ExpressionNodeVisitor.cs index 43bb546e..9af8d45f 100644 --- a/CodeConverter/CSharp/ExpressionNodeVisitor.cs +++ b/CodeConverter/CSharp/ExpressionNodeVisitor.cs @@ -1836,7 +1836,7 @@ RefConversion GetRefConversion(VBSyntax.ExpressionSyntax expression) if (symbolInfo is IPropertySymbol propertySymbol) { return propertySymbol.IsReadOnly ? RefConversion.PreAssigment : RefConversion.PreAndPostAssignment; } - else if (symbolInfo is IFieldSymbol { IsConst: true } || symbolInfo is ILocalSymbol { IsConst: true }) { + else if (symbolInfo is IFieldSymbol { IsConst: true } or ILocalSymbol { IsConst: true }) { return RefConversion.PreAssigment; }