Skip to content

Commit 871f088

Browse files
Merge pull request #1125 from TymurGubayev/fix/RefFunctionCallArgument/1
Don't write back into a method call when it's ByRef argument
2 parents 9e929e1 + 151526a commit 871f088

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

CodeConverter/CSharp/ExpressionNodeVisitor.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,13 +1920,15 @@ private RefConversion NeedsVariableForArgument(VBasic.Syntax.ArgumentSyntax node
19201920
RefConversion GetRefConversion(VBSyntax.ExpressionSyntax expression)
19211921
{
19221922
var symbolInfo = GetSymbolInfoInDocument<ISymbol>(expression);
1923-
if (symbolInfo is IPropertySymbol propertySymbol
1924-
// a property in VB.NET code can be ReturnsByRef if it's defined in a C# assembly the VB.NET code references
1925-
&& !propertySymbol.ReturnsByRef && !propertySymbol.ReturnsByRefReadonly) {
1923+
if (symbolInfo is IPropertySymbol { ReturnsByRef: false, ReturnsByRefReadonly: false } propertySymbol) {
1924+
// a property in VB.NET code can be ReturnsByRef if it's defined in a C# assembly the VB.NET code references
19261925
return propertySymbol.IsReadOnly ? RefConversion.PreAssigment : RefConversion.PreAndPostAssignment;
19271926
}
19281927
else if (symbolInfo is IFieldSymbol { IsConst: true } or ILocalSymbol { IsConst: true }) {
19291928
return RefConversion.PreAssigment;
1929+
} else if (symbolInfo is IMethodSymbol { ReturnsByRef: false, ReturnsByRefReadonly: false }) {
1930+
// a method in VB.NET code can be ReturnsByRef if it's defined in a C# assembly the VB.NET code references
1931+
return RefConversion.PreAssigment;
19301932
}
19311933

19321934
if (DeclaredInUsing(symbolInfo)) return RefConversion.PreAssigment;

Tests/CSharp/MemberTests/MemberTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,30 @@ public void MS(ref string s)
42034203
}");
42044204
}
42054205

4206+
[Fact]
4207+
public async Task TestRefFunctionCallNoParenthesesArgumentAsync()
4208+
{
4209+
await TestConversionVisualBasicToCSharpAsync(
4210+
@"Class RefFunctionCallArgument
4211+
Sub S(ByRef o As Object)
4212+
S(GetI)
4213+
End Sub
4214+
Function GetI() As Integer : End Function
4215+
End Class", @"
4216+
internal partial class RefFunctionCallArgument
4217+
{
4218+
public void S(ref object o)
4219+
{
4220+
object argo = GetI();
4221+
S(ref argo);
4222+
}
4223+
public int GetI()
4224+
{
4225+
return default;
4226+
}
4227+
}");
4228+
}
4229+
42064230
[Fact]
42074231
public async Task TestMissingByRefArgumentWithNoExplicitDefaultValueAsync()
42084232
{

0 commit comments

Comments
 (0)