From 6b3ab663009fe782edc827a60ee76eaf101bd0f4 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 17 Sep 2017 19:42:40 +0200 Subject: [PATCH] Fix ExpectedResultType of main BlockContainer. --- ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs | 1 + ICSharpCode.Decompiler/IL/ILReader.cs | 2 +- ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs | 2 +- ICSharpCode.Decompiler/IL/Instructions/Leave.cs | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs index 385468c82..7b41e7769 100644 --- a/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs +++ b/ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs @@ -95,6 +95,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow TranslateCachedFieldsToLocals(); FinalizeInlineMoveNext(function); + ((BlockContainer)function.Body).ExpectedResultType = underlyingReturnType.GetStackType(); // Re-run control flow simplification over the newly constructed set of gotos, // and inlining because TranslateFieldsToLocalAccess() might have opened up new inlining opportunities. diff --git a/ICSharpCode.Decompiler/IL/ILReader.cs b/ICSharpCode.Decompiler/IL/ILReader.cs index 95430694b..469af50b9 100644 --- a/ICSharpCode.Decompiler/IL/ILReader.cs +++ b/ICSharpCode.Decompiler/IL/ILReader.cs @@ -83,7 +83,7 @@ namespace ICSharpCode.Decompiler.IL v.HasInitialValue = true; } } - mainContainer = new BlockContainer(); + mainContainer = new BlockContainer(methodReturnStackType); this.instructionBuilder = new List(); this.isBranchTarget = new BitArray(body.CodeSize); this.stackByOffset = new Dictionary>(); diff --git a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs index d93df2b46..ead48735b 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/BlockContainer.cs @@ -39,7 +39,7 @@ namespace ICSharpCode.Decompiler.IL public static readonly SlotInfo BlockSlot = new SlotInfo("Block", isCollection: true); public readonly InstructionCollection Blocks; - public StackType ExpectedResultType { get; } + public StackType ExpectedResultType { get; set; } /// /// Gets the number of 'leave' instructions that target this BlockContainer. diff --git a/ICSharpCode.Decompiler/IL/Instructions/Leave.cs b/ICSharpCode.Decompiler/IL/Instructions/Leave.cs index 136ef66aa..56d8091ed 100644 --- a/ICSharpCode.Decompiler/IL/Instructions/Leave.cs +++ b/ICSharpCode.Decompiler/IL/Instructions/Leave.cs @@ -97,6 +97,7 @@ namespace ICSharpCode.Decompiler.IL { base.CheckInvariant(phase); Debug.Assert(phase <= ILPhase.InILReader || this.IsDescendantOf(targetContainer)); + Debug.Assert(phase <= ILPhase.InILReader || value.ResultType == targetContainer.ResultType); } public override void WriteTo(ITextOutput output)