Browse Source

Fixed regression around foreach-on-string introduced in 16134e52e4

pull/2423/head
Siegfried Pammer 4 years ago
parent
commit
ce199fad13
  1. 13
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

13
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Loops.cs

@ -20,6 +20,7 @@ using System; @@ -20,6 +20,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
@ -614,6 +615,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -614,6 +615,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
private static void AppendNamePart(string part, StringBuilder name)
{
foreach (char c in part)
{
if (c == '\\')
{
name.Append('\\');
}
name.Append(c);
}
}
public void NoForeachOverArray(string[] array)
{
for (int i = 0; i < array.Length; i++)

3
ICSharpCode.Decompiler/CSharp/Transforms/PatternStatementTransform.cs

@ -348,10 +348,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -348,10 +348,9 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
var itemVariable = m.Get<IdentifierExpression>("itemVariable").Single().GetILVariable();
var indexVariable = m.Get<IdentifierExpression>("indexVariable").Single().GetILVariable();
var arrayVariable = m.Get<IdentifierExpression>("arrayVariable").Single().GetILVariable();
var loopContainer = forStatement.Annotation<IL.BlockContainer>();
if (itemVariable == null || indexVariable == null || arrayVariable == null)
return null;
if (arrayVariable.Type.Kind != TypeKind.Array)
if (arrayVariable.Type.Kind != TypeKind.Array && !arrayVariable.Type.IsKnownType(KnownTypeCode.String))
return null;
if (!VariableCanBeUsedAsForeachLocal(itemVariable, forStatement))
return null;

Loading…
Cancel
Save