From 6d8d37f8fce192d30e9e9ce00f661e3b6ac9cd2d Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 4 Nov 2017 19:03:41 +0100 Subject: [PATCH] Add ValueTypeCall foreach testcase. --- .../TestCases/Correctness/ValueTypeCall.cs | 38 +++++++++++++++++++ .../IL/Transforms/SplitVariables.cs | 1 - 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs index 72dbb9101..5a8ad0bd6 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/ValueTypeCall.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness { @@ -59,6 +60,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness var gvt = new GenericValueType("Test"); gvt.Call(ref gvt); new ValueTypeCall().InstanceFieldTests(); + ForEach(); } static void RefParameter(ref MutValueType m) @@ -153,5 +155,41 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness z.Increment(); } } + + static void ForEach() + { + var list = new List { + new MutValueType { val = 10 }, + new MutValueType { val = 20 }, + new MutValueType { val = 30 }, + }; + ForEach1(list); + var array = new MutValueType[] { + new MutValueType { val = 100 }, + new MutValueType { val = 200 }, + new MutValueType { val = 300 }, + }; + ForEachArray1(array); + } + + static void ForEach1(List list) + { + Console.WriteLine("ForEach1:"); + foreach (var val in list) { + val.Increment(); + val.Increment(); + } + Console.WriteLine("after: " + list[0].val); + } + + static void ForEachArray1(MutValueType[] list) + { + Console.WriteLine("ForEachArray1:"); + foreach (var val in list) { + val.Increment(); + val.Increment(); + } + Console.WriteLine("after: " + list[0].val); + } } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs b/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs index da89fb969..e45a7a593 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/SplitVariables.cs @@ -33,7 +33,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms { var groupStores = new GroupStores(function, context.CancellationToken); function.Body.AcceptVisitor(groupStores); - var newVariables = new Dictionary(); // Replace analyzed variables with their split versions: foreach (var inst in function.Descendants.OfType()) { if (groupStores.IsAnalyzedVariable(inst.Variable)) {