From 4ae41a855e72e86856f4ca9575149b271ca0b536 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Fri, 12 Mar 2021 10:08:09 +0100 Subject: [PATCH] Fix #2321: Missing readonly modifier for ref local --- .../TestCases/Pretty/RefLocalsAndReturns.cs | 12 ++++++++++++ ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs | 2 ++ 2 files changed, 14 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs index ede53e7bc..b631f9b7c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/RefLocalsAndReturns.cs @@ -137,6 +137,13 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Console.WriteLine("No inlining"); Console.WriteLine(field.GetHashCode()); } + + public void RefReadonlyCallVirt(RefLocalsAndReturns provider) + { + ref readonly NormalStruct readonlyRefInstance = ref provider.GetReadonlyRefInstance(); + Console.WriteLine("No inlining"); + readonlyRefInstance.Method(); + } } private static int[] numbers = new int[10] { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023 }; @@ -156,6 +163,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty throw new NotImplementedException(); } + public ref readonly T GetReadonlyRefInstance() + { + throw new NotImplementedException(); + } + public void CallOnRefReturn() { // Both direct calls: diff --git a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs index ca144927e..902907873 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs @@ -459,6 +459,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms return ldloc.Variable.IsRefReadOnly; case Call call: return call.Method.ReturnTypeIsRefReadOnly; + case CallVirt call: + return call.Method.ReturnTypeIsRefReadOnly; case CallIndirect calli: return calli.FunctionPointerType.ReturnIsRefReadOnly; case AddressOf _: