Browse Source

Basic test for ref reassignment.

pull/1596/head
Siegfried Pammer 6 years ago
parent
commit
911a92f3f9
  1. 8
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

8
ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs

@ -189,6 +189,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -189,6 +189,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
CallOnInParam(in s, in r);
}
public void RefReassignment(ref NormalStruct s)
{
ref NormalStruct @ref = ref GetRef<NormalStruct>();
RefReassignment(ref @ref);
@ref = ref GetRef<NormalStruct>();
RefReassignment(ref @ref.GetHashCode() == 4 ? ref @ref : ref s);
}
public static void Main(string[] args)
{
DoubleNumber(ref args.Length == 1 ? ref numbers[0] : ref DefaultInt);

2
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertParenthesesVisitor.cs

@ -362,7 +362,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor @@ -362,7 +362,7 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
{
// assignment is right-associative
ParenthesizeIfRequired(assignmentExpression.Left, Assignment + 1);
if (InsertParenthesesForReadability) {
if (InsertParenthesesForReadability && !(assignmentExpression.Right is DirectionExpression)) {
ParenthesizeIfRequired(assignmentExpression.Right, RelationalAndTypeTesting + 1);
} else {
ParenthesizeIfRequired(assignmentExpression.Right, Assignment);

Loading…
Cancel
Save