From ab4e05f783671aa012ed75f020d99d2b4ee98bcf Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 9 Jun 2019 16:36:21 +0200 Subject: [PATCH] Don't perform DetectCatchWhenConditionBlocks transform when catchBlock.Variable.Type setter would throw an exception due to differing stack types. --- .../IL/Transforms/DetectCatchWhenConditionBlocks.cs | 6 +++++- .../TypeSystem/Implementation/MinimalCorlib.cs | 5 +++++ ILSpy/LoadedAssembly.cs | 5 +---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs b/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs index 0fdbde1474..2a40c48c2c 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/DetectCatchWhenConditionBlocks.cs @@ -27,7 +27,11 @@ public class DetectCatchWhenConditionBlocks : IILTransform public void Run(ILFunction function, ILTransformContext context) { foreach (var catchBlock in function.Descendants.OfType()) { - if (catchBlock.Filter is BlockContainer container && MatchCatchWhenEntryPoint(catchBlock.Variable, container, container.EntryPoint, out var exceptionType, out var exceptionSlot, out var whenConditionBlock)) { + if (catchBlock.Filter is BlockContainer container + && MatchCatchWhenEntryPoint(catchBlock.Variable, container, container.EntryPoint, + out var exceptionType, out var exceptionSlot, out var whenConditionBlock) + && exceptionType.GetStackType() == catchBlock.Variable.StackType) + { // set exceptionType catchBlock.Variable.Type = exceptionType; // Block entryPoint (incoming: 1) { diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs index e10bc705bb..face71f47e 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs @@ -300,6 +300,11 @@ IType IType.VisitChildren(TypeVisitor visitor) { return this; } + + public override string ToString() + { + return $"[MinimalCorlibType {typeCode}]"; + } } } } diff --git a/ILSpy/LoadedAssembly.cs b/ILSpy/LoadedAssembly.cs index 2a95e3db4e..064c0e8e88 100644 --- a/ILSpy/LoadedAssembly.cs +++ b/ILSpy/LoadedAssembly.cs @@ -26,7 +26,6 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; -using ICSharpCode.Decompiler; using ICSharpCode.Decompiler.DebugInfo; using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.PdbProvider.Cecil; @@ -35,14 +34,12 @@ using ICSharpCode.ILSpy.DebugInfo; using ICSharpCode.ILSpy.Options; -using static System.Reflection.Metadata.PEReaderExtensions; - namespace ICSharpCode.ILSpy { /// /// Represents an assembly loaded into ILSpy. /// - [DebuggerDisplay("LoadedAssembly({shortName})")] + [DebuggerDisplay("[LoadedAssembly {shortName}]")] public sealed class LoadedAssembly { internal static readonly ConditionalWeakTable loadedAssemblies = new ConditionalWeakTable();