Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b1034fb

Browse files
safernwtgodbe
authored andcommitted
React to new compiler nullability warnings
1 parent 270a666 commit b1034fb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,13 @@ private static void ExecutionContextCallback(object? s)
570570
{
571571
Debug.Assert(s is AsyncStateMachineBox<TStateMachine>);
572572
// Only used privately to pass directly to EC.Run
573-
Unsafe.As<AsyncStateMachineBox<TStateMachine>>(s).StateMachine.MoveNext();
573+
Unsafe.As<AsyncStateMachineBox<TStateMachine>>(s).StateMachine!.MoveNext();
574574
}
575575

576576
/// <summary>A delegate to the <see cref="MoveNext()"/> method.</summary>
577577
private Action? _moveNextAction;
578578
/// <summary>The state machine itself.</summary>
579-
[AllowNull, MaybeNull] public TStateMachine StateMachine = default!; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. // TODO-NULLABLE: Remove ! when nullable attributes are respected
579+
[AllowNull, MaybeNull] public TStateMachine StateMachine = default; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name.
580580
/// <summary>Captured ExecutionContext with which to invoke <see cref="MoveNextAction"/>; may be null.</summary>
581581
public ExecutionContext? Context;
582582

@@ -601,7 +601,8 @@ private void MoveNext(Thread? threadPoolThread)
601601
ExecutionContext? context = Context;
602602
if (context == null)
603603
{
604-
StateMachine.MoveNext();
604+
Debug.Assert(StateMachine != null);
605+
StateMachine!.MoveNext(); // TODO-NULLABLE: remove ! when Debug.Assert on fields is respected (https://github.com/dotnet/roslyn/issues/36830)
605606
}
606607
else
607608
{
@@ -620,7 +621,7 @@ private void MoveNext(Thread? threadPoolThread)
620621
// Clear out state now that the async method has completed.
621622
// This avoids keeping arbitrary state referenced by lifted locals
622623
// if this Task / state machine box is held onto.
623-
StateMachine = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
624+
StateMachine = default;
624625
Context = default;
625626

626627
#if !CORERT
@@ -641,7 +642,7 @@ private void MoveNext(Thread? threadPoolThread)
641642
}
642643

643644
/// <summary>Gets the state machine as a boxed object. This should only be used for debugging purposes.</summary>
644-
IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine; // likely boxes, only use for debugging
645+
IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine!; // likely boxes, only use for debugging
645646
}
646647

647648
/// <summary>Gets the <see cref="System.Threading.Tasks.Task{TResult}"/> for this builder.</summary>

src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,14 +1260,15 @@ internal static void CompleteFromAsyncResult(IAsyncResult asyncResult)
12601260
// Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily
12611261
var thisRef = promise!.m_thisRef; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
12621262
var endMethod = promise.m_endMethod;
1263-
promise.m_thisRef = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
1263+
promise.m_thisRef = default;
12641264
promise.m_endMethod = null;
12651265
if (endMethod == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult);
12661266

12671267
// Complete the promise. If the IAsyncResult completed synchronously,
12681268
// we'll instead complete the promise at the call site.
12691269
if (!asyncResult.CompletedSynchronously)
12701270
{
1271+
Debug.Assert(thisRef != null);
12711272
promise.Complete(thisRef, endMethod!, asyncResult, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected
12721273
}
12731274
}

0 commit comments

Comments
 (0)