Browse Source

Fix #3272: Missing variable declarations in repeated nested for-loops

pull/3280/head
Siegfried Pammer 8 months ago
parent
commit
58e993d71d
  1. 2
      ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs
  2. 28
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/VariableNaming.cs
  3. 2
      ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs

2
ICSharpCode.Decompiler.Tests/PrettyTestRunner.cs

@ -736,7 +736,7 @@ namespace ICSharpCode.Decompiler.Tests @@ -736,7 +736,7 @@ namespace ICSharpCode.Decompiler.Tests
var decompiled = await Tester.DecompileCSharp(exeFile, decompilerSettings ?? Tester.GetSettings(cscOptions)).ConfigureAwait(false);
// 3. Compile
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).ToArray());
CodeAssert.FilesAreEqual(csFile, decompiled, Tester.GetPreprocessorSymbols(cscOptions).Append("EXPECTED_OUTPUT").ToArray());
Tester.RepeatOnIOError(() => File.Delete(decompiled));
}
}

28
ICSharpCode.Decompiler.Tests/TestCases/Pretty/VariableNaming.cs

@ -60,5 +60,33 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -60,5 +60,33 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
#pragma warning restore CS0219
}
#endif
private static void NestedForLoopTest(int sizeX, int sizeY, int[] array)
{
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
array[y * sizeX + x] = 0;
}
}
#if !EXPECTED_OUTPUT || (LEGACY_CSC && !OPT)
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
array[y * sizeX + x] = 1;
}
}
#else
for (int i = 0; i < sizeY; i++)
{
for (int j = 0; j < sizeX; j++)
{
array[i * sizeX + j] = 1;
}
}
#endif
}
}
}

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

@ -295,6 +295,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -295,6 +295,8 @@ namespace ICSharpCode.Decompiler.IL.Transforms
// special case for loop counters,
// we don't want them to be named i, i2, ..., but i, j, ...
newName = GenerateNameForVariable(v);
nameWithoutNumber = newName;
newIndex = 1;
}
else
{

Loading…
Cancel
Save