Skip to content

Commit 7fc9025

Browse files
committed
Fix nullability of Extract return type
1 parent d4de698 commit 7fc9025

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

ICSharpCode.Decompiler/IL/Instructions/ILInstruction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ protected internal virtual bool PerformMatch(ref ListMatch listMatch, ref Match
911911
/// If extraction is not possible, the ILAst is left unmodified and the function returns null.
912912
/// May return null if extraction is not possible.
913913
/// </summary>
914-
public ILVariable Extract(ILTransformContext context)
914+
public ILVariable? Extract(ILTransformContext context)
915915
{
916916
return Transforms.ExtractionContext.Extract(this, context);
917917
}

ICSharpCode.Decompiler/IL/Transforms/ILExtraction.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1717
// DEALINGS IN THE SOFTWARE.
1818

19+
#nullable enable
20+
1921
using System;
2022
using System.Collections.Generic;
2123
using System.Diagnostics;
@@ -97,12 +99,12 @@ public bool CanReorderWithInstructionsBeingMoved(ILInstruction predecessor)
9799
///
98100
/// May return null if extraction is not possible.
99101
/// </summary>
100-
public static ILVariable Extract(ILInstruction instToExtract, ILTransformContext context)
102+
public static ILVariable? Extract(ILInstruction instToExtract, ILTransformContext context)
101103
{
102104
var function = instToExtract.Ancestors.OfType<ILFunction>().First();
103105
ExtractionContext ctx = new ExtractionContext(function, context);
104106
ctx.FlagsBeingMoved = instToExtract.Flags;
105-
ILInstruction inst = instToExtract;
107+
ILInstruction? inst = instToExtract;
106108
while (inst != null)
107109
{
108110
if (inst.Parent is IfInstruction ifInst && inst.SlotInfo != IfInstruction.ConditionSlot)
@@ -174,7 +176,7 @@ public static ILVariable Extract(ILInstruction instToExtract, ILTransformContext
174176
}
175177
return v;
176178
}
177-
if (!inst.Parent.PrepareExtract(inst.ChildIndex, ctx))
179+
if (inst.Parent != null && !inst.Parent.PrepareExtract(inst.ChildIndex, ctx))
178180
return null;
179181
inst = inst.Parent;
180182
}

0 commit comments

Comments
 (0)