Browse Source

Relax foreach transform to allow stack slots as foreach-variable again.

pull/1612/head
Daniel Grunwald 6 years ago
parent
commit
0a54a93be0
  1. 4
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

4
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -709,15 +709,13 @@ namespace ICSharpCode.Decompiler.CSharp @@ -709,15 +709,13 @@ namespace ICSharpCode.Decompiler.CSharp
while (inst.Parent is UnboxAny || inst.Parent is CastClass)
inst = inst.Parent;
// One variable was found.
if (inst.Parent is StLoc stloc) {
if (inst.Parent is StLoc stloc && (stloc.Variable.Kind == VariableKind.Local || stloc.Variable.Kind == VariableKind.StackSlot)) {
// Must be a plain assignment expression and variable must only be used in 'body' + only assigned once.
if (stloc.Parent == loopBody && VariableIsOnlyUsedInBlock(stloc, usingContainer)) {
foreachVariable = stloc.Variable;
if (foreachVariable.Kind == VariableKind.Local) {
return RequiredGetCurrentTransformation.UseExistingVariable;
}
}
}
// In optimized Roslyn code it can happen that the foreach variable is referenced via addressof
// We only do this unwrapping if where dealing with a custom struct type.
if (CurrentIsStructSetterTarget(inst, singleGetter)) {

Loading…
Cancel
Save