diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs index 0a76c7b48..166db754e 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs @@ -480,8 +480,14 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public void ForEachOverListOfStruct(List items, int value) { foreach (DataItem item in items) { +#if ROSLYN && OPT + // The variable name differs based on whether roslyn optimizes out the 'item' variable + DataItem current = item; + current.Property = value; +#else DataItem dataItem = item; dataItem.Property = value; +#endif } } @@ -671,7 +677,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty } //other configurations work fine, just with different labels -#if OPT && !MCS +#if OPT && !MCS public void WhileWithGoto() { while (Condition("Main Loop")) { diff --git a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs index 6ad799321..a51ebf7a2 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ILInlining.cs @@ -19,6 +19,7 @@ using System; using System.Diagnostics; using System.Linq; +using System.Reflection; using ICSharpCode.Decompiler.TypeSystem; namespace ICSharpCode.Decompiler.IL.Transforms @@ -275,7 +276,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms switch (ldloca.Parent.OpCode) { case OpCode.Call: case OpCode.CallVirt: - return !((CallInstruction)ldloca.Parent).Method.IsStatic; + var method = ((CallInstruction)ldloca.Parent).Method; + if (method.IsAccessor && method.AccessorKind != MethodSemanticsAttributes.Getter) { + // C# doesn't allow calling setters on temporary structs + return false; + } + return !method.IsStatic; case OpCode.Await: return true; default: