Skip to content

Commit

Permalink
Merge pull request #1120 from TymurGubayev/fix/RefConstArgument/1
Browse files Browse the repository at this point in the history
Always use `RefConversion.PreAssigment` for `const`s
  • Loading branch information
GrahamTheCoder authored Jul 22, 2024
2 parents fc0a1e6 + 19b0a5c commit cf2d4aa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CodeConverter/CSharp/ExpressionNodeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } or ILocalSymbol { IsConst: true }) {
return RefConversion.PreAssigment;
}

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

Expand Down
34 changes: 34 additions & 0 deletions Tests/CSharp/MemberTests/MemberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
}");
}
}

0 comments on commit cf2d4aa

Please sign in to comment.