diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs index 393fa9374..c975fa00a 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Correctness/InitializerTests.cs @@ -1015,5 +1015,35 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness } }; } + + class Issue855 + { + class Data + { + public object Obj; + } + + class Items + { + public void SetItem(int i, object item) { } + } + + object Item(string s, Data d) + { + return new object(); + } + + void Test() + { + Items items = null; + + int num = 0; + + for (int i = 0; i < 2; i++) { + if (num < 10) + items.SetItem(num, Item(string.Empty, new Data { Obj = null })); + } + } + } } } \ No newline at end of file diff --git a/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs index cbc06bbb3..1aa31130d 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/LockTransform.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms // This happens in some cases: // Use correct index after transformation. if (i >= block.Instructions.Count) - i = block.Instructions.Count - 1; + i = block.Instructions.Count; } } diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index 6b28ac2f5..3e6f175f2 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -36,6 +36,10 @@ namespace ICSharpCode.Decompiler.IL.Transforms for (int i = block.Instructions.Count - 1; i >= 0; i--) { DoTransform(block, i); + // This happens in some cases: + // Use correct index after transformation. + if (i >= block.Instructions.Count) + i = block.Instructions.Count; } }