Skip to content

Commit a65921c

Browse files
authored
Nullable: System.Runtime.CompilerServices (dotnet#23886)
1 parent bc69ecd commit a65921c

27 files changed

+109
-90
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Runtime.InteropServices;
67
using System.Threading;
7-
using System.Threading.Tasks;
88

99
namespace System.Runtime.CompilerServices
1010
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
namespace System.Runtime.CompilerServices
67
{
78
/// <summary>Indicates whether a method is an asynchronous iterator.</summary>

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

Lines changed: 45 additions & 43 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
namespace System.Runtime.CompilerServices
67
{
78
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Runtime.InteropServices;
67
using System.Security;
78
using System.Threading.Tasks;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
namespace System.Runtime.CompilerServices
67
{
78
/// IMPORTANT: Keep this in sync with corhdr.h
@@ -12,4 +13,4 @@ public enum CompilationRelaxations : int
1213
// so we'll start here just in case somebody used them. This flag is only
1314
// valid when set for Assemblies.
1415
}
15-
}
16+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Runtime.InteropServices;
67

78
namespace System.Runtime.CompilerServices

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Collections.Generic;
67
using System.Runtime.InteropServices;
78
using System.Threading;

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
#nullable enable
56
using System.Diagnostics;
67
using System.Runtime.InteropServices;
78
using System.Threading;
@@ -57,7 +58,7 @@ public bool IsCompleted
5758
/// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
5859
public void OnCompleted(Action continuation)
5960
{
60-
object obj = _value._obj;
61+
object? obj = _value._obj;
6162
Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
6263

6364
if (obj is Task t)
@@ -79,7 +80,7 @@ public void OnCompleted(Action continuation)
7980
/// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
8081
public void UnsafeOnCompleted(Action continuation)
8182
{
82-
object obj = _value._obj;
83+
object? obj = _value._obj;
8384
Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
8485

8586
if (obj is Task t)
@@ -99,7 +100,7 @@ public void UnsafeOnCompleted(Action continuation)
99100

100101
void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
101102
{
102-
object obj = _value._obj;
103+
object? obj = _value._obj;
103104
Debug.Assert(obj == null || obj is Task || obj is IValueTaskSource);
104105

105106
if (obj is Task t)
@@ -163,7 +164,7 @@ public bool IsCompleted
163164
/// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
164165
public void OnCompleted(Action continuation)
165166
{
166-
object obj = _value._obj;
167+
object? obj = _value._obj;
167168
Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
168169

169170
if (obj is Task<TResult> t)
@@ -185,7 +186,7 @@ public void OnCompleted(Action continuation)
185186
/// <summary>Schedules the continuation action for the <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
186187
public void UnsafeOnCompleted(Action continuation)
187188
{
188-
object obj = _value._obj;
189+
object? obj = _value._obj;
189190
Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
190191

191192
if (obj is Task<TResult> t)
@@ -205,7 +206,7 @@ public void UnsafeOnCompleted(Action continuation)
205206

206207
void IStateMachineBoxAwareAwaiter.AwaitUnsafeOnCompleted(IAsyncStateMachineBox box)
207208
{
208-
object obj = _value._obj;
209+
object? obj = _value._obj;
209210
Debug.Assert(obj == null || obj is Task<TResult> || obj is IValueTaskSource<TResult>);
210211

211212
if (obj is Task<TResult> t)

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#define DEBUG // The behavior of this contract library should be consistent regardless of build type.
66

7-
using System.Diagnostics;
7+
#nullable enable
88
using System.Diagnostics.Contracts;
99

1010
namespace System.Runtime.CompilerServices
@@ -31,14 +31,14 @@ public static class ContractHelper
3131
/// Otherwise, returns the localized failure message.
3232
/// </summary>
3333
[System.Diagnostics.DebuggerNonUserCode]
34-
public static string RaiseContractFailedEvent(ContractFailureKind failureKind, string userMessage, string conditionText, Exception innerException)
34+
public static string? RaiseContractFailedEvent(ContractFailureKind failureKind, string? userMessage, string? conditionText, Exception? innerException)
3535
{
3636
if (failureKind < ContractFailureKind.Precondition || failureKind > ContractFailureKind.Assume)
3737
throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, failureKind), nameof(failureKind));
3838

39-
string returnValue;
39+
string? returnValue;
4040
string displayMessage = "contract failed."; // Incomplete, but in case of OOM during resource lookup...
41-
ContractFailedEventArgs eventArgs = null; // In case of OOM.
41+
ContractFailedEventArgs? eventArgs = null; // In case of OOM.
4242

4343
try
4444
{
@@ -78,14 +78,15 @@ public static string RaiseContractFailedEvent(ContractFailureKind failureKind, s
7878
returnValue = displayMessage;
7979
}
8080
}
81+
8182
return returnValue;
8283
}
8384

8485
/// <summary>
8586
/// Rewriter calls this method to get the default failure behavior.
8687
/// </summary>
8788
[System.Diagnostics.DebuggerNonUserCode]
88-
public static void TriggerFailure(ContractFailureKind kind, string displayMessage, string userMessage, string conditionText, Exception innerException)
89+
public static void TriggerFailure(ContractFailureKind kind, string? displayMessage, string? userMessage, string? conditionText, Exception? innerException)
8990
{
9091
if (string.IsNullOrEmpty(displayMessage))
9192
{
@@ -95,7 +96,7 @@ public static void TriggerFailure(ContractFailureKind kind, string displayMessag
9596
System.Diagnostics.Debug.ContractFailure(displayMessage, string.Empty, GetFailureMessage(kind, null));
9697
}
9798

98-
private static string GetFailureMessage(ContractFailureKind failureKind, string conditionText)
99+
private static string GetFailureMessage(ContractFailureKind failureKind, string? conditionText)
99100
{
100101
bool hasConditionText = !string.IsNullOrEmpty(conditionText);
101102
switch (failureKind)
@@ -124,7 +125,7 @@ private static string GetFailureMessage(ContractFailureKind failureKind, string
124125
}
125126
}
126127

127-
private static string GetDisplayMessage(ContractFailureKind failureKind, string userMessage, string conditionText)
128+
private static string GetDisplayMessage(ContractFailureKind failureKind, string? userMessage, string? conditionText)
128129
{
129130
string failureMessage;
130131
// Well-formatted English messages will take one of four forms. A sentence ending in

0 commit comments

Comments
 (0)