diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs index a1fca3d89..72a741b28 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/SwitchDetection.cs @@ -158,13 +158,13 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow void ProcessBlock(Block block, ref bool blockContainerNeedsCleanup) { bool analysisSuccess = analysis.AnalyzeBlock(block); - KeyValuePair defaultSection; - if (analysisSuccess && UseCSharpSwitch(out defaultSection)) { + if (analysisSuccess && UseCSharpSwitch(out _)) { // complex multi-block switch that can be combined into a single SwitchInstruction ILInstruction switchValue = new LdLoc(analysis.SwitchVariable); - if (switchValue.ResultType == StackType.Unknown) { + Debug.Assert(switchValue.ResultType.IsIntegerType() || switchValue.ResultType == StackType.Unknown); + if (!(switchValue.ResultType == StackType.I4 || switchValue.ResultType == StackType.I8)) { // switchValue must have a result type of either I4 or I8 - switchValue = new Conv(switchValue, PrimitiveType.I8, false, TypeSystem.Sign.Signed); + switchValue = new Conv(switchValue, PrimitiveType.I8, false, Sign.Signed); } var sw = new SwitchInstruction(switchValue); foreach (var section in analysis.Sections) { diff --git a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs index 8578de0bd..9ff31840e 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs @@ -62,6 +62,17 @@ namespace ICSharpCode.Decompiler.IL.Transforms } } + protected internal override void VisitBlockContainer(BlockContainer container) + { + if (container.Kind == ContainerKind.Switch) { + // Special case for switch: Only visit the switch condition block. + var switchInst = (SwitchInstruction)container.EntryPoint.Instructions[0]; + switchInst.Value.AcceptVisitor(this); + return; + } + base.VisitBlockContainer(container); + } + protected internal override void VisitBlock(Block block) { if (block.Kind == BlockKind.ControlFlow) {