Skip to content

Commit cf2d4aa

Browse files
Merge pull request #1120 from TymurGubayev/fix/RefConstArgument/1
Always use `RefConversion.PreAssigment` for `const`s
2 parents fc0a1e6 + 19b0a5c commit cf2d4aa

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

CodeConverter/CSharp/ExpressionNodeVisitor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,9 @@ RefConversion GetRefConversion(VBSyntax.ExpressionSyntax expression)
18361836
if (symbolInfo is IPropertySymbol propertySymbol) {
18371837
return propertySymbol.IsReadOnly ? RefConversion.PreAssigment : RefConversion.PreAndPostAssignment;
18381838
}
1839+
else if (symbolInfo is IFieldSymbol { IsConst: true } or ILocalSymbol { IsConst: true }) {
1840+
return RefConversion.PreAssigment;
1841+
}
18391842

18401843
if (DeclaredInUsing(symbolInfo)) return RefConversion.PreAssigment;
18411844

Tests/CSharp/MemberTests/MemberTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,6 +4047,40 @@ public static int StaticTestProperty
40474047
return _StaticTestProperty_sPrevPosition + 1;
40484048
}
40494049
}
4050+
}");
4051+
}
4052+
4053+
[Fact]
4054+
public async Task TestRefConstArgumentAsync()
4055+
{
4056+
await TestConversionVisualBasicToCSharpAsync(
4057+
@"Class RefConstArgument
4058+
Const a As String = ""a""
4059+
Sub S()
4060+
Const b As String = ""b""
4061+
MO(a)
4062+
MS(b)
4063+
End Sub
4064+
Sub MO(ByRef s As Object) : End Sub
4065+
Sub MS(ByRef s As String) : End Sub
4066+
End Class", @"
4067+
internal partial class RefConstArgument
4068+
{
4069+
private const string a = ""a"";
4070+
public void S()
4071+
{
4072+
const string b = ""b"";
4073+
object args = a;
4074+
MO(ref args);
4075+
string args1 = b;
4076+
MS(ref args1);
4077+
}
4078+
public void MO(ref object s)
4079+
{
4080+
}
4081+
public void MS(ref string s)
4082+
{
4083+
}
40504084
}");
40514085
}
40524086
}

0 commit comments

Comments
 (0)