Browse Source

Keep ref-returning switches as statements

C# has no ref-returning switch expression. Skip the transform for StackType.Ref and cover the statement form in RefLocalsAndReturns.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0dd407b6-9410-48df-add5-761ca4a8dec0
pull/3969/head
Sebastien Lebreton 1 month ago committed by Siegfried Pammer
parent
commit
076a43671e
  1. 13
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs
  2. 2
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

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

@ -282,6 +282,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -282,6 +282,19 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return ref DefaultInt;
}
public static ref int SwitchRefReturn(int index)
{
switch (index)
{
case 0:
return ref numbers[0];
case 1:
return ref numbers[1];
default:
throw new InvalidOperationException();
}
}
public static ref int LastOrDefault()
{
if (numbers.Length != 0)

2
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -676,6 +676,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -676,6 +676,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// Exactly one of resultVariable/leaveTarget must be null
if ((resultVariable == null) == (leaveTarget == null))
return;
if (resultType == StackType.Ref)
return;
if (switchInst.Value is StringToInt str2int)
{
// validate that each integer is used for exactly one value

Loading…
Cancel
Save