Skip to content

Commit 3d74b00

Browse files
Enable nullable for Microsoft.Bcl.AsyncInterfaces (dotnet#70454)
* Enable nullable for Microsoft.Bcl.AsyncInterfaces * Apply suggestions from code review Co-authored-by: Eric Erhardt <[email protected]> Co-authored-by: Eric Erhardt <[email protected]>
1 parent fcbf91d commit 3d74b00

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

src/libraries/Microsoft.Bcl.AsyncInterfaces/ref/Microsoft.Bcl.AsyncInterfaces.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public partial struct ManualResetValueTaskSourceCore<TResult>
8888
public short Version { get { throw null; } }
8989
public TResult GetResult(short token) { throw null; }
9090
public System.Threading.Tasks.Sources.ValueTaskSourceStatus GetStatus(short token) { throw null; }
91-
public void OnCompleted(System.Action<object> continuation, object state, short token, System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags flags) { }
91+
public void OnCompleted(System.Action<object?> continuation, object? state, short token, System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags flags) { }
9292
public void Reset() { }
9393
public void SetException(System.Exception error) { }
9494
public void SetResult(TResult result) { }

src/libraries/Microsoft.Bcl.AsyncInterfaces/ref/Microsoft.Bcl.AsyncInterfaces.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum);netstandard2.1</TargetFrameworks>
4-
<Nullable>disable</Nullable>
54
</PropertyGroup>
65
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.1'">
76
<Compile Include="Microsoft.Bcl.AsyncInterfaces.cs" />

src/libraries/Microsoft.Bcl.AsyncInterfaces/src/Microsoft.Bcl.AsyncInterfaces.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum);netstandard2.1</TargetFrameworks>
4-
<Nullable>disable</Nullable>
54
<IsPackable>true</IsPackable>
65
<!-- This assembly should never be placed inbox as it is only for downlevel compatibility. -->
76
<PackageDescription>Provides the IAsyncEnumerable&lt;T&gt; and IAsyncDisposable interfaces and helper types for .NET Standard 2.0. This package is not required starting with .NET Standard 2.1 and .NET Core 3.0.

src/libraries/Microsoft.Bcl.AsyncInterfaces/src/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,22 @@ public struct ManualResetValueTaskSourceCore<TResult>
2626
/// or <see cref="ManualResetValueTaskSourceCoreShared.s_sentinel"/> if the operation completed before a callback was supplied,
2727
/// or null if a callback hasn't yet been provided and the operation hasn't yet completed.
2828
/// </summary>
29-
private Action<object> _continuation;
29+
private Action<object?>? _continuation;
3030
/// <summary>State to pass to <see cref="_continuation"/>.</summary>
31-
private object _continuationState;
31+
private object? _continuationState;
3232
/// <summary><see cref="ExecutionContext"/> to flow to the callback, or null if no flowing is required.</summary>
33-
private ExecutionContext _executionContext;
33+
private ExecutionContext? _executionContext;
3434
/// <summary>
3535
/// A "captured" <see cref="SynchronizationContext"/> or <see cref="TaskScheduler"/> with which to invoke the callback,
3636
/// or null if no special context is required.
3737
/// </summary>
38-
private object _capturedContext;
38+
private object? _capturedContext;
3939
/// <summary>Whether the current operation has completed.</summary>
4040
private bool _completed;
4141
/// <summary>The result with which the operation succeeded, or the default value if it hasn't yet completed or failed.</summary>
42-
private TResult _result;
42+
private TResult? _result;
4343
/// <summary>The exception with which the operation failed, or null if it hasn't yet completed or completed successfully.</summary>
44-
private ExceptionDispatchInfo _error;
44+
private ExceptionDispatchInfo? _error;
4545
/// <summary>The current version of this value, used to help prevent misuse.</summary>
4646
private short _version;
4747

@@ -105,15 +105,15 @@ public TResult GetResult(short token)
105105
}
106106

107107
_error?.Throw();
108-
return _result;
108+
return _result!;
109109
}
110110

111111
/// <summary>Schedules the continuation action for this operation.</summary>
112112
/// <param name="continuation">The continuation to invoke when the operation has completed.</param>
113113
/// <param name="state">The state object to pass to <paramref name="continuation"/> when it's invoked.</param>
114114
/// <param name="token">Opaque value that was provided to the <see cref="ValueTask"/>'s constructor.</param>
115115
/// <param name="flags">The flags describing the behavior of the continuation.</param>
116-
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
116+
public void OnCompleted(Action<object?> continuation, object? state, short token, ValueTaskSourceOnCompletedFlags flags)
117117
{
118118
if (continuation is null)
119119
{
@@ -128,7 +128,7 @@ public void OnCompleted(Action<object> continuation, object state, short token,
128128

129129
if ((flags & ValueTaskSourceOnCompletedFlags.UseSchedulingContext) != 0)
130130
{
131-
SynchronizationContext sc = SynchronizationContext.Current;
131+
SynchronizationContext? sc = SynchronizationContext.Current;
132132
if (sc != null && sc.GetType() != typeof(SynchronizationContext))
133133
{
134134
_capturedContext = sc;
@@ -151,7 +151,7 @@ public void OnCompleted(Action<object> continuation, object state, short token,
151151
// To minimize the chances of that, we check preemptively whether _continuation
152152
// is already set to something other than the completion sentinel.
153153

154-
object oldContinuation = _continuation;
154+
object? oldContinuation = _continuation;
155155
if (oldContinuation == null)
156156
{
157157
_continuationState = state;
@@ -175,7 +175,7 @@ public void OnCompleted(Action<object> continuation, object state, short token,
175175
case SynchronizationContext sc:
176176
sc.Post(s =>
177177
{
178-
var tuple = (Tuple<Action<object>, object>)s;
178+
var tuple = (Tuple<Action<object?>, object?>)s!;
179179
tuple.Item1(tuple.Item2);
180180
}, Tuple.Create(continuation, state));
181181
break;
@@ -212,7 +212,7 @@ private void SignalCompletion()
212212
{
213213
ExecutionContext.Run(
214214
_executionContext,
215-
s => ((ManualResetValueTaskSourceCore<TResult>)s).InvokeContinuation(),
215+
s => ((ManualResetValueTaskSourceCore<TResult>)s!).InvokeContinuation(),
216216
this);
217217
}
218218
else
@@ -247,7 +247,7 @@ private void InvokeContinuation()
247247
case SynchronizationContext sc:
248248
sc.Post(s =>
249249
{
250-
var state = (Tuple<Action<object>, object>)s;
250+
var state = (Tuple<Action<object?>, object?>)s!;
251251
state.Item1(state.Item2);
252252
}, Tuple.Create(_continuation, _continuationState));
253253
break;
@@ -261,8 +261,8 @@ private void InvokeContinuation()
261261

262262
internal static class ManualResetValueTaskSourceCoreShared // separated out of generic to avoid unnecessary duplication
263263
{
264-
internal static readonly Action<object> s_sentinel = CompletionSentinel;
265-
private static void CompletionSentinel(object _) // named method to aid debugging
264+
internal static readonly Action<object?> s_sentinel = CompletionSentinel;
265+
private static void CompletionSentinel(object? _) // named method to aid debugging
266266
{
267267
Debug.Fail("The sentinel delegate should never be invoked.");
268268
throw new InvalidOperationException();

0 commit comments

Comments
 (0)