Browse Source

Fix bug in StatementBuilder: do not inline blocks into switch case that are outside of the switchContainer.

pull/887/head
Siegfried Pammer 8 years ago
parent
commit
4c44f05af1
  1. 10
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

10
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -152,7 +152,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -152,7 +152,9 @@ namespace ICSharpCode.Decompiler.CSharp
}
switch (section.Body) {
case Branch br:
caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult);
// we can only inline the block, if all branches are in the switchContainer.
if (br.TargetBlock.IsDescendantOf(switchContainer))
caseLabelMapping.Add(br.TargetBlock, firstValueResolveResult);
break;
default:
break;
@ -164,7 +166,11 @@ namespace ICSharpCode.Decompiler.CSharp @@ -164,7 +166,11 @@ namespace ICSharpCode.Decompiler.CSharp
var astSection = translationDictionary[section];
switch (section.Body) {
case Branch br:
ConvertSwitchSectionBody(astSection, br.TargetBlock);
// we can only inline the block, if all branches are in the switchContainer.
if (br.TargetBlock.IsDescendantOf(switchContainer))
ConvertSwitchSectionBody(astSection, br.TargetBlock);
else
ConvertSwitchSectionBody(astSection, section.Body);
break;
default:
ConvertSwitchSectionBody(astSection, section.Body);

Loading…
Cancel
Save