Browse Source

Fix #2342: Do not generate empty names for foreach loop variables.

pull/2345/head
Siegfried Pammer 5 years ago
parent
commit
d60f158dfd
  1. 6
      ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs

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

@ -18,6 +18,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Metadata; using System.Reflection.Metadata;
@ -473,6 +474,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
reservedVariableNames.Add(proposedName, 0); reservedVariableNames.Add(proposedName, 0);
} }
int count = ++reservedVariableNames[proposedName]; int count = ++reservedVariableNames[proposedName];
Debug.Assert(!string.IsNullOrWhiteSpace(proposedName));
if (count > 1) if (count > 1)
{ {
return proposedName + count.ToString(); return proposedName + count.ToString();
@ -763,6 +765,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
reservedVariableNames.Add(proposedName, 0); reservedVariableNames.Add(proposedName, 0);
} }
int count = ++reservedVariableNames[proposedName]; int count = ++reservedVariableNames[proposedName];
Debug.Assert(!string.IsNullOrWhiteSpace(proposedName));
if (count > 1) if (count > 1)
{ {
return proposedName + count.ToString(); return proposedName + count.ToString();
@ -815,6 +818,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
reservedVariableNames.Add(proposedName, 0); reservedVariableNames.Add(proposedName, 0);
} }
int count = ++reservedVariableNames[proposedName]; int count = ++reservedVariableNames[proposedName];
Debug.Assert(!string.IsNullOrWhiteSpace(proposedName));
if (count > 1) if (count > 1)
{ {
return proposedName + count.ToString(); return proposedName + count.ToString();
@ -828,7 +832,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
private static bool IsPlural(string baseName, ref string proposedName) private static bool IsPlural(string baseName, ref string proposedName)
{ {
var newName = Vocabularies.Default.Singularize(baseName, inputIsKnownToBePlural: false); var newName = Vocabularies.Default.Singularize(baseName, inputIsKnownToBePlural: false);
if (newName == baseName) if (string.IsNullOrWhiteSpace(newName) || newName == baseName)
return false; return false;
proposedName = newName; proposedName = newName;
return true; return true;

Loading…
Cancel
Save