Browse Source

Fix nullability of Extract return type

pull/3444/merge
Daniel Grunwald 2 months ago
parent
commit
7fc9025500
  1. 2
      ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs
  2. 8
      ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs

2
ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

@ -911,7 +911,7 @@ namespace ICSharpCode.Decompiler.IL @@ -911,7 +911,7 @@ namespace ICSharpCode.Decompiler.IL
/// If extraction is not possible, the ILAst is left unmodified and the function returns null.
/// May return null if extraction is not possible.
/// </summary>
public ILVariable Extract(ILTransformContext context)
public ILVariable? Extract(ILTransformContext context)
{
return Transforms.ExtractionContext.Extract(this, context);
}

8
ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs

@ -16,6 +16,8 @@ @@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
@ -97,12 +99,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -97,12 +99,12 @@ namespace ICSharpCode.Decompiler.IL.Transforms
///
/// May return null if extraction is not possible.
/// </summary>
public static ILVariable Extract(ILInstruction instToExtract, ILTransformContext context)
public static ILVariable? Extract(ILInstruction instToExtract, ILTransformContext context)
{
var function = instToExtract.Ancestors.OfType<ILFunction>().First();
ExtractionContext ctx = new ExtractionContext(function, context);
ctx.FlagsBeingMoved = instToExtract.Flags;
ILInstruction inst = instToExtract;
ILInstruction? inst = instToExtract;
while (inst != null)
{
if (inst.Parent is IfInstruction ifInst && inst.SlotInfo != IfInstruction.ConditionSlot)
@ -174,7 +176,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -174,7 +176,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
}
return v;
}
if (!inst.Parent.PrepareExtract(inst.ChildIndex, ctx))
if (inst.Parent != null && !inst.Parent.PrepareExtract(inst.ChildIndex, ctx))
return null;
inst = inst.Parent;
}

Loading…
Cancel
Save