From: Santiago Fernandez Madero Date: Thu, 27 Jun 2019 17:39:13 +0000 (-0700) Subject: React to new compiler nullability warnings X-Git-Tag: accepted/tizen/unified/20191011.080124~150^2~116^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5ccdc3d9b9c8f6020e9c458e19a8504eb845910;p=platform%2Fupstream%2Fcoreclr.git React to new compiler nullability warnings --- diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index d08753a..fd66c18 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -570,13 +570,13 @@ namespace System.Runtime.CompilerServices { Debug.Assert(s is AsyncStateMachineBox); // Only used privately to pass directly to EC.Run - Unsafe.As>(s).StateMachine.MoveNext(); + Unsafe.As>(s).StateMachine!.MoveNext(); } /// A delegate to the method. private Action? _moveNextAction; /// The state machine itself. - [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 + [AllowNull, MaybeNull] public TStateMachine StateMachine = default; // mutable struct; do not make this readonly. SOS DumpAsync command depends on this name. /// Captured ExecutionContext with which to invoke ; may be null. public ExecutionContext? Context; @@ -601,7 +601,8 @@ namespace System.Runtime.CompilerServices ExecutionContext? context = Context; if (context == null) { - StateMachine.MoveNext(); + Debug.Assert(StateMachine != null); + StateMachine!.MoveNext(); // TODO-NULLABLE: remove ! when Debug.Assert on fields is respected (https://github.com/dotnet/roslyn/issues/36830) } else { @@ -620,7 +621,7 @@ namespace System.Runtime.CompilerServices // Clear out state now that the async method has completed. // This avoids keeping arbitrary state referenced by lifted locals // if this Task / state machine box is held onto. - StateMachine = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected + StateMachine = default; Context = default; #if !CORERT @@ -641,7 +642,7 @@ namespace System.Runtime.CompilerServices } /// Gets the state machine as a boxed object. This should only be used for debugging purposes. - IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine; // likely boxes, only use for debugging + IAsyncStateMachine IAsyncStateMachineBox.GetStateMachineObject() => StateMachine!; // likely boxes, only use for debugging } /// Gets the for this builder. diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs index a7de15a..6464676 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs @@ -1260,7 +1260,7 @@ namespace System.Threading.Tasks // Grab the relevant state and then null it out so that the task doesn't hold onto the state unnecessarily var thisRef = promise!.m_thisRef; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected var endMethod = promise.m_endMethod; - promise.m_thisRef = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected + promise.m_thisRef = default; promise.m_endMethod = null; if (endMethod == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult); @@ -1268,6 +1268,7 @@ namespace System.Threading.Tasks // we'll instead complete the promise at the call site. if (!asyncResult.CompletedSynchronously) { + Debug.Assert(thisRef != null); promise.Complete(thisRef, endMethod!, asyncResult, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected } }