diff options
author | Stephen Toub <stoub@microsoft.com> | 2019-07-17 13:01:37 -0400 |
---|---|---|
committer | Stephen Toub <stoub@microsoft.com> | 2019-07-18 14:25:53 -0400 |
commit | f9d0787a1aa181651cd2362bb20d2ccbf5de5a69 (patch) | |
tree | 189911f53d045d61f6afafdeb04debafef34cf62 /src/System.Private.CoreLib | |
parent | 3c0368e2854e969c20e96984d9978f3d7f7a18a2 (diff) | |
download | coreclr-f9d0787a1aa181651cd2362bb20d2ccbf5de5a69.tar.gz coreclr-f9d0787a1aa181651cd2362bb20d2ccbf5de5a69.tar.bz2 coreclr-f9d0787a1aa181651cd2362bb20d2ccbf5de5a69.zip |
Remove now unnecessary !s / TODO-NULLABLE comments (#25749)
* Remove !s and TODO-NULLABLE comments for [DoesNotReturn]
* Remove !s and TODO-NULLABLE comments for [NotNullIfNotNull]
* Remove !s and TODO-NULLABLE comments for writes via Interlocked.CompareExchange
* Remove !s and TODO-NULLABLE comments for Debug.Assert on fields
* Update/add several TODO-NULLABLE comments
Diffstat (limited to 'src/System.Private.CoreLib')
60 files changed, 312 insertions, 312 deletions
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs index b1589acff2..0e7519d42f 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs @@ -33,7 +33,7 @@ internal partial class Interop int dwFlagsAndAttributes, IntPtr hTemplateFile) { - lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName); return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); } } diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs index 82d62cc4d3..323de99c2a 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs @@ -26,7 +26,7 @@ internal partial class Interop FileMode dwCreationDisposition, ref Kernel32.CREATEFILE2_EXTENDED_PARAMETERS pCreateExParams) { - lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName); return CreateFile2Private(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, ref pCreateExParams); } } diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs index 7d5203d44f..bb1ddf7857 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs @@ -21,7 +21,7 @@ internal partial class Interop internal static SafeFindHandle FindFirstFile(string fileName, ref WIN32_FIND_DATA data) { - fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName); // use FindExInfoBasic since we don't care about short name and it has better perf return FindFirstFileExPrivate(fileName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0); diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs index 65649e497d..ee2370038f 100644 --- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs +++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs @@ -21,7 +21,7 @@ internal partial class Interop internal static bool GetFileAttributesEx(string name, GET_FILEEX_INFO_LEVELS fileInfoLevel, ref WIN32_FILE_ATTRIBUTE_DATA lpFileInformation) { - name = PathInternal.EnsureExtendedPrefixIfNeeded(name)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + name = PathInternal.EnsureExtendedPrefixIfNeeded(name); return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation); } } diff --git a/src/System.Private.CoreLib/shared/System/AppContext.cs b/src/System.Private.CoreLib/shared/System/AppContext.cs index 8601d3f26b..605326ca1f 100644 --- a/src/System.Private.CoreLib/shared/System/AppContext.cs +++ b/src/System.Private.CoreLib/shared/System/AppContext.cs @@ -63,12 +63,12 @@ namespace System } #pragma warning disable CS0067 // events raised by the VM - public static event UnhandledExceptionEventHandler UnhandledException; + public static event UnhandledExceptionEventHandler UnhandledException; // TODO-NULLABLE: Should all events use nullable delegate types? - public static event System.EventHandler<FirstChanceExceptionEventArgs> FirstChanceException; + public static event System.EventHandler<FirstChanceExceptionEventArgs> FirstChanceException; // TODO-NULLABLE: Should all events use nullable delegate types? #pragma warning restore CS0067 - public static event System.EventHandler ProcessExit; + public static event System.EventHandler ProcessExit; // TODO-NULLABLE: Should all events use nullable delegate types? internal static void OnProcessExit() { @@ -126,7 +126,7 @@ namespace System Interlocked.CompareExchange(ref s_switches, new Dictionary<string, bool>(), null); } - lock (s_switches!) // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + lock (s_switches) { s_switches[switchName] = isEnabled; } diff --git a/src/System.Private.CoreLib/shared/System/AppDomain.cs b/src/System.Private.CoreLib/shared/System/AppDomain.cs index d48d34922f..6795e556f3 100644 --- a/src/System.Private.CoreLib/shared/System/AppDomain.cs +++ b/src/System.Private.CoreLib/shared/System/AppDomain.cs @@ -41,7 +41,7 @@ namespace System public PermissionSet PermissionSet => new PermissionSet(PermissionState.Unrestricted); - public event UnhandledExceptionEventHandler UnhandledException + public event UnhandledExceptionEventHandler UnhandledException // TODO-NULLABLE: Should all events use nullable delegate types? { add { AppContext.UnhandledException += value; } remove { AppContext.UnhandledException -= value; } @@ -67,15 +67,15 @@ namespace System public bool IsHomogenous => true; - public event EventHandler DomainUnload = null!; + public event EventHandler DomainUnload = null!; // TODO-NULLABLE: Should all events use nullable delegate types? - public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException + public event EventHandler<FirstChanceExceptionEventArgs> FirstChanceException // TODO-NULLABLE: Should all events use nullable delegate types? { add { AppContext.FirstChanceException += value; } remove { AppContext.FirstChanceException -= value; } } - public event EventHandler ProcessExit + public event EventHandler ProcessExit // TODO-NULLABLE: Should all events use nullable delegate types? { add { AppContext.ProcessExit += value; } remove { AppContext.ProcessExit -= value; } @@ -232,27 +232,27 @@ namespace System public Assembly[] GetAssemblies() => AssemblyLoadContext.GetLoadedAssemblies(); - public event AssemblyLoadEventHandler AssemblyLoad + public event AssemblyLoadEventHandler AssemblyLoad // TODO-NULLABLE: Should all events use nullable delegate types? { add { AssemblyLoadContext.AssemblyLoad += value; } remove { AssemblyLoadContext.AssemblyLoad -= value; } } - public event ResolveEventHandler AssemblyResolve + public event ResolveEventHandler AssemblyResolve // TODO-NULLABLE: Should all events use nullable delegate types? { add { AssemblyLoadContext.AssemblyResolve += value; } remove { AssemblyLoadContext.AssemblyResolve -= value; } } - public event ResolveEventHandler ReflectionOnlyAssemblyResolve = null!; + public event ResolveEventHandler ReflectionOnlyAssemblyResolve = null!; // TODO-NULLABLE: Should all events use nullable delegate types? - public event ResolveEventHandler TypeResolve + public event ResolveEventHandler TypeResolve // TODO-NULLABLE: Should all events use nullable delegate types? { add { AssemblyLoadContext.TypeResolve += value; } remove { AssemblyLoadContext.TypeResolve -= value; } } - public event ResolveEventHandler ResourceResolve + public event ResolveEventHandler ResourceResolve // TODO-NULLABLE: Should all events use nullable delegate types? { add { AssemblyLoadContext.ResourceResolve += value; } remove { AssemblyLoadContext.ResourceResolve -= value; } @@ -409,7 +409,7 @@ namespace System (Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>))); } - principal = s_getUnauthenticatedPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + principal = s_getUnauthenticatedPrincipal(); break; case PrincipalPolicy.WindowsPrincipal: @@ -425,7 +425,7 @@ namespace System (Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>))); } - principal = s_getWindowsPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + principal = s_getWindowsPrincipal(); break; } } diff --git a/src/System.Private.CoreLib/shared/System/Array.cs b/src/System.Private.CoreLib/shared/System/Array.cs index 11479d88e2..0613abeb0e 100644 --- a/src/System.Private.CoreLib/shared/System/Array.cs +++ b/src/System.Private.CoreLib/shared/System/Array.cs @@ -37,7 +37,7 @@ namespace System } // T[] implements IList<T>. - return new ReadOnlyCollection<T>(array!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return new ReadOnlyCollection<T>(array); } public static void Resize<T>([NotNull] ref T[]? array, int newSize) @@ -66,7 +66,7 @@ namespace System { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths); } - if (lengths!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (lengths.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank); int[] intLengths = new int[lengths.Length]; @@ -150,7 +150,7 @@ namespace System { if (indices == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); - if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (Rank != indices.Length) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); int[] intIndices = new int[indices.Length]; @@ -210,7 +210,7 @@ namespace System { if (indices == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); - if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (Rank != indices.Length) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); int[] intIndices = new int[indices.Length]; @@ -325,7 +325,7 @@ namespace System int i = 0; int c = 0; - while (i < o!.Length && c == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + while (i < o.Length && c == 0) { object? left = GetValue(i); object? right = o.GetValue(i); @@ -384,7 +384,7 @@ namespace System for (int i = (this.Length >= 8 ? this.Length - 8 : 0); i < this.Length; i++) { - ret = CombineHashCodes(ret, comparer!.GetHashCode(GetValue(i)!)); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ret = CombineHashCodes(ret, comparer.GetHashCode(GetValue(i)!)); } return ret; @@ -407,7 +407,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - return BinarySearch(array!, array!.GetLowerBound(0), array.Length, value, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return BinarySearch(array, array.GetLowerBound(0), array.Length, value, null); } // Searches a section of an array for a given element using a binary search @@ -446,7 +446,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - return BinarySearch(array!, array!.GetLowerBound(0), array.Length, value, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return BinarySearch(array, array.GetLowerBound(0), array.Length, value, comparer); } // Searches a section of an array for a given element using a binary search @@ -468,7 +468,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int lb = array.GetLowerBound(0); if (index < lb) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) @@ -553,14 +553,14 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - return BinarySearch<T>(array!, 0, array!.Length, value, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return BinarySearch<T>(array, 0, array.Length, value, null); } public static int BinarySearch<T>(T[] array, T value, System.Collections.Generic.IComparer<T>? comparer) { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - return BinarySearch<T>(array!, 0, array!.Length, value, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return BinarySearch<T>(array, 0, array.Length, value, comparer); } public static int BinarySearch<T>(T[] array, int index, int length, T value) @@ -577,7 +577,7 @@ namespace System if (length < 0) ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); - if (array!.Length - index < length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Length - index < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); return ArraySortHelper<T>.Default.BinarySearch(array, index, length, value, comparer); @@ -595,10 +595,10 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.converter); } - TOutput[] newArray = new TOutput[array!.Length]; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + TOutput[] newArray = new TOutput[array.Length]; for (int i = 0; i < array.Length; i++) { - newArray[i] = converter!(array[i]); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + newArray[i] = converter(array[i]); } return newArray; } @@ -615,7 +615,7 @@ namespace System if (array != null && array.Rank != 1) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); // Note: Array.Copy throws a RankException and we want a consistent ArgumentException for all the IList CopyTo methods. - Array.Copy(this, GetLowerBound(0), array!, index, Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Array.Copy(this, GetLowerBound(0), array!, index, Length); } public void CopyTo(Array array, long index) @@ -649,7 +649,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = 0; i < array.Length; i++) { array[i] = value; } @@ -662,19 +662,19 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (startIndex < 0 || startIndex > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (startIndex < 0 || startIndex > array.Length) { ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } - if (count < 0 || startIndex > array!.Length - count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (count < 0 || startIndex > array.Length - count) { ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } for (int i = startIndex; i < startIndex + count; i++) { - array![i] = value; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + array[i] = value; } } @@ -691,9 +691,9 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } - for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = 0; i < array.Length; i++) { - if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match(array[i])) { return array[i]; } @@ -714,9 +714,9 @@ namespace System } List<T> list = new List<T>(); - for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = 0; i < array.Length; i++) { - if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match(array[i])) { list.Add(array[i]); } @@ -731,7 +731,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return FindIndex(array!, 0, array!.Length, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return FindIndex(array, 0, array.Length, match); } public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match) @@ -741,7 +741,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return FindIndex(array!, startIndex, array!.Length - startIndex, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return FindIndex(array, startIndex, array.Length - startIndex, match); } public static int FindIndex<T>(T[] array, int startIndex, int count, Predicate<T> match) @@ -751,12 +751,12 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (startIndex < 0 || startIndex > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (startIndex < 0 || startIndex > array.Length) { ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } - if (count < 0 || startIndex > array!.Length - count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (count < 0 || startIndex > array.Length - count) { ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(); } @@ -769,7 +769,7 @@ namespace System int endIndex = startIndex + count; for (int i = startIndex; i < endIndex; i++) { - if (match!(array![i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match!(array[i])) return i; } return -1; @@ -788,9 +788,9 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } - for (int i = array!.Length - 1; i >= 0; i--) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = array.Length - 1; i >= 0; i--) { - if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match(array[i])) { return array[i]; } @@ -805,7 +805,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return FindLastIndex(array!, array!.Length - 1, array.Length, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return FindLastIndex(array, array.Length - 1, array.Length, match); } public static int FindLastIndex<T>(T[] array, int startIndex, Predicate<T> match) @@ -815,7 +815,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return FindLastIndex(array!, startIndex, startIndex + 1, match); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return FindLastIndex(array, startIndex, startIndex + 1, match); } public static int FindLastIndex<T>(T[] array, int startIndex, int count, Predicate<T> match) @@ -830,7 +830,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } - if (array!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Length == 0) { // Special case for 0 length List if (startIndex != -1) @@ -856,7 +856,7 @@ namespace System int endIndex = startIndex - count; for (int i = startIndex; i > endIndex; i--) { - if (match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match(array[i])) { return i; } @@ -876,9 +876,9 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.action); } - for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = 0; i < array.Length; i++) { - action!(array[i]); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + action(array[i]); } } @@ -890,7 +890,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - return IndexOf(array!, value, array!.GetLowerBound(0), array.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return IndexOf(array, value, array.GetLowerBound(0), array.Length); } // Returns the index of the first occurrence of a given value in a range of @@ -903,7 +903,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int lb = array.GetLowerBound(0); return IndexOf(array, value, startIndex, array.Length - startIndex + lb); } @@ -917,7 +917,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported); int lb = array.GetLowerBound(0); @@ -987,7 +987,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return IndexOf(array!, value, 0, array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return IndexOf(array, value, 0, array.Length); } public static int IndexOf<T>(T[] array, T value, int startIndex) @@ -997,7 +997,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return IndexOf(array!, value, startIndex, array!.Length - startIndex); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return IndexOf(array, value, startIndex, array.Length - startIndex); } public static int IndexOf<T>(T[] array, T value, int startIndex, int count) @@ -1007,7 +1007,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if ((uint)startIndex > (uint)array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if ((uint)startIndex > (uint)array.Length) { ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(); } @@ -1071,7 +1071,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int lb = array.GetLowerBound(0); return LastIndexOf(array, value, array.Length - 1 + lb, array.Length); } @@ -1084,7 +1084,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int lb = array.GetLowerBound(0); return LastIndexOf(array, value, startIndex, startIndex + 1 - lb); } @@ -1098,7 +1098,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - int lb = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int lb = array.GetLowerBound(0); if (array.Length == 0) { return lb - 1; @@ -1170,7 +1170,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - return LastIndexOf(array!, value, array!.Length - 1, array.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return LastIndexOf(array, value, array.Length - 1, array.Length); } public static int LastIndexOf<T>(T[] array, T value, int startIndex) @@ -1180,7 +1180,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } // if array is empty and startIndex is 0, we need to pass 0 as count - return LastIndexOf(array!, value, startIndex, (array!.Length == 0) ? 0 : (startIndex + 1)); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return LastIndexOf(array, value, startIndex, (array.Length == 0) ? 0 : (startIndex + 1)); } public static int LastIndexOf<T>(T[] array, T value, int startIndex, int count) @@ -1190,7 +1190,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (array!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Length == 0) { // // Special case for 0 length List @@ -1285,7 +1285,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - Reverse(array!, array!.GetLowerBound(0), array.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Reverse(array, array.GetLowerBound(0), array.Length); } // Reverses the elements in a range of an array. Following a call to this @@ -1298,7 +1298,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - int lowerBound = array!.GetLowerBound(0); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int lowerBound = array.GetLowerBound(0); if (index < lowerBound) ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) @@ -1341,7 +1341,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - Reverse(array!, 0, array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Reverse(array, 0, array.Length); } public static void Reverse<T>(T[] array, int index, int length) @@ -1352,7 +1352,7 @@ namespace System ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); - if (array!.Length - index < length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Length - index < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); if (length <= 1) @@ -1378,7 +1378,7 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - Sort(array!, null, array!.GetLowerBound(0), array.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(array, null, array.GetLowerBound(0), array.Length, null); } // Sorts the elements of two arrays based on the keys in the first array. @@ -1391,7 +1391,7 @@ namespace System { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - Sort(keys!, items, keys!.GetLowerBound(0), keys.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(keys, items, keys.GetLowerBound(0), keys.Length, null); } // Sorts the elements in a section of an array. The sort compares the @@ -1439,7 +1439,7 @@ namespace System { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - Sort(keys!, items, keys!.GetLowerBound(0), keys.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(keys, items, keys.GetLowerBound(0), keys.Length, comparer); } // Sorts the elements in a section of an array. The sort compares the @@ -1465,7 +1465,7 @@ namespace System { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - if (keys!.Rank != 1 || (items != null && items.Rank != 1)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (keys.Rank != 1 || (items != null && items.Rank != 1)) ThrowHelper.ThrowRankException(ExceptionResource.Rank_MultiDimNotSupported); int keysLowerBound = keys.GetLowerBound(0); if (items != null && keysLowerBound != items.GetLowerBound(0)) @@ -1488,14 +1488,14 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - Sort<T>(array!, 0, array!.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort<T>(array, 0, array.Length, null); } public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items) { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - Sort<TKey, TValue>(keys!, items, 0, keys!.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort<TKey, TValue>(keys, items, 0, keys.Length, null); } public static void Sort<T>(T[] array, int index, int length) @@ -1512,14 +1512,14 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - Sort<T>(array!, 0, array!.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort<T>(array, 0, array.Length, comparer); } public static void Sort<TKey, TValue>(TKey[] keys, TValue[]? items, System.Collections.Generic.IComparer<TKey>? comparer) { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - Sort<TKey, TValue>(keys!, items, 0, keys!.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort<TKey, TValue>(keys, items, 0, keys.Length, comparer); } public static void Sort<T>(T[] array, int index, int length, System.Collections.Generic.IComparer<T>? comparer) @@ -1530,7 +1530,7 @@ namespace System ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); - if (array!.Length - index < length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Length - index < length) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); if (length > 1) @@ -1557,7 +1557,7 @@ namespace System ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); if (length < 0) ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); - if (keys!.Length - index < length || (items != null && index > items.Length - length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (keys.Length - index < length || (items != null && index > items.Length - length)) ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); if (length > 1) @@ -1594,7 +1594,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparison); } - ArraySortHelper<T>.Sort(array!, 0, array!.Length, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ArraySortHelper<T>.Sort(array, 0, array.Length, comparison!); } public static bool TrueForAll<T>(T[] array, Predicate<T> match) @@ -1609,9 +1609,9 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match); } - for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = 0; i < array.Length; i++) { - if (!match!(array[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (!match(array[i])) { return false; } diff --git a/src/System.Private.CoreLib/shared/System/ArraySegment.cs b/src/System.Private.CoreLib/shared/System/ArraySegment.cs index 941d73ca11..9c383a0e49 100644 --- a/src/System.Private.CoreLib/shared/System/ArraySegment.cs +++ b/src/System.Private.CoreLib/shared/System/ArraySegment.cs @@ -43,7 +43,7 @@ namespace System _array = array; _offset = 0; - _count = array!.Length; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + _count = array.Length; } public ArraySegment(T[] array, int offset, int count) diff --git a/src/System.Private.CoreLib/shared/System/BitConverter.cs b/src/System.Private.CoreLib/shared/System/BitConverter.cs index f6f6b98379..8841ca9b1c 100644 --- a/src/System.Private.CoreLib/shared/System/BitConverter.cs +++ b/src/System.Private.CoreLib/shared/System/BitConverter.cs @@ -236,7 +236,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); - if (unchecked((uint)startIndex) >= unchecked((uint)value!.Length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (unchecked((uint)startIndex) >= unchecked((uint)value.Length)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (startIndex > value.Length - sizeof(short)) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); @@ -257,7 +257,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); - if (unchecked((uint)startIndex) >= unchecked((uint)value!.Length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (unchecked((uint)startIndex) >= unchecked((uint)value.Length)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (startIndex > value.Length - sizeof(int)) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); @@ -278,7 +278,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); - if (unchecked((uint)startIndex) >= unchecked((uint)value!.Length)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (unchecked((uint)startIndex) >= unchecked((uint)value.Length)) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (startIndex > value.Length - sizeof(long)) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); @@ -363,11 +363,11 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); - if (startIndex < 0 || startIndex >= value!.Length && startIndex > 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (startIndex < 0 || startIndex >= value.Length && startIndex > 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); if (length < 0) throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_GenericPositive); - if (startIndex > value!.Length - length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (startIndex > value.Length - length) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); if (length == 0) @@ -409,7 +409,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); - return ToString(value!, 0, value!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return ToString(value, 0, value.Length); } // Converts an array of bytes into a String. @@ -417,7 +417,7 @@ namespace System { if (value == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); - return ToString(value!, startIndex, value!.Length - startIndex); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return ToString(value, startIndex, value.Length - startIndex); } /*==================================ToBoolean=================================== @@ -435,7 +435,7 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); if (startIndex < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); - if (startIndex > value!.Length - 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (startIndex > value.Length - 1) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); // differs from other overloads, which throw base ArgumentException return value[startIndex] != 0; diff --git a/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs b/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs index e62e37272a..adc22effff 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs @@ -100,7 +100,7 @@ namespace System.Collections.Concurrent // Initialize the segment and add all of the data to it. _tail = _head = new ConcurrentQueueSegment<T>(length); - foreach (T item in collection!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (T item in collection) { Enqueue(item); } @@ -147,7 +147,7 @@ namespace System.Collections.Concurrent // Otherwise, fall back to the slower path that first copies the contents // to an array, and then uses that array's non-generic CopyTo to do the copy. - ToArray().CopyTo(array!, index); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ToArray().CopyTo(array, index); } /// <summary> @@ -164,7 +164,7 @@ namespace System.Collections.Concurrent /// cref="ICollection"/>. This property is not supported. /// </summary> /// <exception cref="NotSupportedException">The SyncRoot property is not supported.</exception> - object ICollection.SyncRoot { get { ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); return default!; } } // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + object ICollection.SyncRoot { get { ThrowHelper.ThrowNotSupportedException(ExceptionResource.ConcurrentCollection_SyncRoot_NotSupported); return default; } } /// <summary>Returns an enumerator that iterates through a collection.</summary> /// <returns>An <see cref="IEnumerator"/> that can be used to iterate through the collection.</returns> @@ -462,7 +462,7 @@ namespace System.Collections.Concurrent // Get the number of items to be enumerated long count = GetCount(head, headHead, tail, tailTail); - if (index > array!.Length - count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (index > array.Length - count) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs index a10bb894a8..f2372deeea 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs @@ -100,7 +100,7 @@ namespace System.Collections.Generic // avoid the enumerator allocation and overhead by looping through the entries array directly. // We only do this when dictionary is Dictionary<TKey,TValue> and not a subclass, to maintain // back-compat with subclasses that may have overridden the enumerator behavior. - if (dictionary!.GetType() == typeof(Dictionary<TKey, TValue>)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (dictionary.GetType() == typeof(Dictionary<TKey, TValue>)) { Dictionary<TKey, TValue> d = (Dictionary<TKey, TValue>)dictionary; int count = d._count; @@ -131,7 +131,7 @@ namespace System.Collections.Generic ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } - foreach (KeyValuePair<TKey, TValue> pair in collection!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (KeyValuePair<TKey, TValue> pair in collection) { Add(pair.Key, pair.Value); } @@ -219,7 +219,7 @@ namespace System.Collections.Generic int i = FindEntry(key); if (i >= 0) return _entries![i].value; ThrowHelper.ThrowKeyNotFoundException(key); - return default!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return default; } set { @@ -320,7 +320,7 @@ namespace System.Collections.Generic ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if ((uint)index > (uint)array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if ((uint)index > (uint)array.Length) { ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } @@ -354,7 +354,7 @@ namespace System.Collections.Generic ThrowHelper.ThrowArgumentNullException(ExceptionArgument.info); } - info!.AddValue(VersionName, _version); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + info.AddValue(VersionName, _version); info.AddValue(ComparerName, _comparer ?? EqualityComparer<TKey>.Default, typeof(IEqualityComparer<TKey>)); info.AddValue(HashSizeName, _buckets == null ? 0 : _buckets.Length); // This is the length of the bucket array @@ -383,7 +383,7 @@ namespace System.Collections.Generic IEqualityComparer<TKey>? comparer = _comparer; if (comparer == null) { - uint hashCode = (uint)key!.GetHashCode(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + uint hashCode = (uint)key.GetHashCode(); // Value in _buckets is 1-based i = buckets[hashCode % (uint)buckets.Length] - 1; if (default(TKey)! != null) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757) @@ -492,7 +492,7 @@ namespace System.Collections.Generic Debug.Assert(entries != null, "expected entries to be non-null"); IEqualityComparer<TKey>? comparer = _comparer; - uint hashCode = (uint)((comparer == null) ? key!.GetHashCode() : comparer.GetHashCode(key)); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + uint hashCode = (uint)((comparer == null) ? key.GetHashCode() : comparer.GetHashCode(key)); int collisionCount = 0; ref int bucket = ref _buckets[hashCode % (uint)_buckets.Length]; @@ -700,7 +700,7 @@ namespace System.Collections.Generic ThrowHelper.ThrowSerializationException(ExceptionResource.Serialization_MissingKeys); } - for (int i = 0; i < array!.Length; i++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = 0; i < array.Length; i++) { if (array[i].Key == null) { @@ -778,7 +778,7 @@ namespace System.Collections.Generic if (buckets != null) { Debug.Assert(entries != null, "entries should be non-null"); - uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key!.GetHashCode()); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode()); uint bucket = hashCode % (uint)buckets.Length; int last = -1; // Value in buckets is 1-based @@ -846,7 +846,7 @@ namespace System.Collections.Generic if (buckets != null) { Debug.Assert(entries != null, "entries should be non-null"); - uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key!.GetHashCode()); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + uint hashCode = (uint)(_comparer?.GetHashCode(key) ?? key.GetHashCode()); uint bucket = hashCode % (uint)buckets.Length; int last = -1; // Value in buckets is 1-based @@ -925,7 +925,7 @@ namespace System.Collections.Generic { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); if (array.GetLowerBound(0) != 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound); @@ -965,7 +965,7 @@ namespace System.Collections.Generic { if (entries![i].next >= -1) { - objects![index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + objects[index++] = new KeyValuePair<TKey, TValue>(entries[i].key, entries[i].value); } } } @@ -1089,7 +1089,7 @@ namespace System.Collections.Generic try { - TKey tempKey = (TKey)key!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + TKey tempKey = (TKey)key; try { this[tempKey] = (TValue)value!; @@ -1125,7 +1125,7 @@ namespace System.Collections.Generic try { - TKey tempKey = (TKey)key!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + TKey tempKey = (TKey)key; try { @@ -1298,7 +1298,7 @@ namespace System.Collections.Generic { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary); } - _dictionary = dictionary!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + _dictionary = dictionary; } public Enumerator GetEnumerator() @@ -1311,12 +1311,12 @@ namespace System.Collections.Generic ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (index < 0 || index > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (index < 0 || index > array.Length) { ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } - if (array!.Length - index < _dictionary.Count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Length - index < _dictionary.Count) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } @@ -1358,7 +1358,7 @@ namespace System.Collections.Generic { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); if (array.GetLowerBound(0) != 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound); @@ -1385,7 +1385,7 @@ namespace System.Collections.Generic { for (int i = 0; i < count; i++) { - if (entries![i].next >= -1) objects![index++] = entries[i].key; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (entries![i].next >= -1) objects[index++] = entries[i].key; } } catch (ArrayTypeMismatchException) @@ -1481,7 +1481,7 @@ namespace System.Collections.Generic { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.dictionary); } - _dictionary = dictionary!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + _dictionary = dictionary; } public Enumerator GetEnumerator() @@ -1494,7 +1494,7 @@ namespace System.Collections.Generic ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if ((uint)index > array!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if ((uint)index > array.Length) { ThrowHelper.ThrowIndexArgumentOutOfRange_NeedNonNegNumException(); } @@ -1541,7 +1541,7 @@ namespace System.Collections.Generic { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); if (array.GetLowerBound(0) != 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NonZeroLowerBound); @@ -1568,7 +1568,7 @@ namespace System.Collections.Generic { for (int i = 0; i < count; i++) { - if (entries![i].next >= -1) objects![index++] = entries[i].value!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (entries![i].next >= -1) objects[index++] = entries[i].value!; } } catch (ArrayTypeMismatchException) diff --git a/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs b/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs index 5e13e3eb37..46d710a7f7 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs @@ -346,7 +346,7 @@ namespace System.Collections.Generic List<TOutput> list = new List<TOutput>(_size); for (int i = 0; i < _size; i++) { - list._items[i] = converter!(_items[i]); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + list._items[i] = converter(_items[i]); } list._size = _size; return list; @@ -447,7 +447,7 @@ namespace System.Collections.Generic List<T> list = new List<T>(); for (int i = 0; i < _size; i++) { - if (match!(_items[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match(_items[i])) { list.Add(_items[i]); } @@ -543,7 +543,7 @@ namespace System.Collections.Generic int endIndex = startIndex - count; for (int i = startIndex; i > endIndex; i--) { - if (match!(_items[i])) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (match(_items[i])) { return i; } @@ -747,7 +747,7 @@ namespace System.Collections.Generic } else { - using (IEnumerator<T> en = collection!.GetEnumerator()) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + using (IEnumerator<T> en = collection.GetEnumerator()) { while (en.MoveNext()) { @@ -867,7 +867,7 @@ namespace System.Collections.Generic int freeIndex = 0; // the first free slot in items array // Find the first item which needs to be removed. - while (freeIndex < _size && !match!(_items[freeIndex])) freeIndex++; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + while (freeIndex < _size && !match(_items[freeIndex])) freeIndex++; if (freeIndex >= _size) return 0; int current = freeIndex + 1; @@ -1026,7 +1026,7 @@ namespace System.Collections.Generic if (_size > 1) { - ArraySortHelper<T>.Sort(_items, 0, _size, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ArraySortHelper<T>.Sort(_items, 0, _size, comparison); } _version++; } diff --git a/src/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs b/src/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs index 64cf029d1c..0a2fbb90a3 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs @@ -22,7 +22,7 @@ namespace System.Collections if (s_serializationInfoTable == null) Interlocked.CompareExchange(ref s_serializationInfoTable, new ConditionalWeakTable<object, SerializationInfo>(), null); - return s_serializationInfoTable!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_serializationInfoTable; } } } diff --git a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs index 21af1c3593..0b258b7846 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs @@ -26,7 +26,7 @@ namespace System.Collections.ObjectModel { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list); } - items = list!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + items = list; } public int Count @@ -195,7 +195,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); } @@ -249,7 +249,7 @@ namespace System.Collections.ObjectModel { for (int i = 0; i < count; i++) { - objects![index++] = items[i]; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + objects[index++] = items[i]; } } catch (ArrayTypeMismatchException) diff --git a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs index 69b3424169..52a18e891b 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs @@ -21,7 +21,7 @@ namespace System.Collections.ObjectModel { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list); } - this.list = list!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this.list = list; } public int Count @@ -127,7 +127,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); } @@ -181,7 +181,7 @@ namespace System.Collections.ObjectModel { for (int i = 0; i < count; i++) { - objects![index++] = list[i]; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + objects[index++] = list[i]; } } catch (ArrayTypeMismatchException) diff --git a/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs b/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs index 20457028c2..6cc68de64d 100644 --- a/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs +++ b/src/System.Private.CoreLib/shared/System/DateTimeOffset.cs @@ -658,7 +658,7 @@ namespace System public static DateTimeOffset Parse(string input, IFormatProvider? formatProvider) { if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input); - return Parse(input!, formatProvider, DateTimeStyles.None); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return Parse(input, formatProvider, DateTimeStyles.None); } public static DateTimeOffset Parse(string input, IFormatProvider? formatProvider, DateTimeStyles styles) @@ -689,7 +689,7 @@ namespace System { if (input == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.input); if (format == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.format); - return ParseExact(input!, format!, formatProvider, DateTimeStyles.None); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return ParseExact(input, format, formatProvider, DateTimeStyles.None); } // Constructs a DateTimeOffset from a string. The string must specify a diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs index af6c1a333f..df338d16fb 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs @@ -703,7 +703,7 @@ namespace System.Diagnostics.Contracts /// full trust, because it will inform you of bugs in the appdomain and because the event handler /// could allow you to continue execution. /// </summary> - public static event EventHandler<ContractFailedEventArgs> ContractFailed + public static event EventHandler<ContractFailedEventArgs> ContractFailed // TODO-NULLABLE: Should all events use nullable delegate types? { add { diff --git a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index b7492347a8..58e74a12eb 100644 --- a/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/src/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -479,7 +479,7 @@ namespace System.Diagnostics.Tracing /// <summary> /// Fires when a Command (e.g. Enable) comes from a an EventListener. /// </summary> - public event EventHandler<EventCommandEventArgs> EventCommandExecuted + public event EventHandler<EventCommandEventArgs> EventCommandExecuted // TODO-NULLABLE: Should all events use nullable delegate types? { add { @@ -4042,7 +4042,7 @@ namespace System.Diagnostics.Tracing /// In a multi-threaded environment, it is possible that 'EventSourceEventWrittenCallback' /// events for a particular eventSource to occur BEFORE the EventSourceCreatedCallback is issued. /// </summary> - public event EventHandler<EventSourceCreatedEventArgs> EventSourceCreated + public event EventHandler<EventSourceCreatedEventArgs> EventSourceCreated // TODO-NULLABLE: Should all events use nullable delegate types? { add { @@ -4060,7 +4060,7 @@ namespace System.Diagnostics.Tracing /// This event is raised whenever an event has been written by a EventSource for which /// the EventListener has enabled events. /// </summary> - public event EventHandler<EventWrittenEventArgs> EventWritten = null!; + public event EventHandler<EventWrittenEventArgs> EventWritten = null!; // TODO-NULLABLE: Should all events use nullable delegate types? static EventListener() { @@ -4479,7 +4479,7 @@ namespace System.Diagnostics.Tracing { if (s_EventSources == null) Interlocked.CompareExchange(ref s_EventSources, new List<WeakReference>(2), null); - return s_EventSources!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_EventSources; } } diff --git a/src/System.Private.CoreLib/shared/System/Environment.Win32.cs b/src/System.Private.CoreLib/shared/System/Environment.Win32.cs index 3cad6fbf8c..78d49b1bcc 100644 --- a/src/System.Private.CoreLib/shared/System/Environment.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/Environment.Win32.cs @@ -80,7 +80,7 @@ namespace System { foreach (string name in environmentKey.GetValueNames()) { - string? value = environmentKey.GetValue(name, "")!.ToString(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + string? value = environmentKey.GetValue(name, "").ToString(); try { results.Add(name, value); diff --git a/src/System.Private.CoreLib/shared/System/Environment.cs b/src/System.Private.CoreLib/shared/System/Environment.cs index d99a5a667a..2b638fde9e 100644 --- a/src/System.Private.CoreLib/shared/System/Environment.cs +++ b/src/System.Private.CoreLib/shared/System/Environment.cs @@ -122,7 +122,7 @@ namespace System { Interlocked.CompareExchange(ref s_osVersion, GetOSVersion(), null); } - return s_osVersion!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_osVersion; } } diff --git a/src/System.Private.CoreLib/shared/System/Exception.cs b/src/System.Private.CoreLib/shared/System/Exception.cs index cb13645192..80dec57b10 100644 --- a/src/System.Private.CoreLib/shared/System/Exception.cs +++ b/src/System.Private.CoreLib/shared/System/Exception.cs @@ -166,7 +166,7 @@ namespace System return s; } - protected event EventHandler<SafeSerializationEventArgs> SerializeObjectState + protected event EventHandler<SafeSerializationEventArgs> SerializeObjectState // TODO-NULLABLE: Should all events use nullable delegate types? { add { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); } remove { throw new PlatformNotSupportedException(SR.PlatformNotSupported_SecureBinarySerialization); } diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs b/src/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs index 8d117ebab1..2e528e69a4 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs @@ -432,7 +432,7 @@ namespace System.Globalization { for (int i = 0; i < array.Length; i++) { - array[i] = ReescapeWin32String(array[i])!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + array[i] = ReescapeWin32String(array[i]); } } diff --git a/src/System.Private.CoreLib/shared/System/Progress.cs b/src/System.Private.CoreLib/shared/System/Progress.cs index 12557da4e9..36095c96c1 100644 --- a/src/System.Private.CoreLib/shared/System/Progress.cs +++ b/src/System.Private.CoreLib/shared/System/Progress.cs @@ -56,7 +56,7 @@ namespace System /// Handlers registered with this event will be invoked on the /// <see cref="System.Threading.SynchronizationContext"/> captured when the instance was constructed. /// </remarks> - public event EventHandler<T> ProgressChanged = null!; + public event EventHandler<T> ProgressChanged = null!; // TODO-NULLABLE: Should all events use nullable delegate types? /// <summary>Reports a progress change.</summary> /// <param name="value">The value of the updated progress.</param> diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs index 69820dea99..0b7a189219 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs @@ -117,7 +117,7 @@ namespace System.Reflection return Activator.CreateInstance(t, bindingAttr, binder, args, culture, activationAttributes); } - public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } } + public virtual event ModuleResolveEventHandler ModuleResolve { add { throw NotImplemented.ByDesign; } remove { throw NotImplemented.ByDesign; } } // TODO-NULLABLE: Should all events use nullable delegate types? public virtual Module ManifestModule { get { throw NotImplemented.ByDesign; } } public virtual Module? GetModule(string name) { throw NotImplemented.ByDesign; } 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 35f9702327..3c9ecc3a12 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -132,7 +132,7 @@ namespace System.Runtime.CompilerServices // and decrement its outstanding operation count. try { - System.Threading.Tasks.Task.ThrowAsync(exception!, targetContext: _synchronizationContext); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + System.Threading.Tasks.Task.ThrowAsync(exception, targetContext: _synchronizationContext); } finally { @@ -144,7 +144,7 @@ namespace System.Runtime.CompilerServices // Otherwise, queue the exception to be thrown on the ThreadPool. This will // result in a crash unless legacy exception behavior is enabled by a config // file or a CLR host. - System.Threading.Tasks.Task.ThrowAsync(exception!, targetContext: null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + System.Threading.Tasks.Task.ThrowAsync(exception, targetContext: null); } // The exception was propagated already; we don't need or want to fault the builder, just mark it as completed. @@ -602,7 +602,7 @@ namespace System.Runtime.CompilerServices if (context == null) { Debug.Assert(StateMachine != null); - StateMachine!.MoveNext(); // TODO-NULLABLE: remove ! when Debug.Assert on fields is respected (https://github.com/dotnet/roslyn/issues/36830) + StateMachine.MoveNext(); } else { @@ -788,7 +788,7 @@ namespace System.Runtime.CompilerServices // If the exception represents cancellation, cancel the task. Otherwise, fault the task. bool successfullySet = exception is OperationCanceledException oce ? task.TrySetCanceled(oce.CancellationToken, oce) : - task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + task.TrySetException(exception); // Unlike with TaskCompletionSource, we do not need to spin here until _taskAndStateMachine is completed, // since AsyncTaskMethodBuilder.SetException should not be immediately followed by any code @@ -1017,7 +1017,7 @@ namespace System.Runtime.CompilerServices try { - stateMachine!.MoveNext(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + stateMachine.MoveNext(); } finally { diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs index a916d719fc..b1a760af8c 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs @@ -59,7 +59,7 @@ namespace System.Runtime.CompilerServices ThrowHelper.ThrowArgumentNullException(ExceptionArgument.key); } - return _container.TryGetValueWorker(key!, out value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return _container.TryGetValueWorker(key, out value); } /// <summary>Adds a key to the table.</summary> @@ -80,13 +80,13 @@ namespace System.Runtime.CompilerServices lock (_lock) { - int entryIndex = _container.FindEntry(key!, out _); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int entryIndex = _container.FindEntry(key, out _); if (entryIndex != -1) { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate); } - CreateEntry(key!, value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + CreateEntry(key, value); } } @@ -102,7 +102,7 @@ namespace System.Runtime.CompilerServices lock (_lock) { - int entryIndex = _container.FindEntry(key!, out _); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int entryIndex = _container.FindEntry(key, out _); // if we found a key we should just update, if no we should create a new entry. if (entryIndex != -1) @@ -111,7 +111,7 @@ namespace System.Runtime.CompilerServices } else { - CreateEntry(key!, value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + CreateEntry(key, value); } } } @@ -133,7 +133,7 @@ namespace System.Runtime.CompilerServices lock (_lock) { - return _container.Remove(key!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return _container.Remove(key); } } diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs index 4cb70c052e..e654458cc8 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs @@ -17,7 +17,7 @@ namespace System.Runtime.CompilerServices /// event handlers sets the Cancel flag in the ContractFailedEventArgs, then the Contract class will /// not pop up an assert dialog box or trigger escalation policy. /// </summary> - internal static event EventHandler<ContractFailedEventArgs> InternalContractFailed; + internal static event EventHandler<ContractFailedEventArgs> InternalContractFailed; // TODO-NULLABLE: Should all events use nullable delegate types? /// <summary> /// Rewriter will call this method on a contract failure to allow listeners to be notified. diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs index b251c0b05d..60fa072752 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs @@ -23,7 +23,7 @@ namespace System.Runtime.CompilerServices ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - (int offset, int length) = range.GetOffsetAndLength(array!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + (int offset, int length) = range.GetOffsetAndLength(array.Length); if (default(T)! != null || typeof(T[]) == array.GetType()) // TODO-NULLABLE: default(T) == null warning (https://github.com/dotnet/roslyn/issues/34757) { diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs index 2062499057..33dee03fb8 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs @@ -208,7 +208,7 @@ namespace System.Runtime.InteropServices try { - s_nativeDllResolveMap!.Add(assembly, resolver); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + s_nativeDllResolveMap.Add(assembly, resolver); } catch (ArgumentException) { diff --git a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index c952686276..1c19e0971c 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs @@ -168,7 +168,7 @@ namespace System.Runtime.Loader // // Inputs: Invoking assembly, and library name to resolve // Returns: A handle to the loaded native library - public event Func<Assembly, string, IntPtr> ResolvingUnmanagedDll + public event Func<Assembly, string, IntPtr> ResolvingUnmanagedDll // TODO-NULLABLE: Should all events use nullable delegate types? { add { @@ -186,7 +186,7 @@ namespace System.Runtime.Loader // // Inputs: The AssemblyLoadContext and AssemblyName to be loaded // Returns: The Loaded assembly object. - public event Func<AssemblyLoadContext, AssemblyName, Assembly?> Resolving + public event Func<AssemblyLoadContext, AssemblyName, Assembly?> Resolving // TODO-NULLABLE: Should all events use nullable delegate types? { add { @@ -198,7 +198,7 @@ namespace System.Runtime.Loader } } - public event Action<AssemblyLoadContext> Unloading + public event Action<AssemblyLoadContext> Unloading // TODO-NULLABLE: Should all events use nullable delegate types? { add { @@ -212,17 +212,17 @@ namespace System.Runtime.Loader #region AppDomainEvents // Occurs when an Assembly is loaded - internal static event AssemblyLoadEventHandler AssemblyLoad; + internal static event AssemblyLoadEventHandler AssemblyLoad; // TODO-NULLABLE: Should all events use nullable delegate types? // Occurs when resolution of type fails - internal static event ResolveEventHandler TypeResolve; + internal static event ResolveEventHandler TypeResolve; // TODO-NULLABLE: Should all events use nullable delegate types? // Occurs when resolution of resource fails - internal static event ResolveEventHandler ResourceResolve; + internal static event ResolveEventHandler ResourceResolve; // TODO-NULLABLE: Should all events use nullable delegate types? // Occurs when resolution of assembly fails // This event is fired after resolve events of AssemblyLoadContext fails - internal static event ResolveEventHandler AssemblyResolve; + internal static event ResolveEventHandler AssemblyResolve; // TODO-NULLABLE: Should all events use nullable delegate types? #endregion public static AssemblyLoadContext Default => DefaultAssemblyLoadContext.s_loadContext; diff --git a/src/System.Private.CoreLib/shared/System/String.Searching.cs b/src/System.Private.CoreLib/shared/System/String.Searching.cs index ab98daf75d..cce119b1d0 100644 --- a/src/System.Private.CoreLib/shared/System/String.Searching.cs +++ b/src/System.Private.CoreLib/shared/System/String.Searching.cs @@ -18,7 +18,7 @@ namespace System return SpanHelpers.IndexOf( ref _firstChar, Length, - ref value!._firstChar, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ref value._firstChar, value.Length) >= 0; } diff --git a/src/System.Private.CoreLib/shared/System/StringComparer.cs b/src/System.Private.CoreLib/shared/System/StringComparer.cs index ef7281f061..3774a713dc 100644 --- a/src/System.Private.CoreLib/shared/System/StringComparer.cs +++ b/src/System.Private.CoreLib/shared/System/StringComparer.cs @@ -302,10 +302,10 @@ namespace System if (_ignoreCase) { - return obj!.GetHashCodeOrdinalIgnoreCase(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return obj.GetHashCodeOrdinalIgnoreCase(); } - return obj!.GetHashCode(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return obj.GetHashCode(); } // Equals method for the comparer itself. @@ -342,7 +342,7 @@ namespace System { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj); } - return obj!.GetHashCode(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return obj.GetHashCode(); } public void GetObjectData(SerializationInfo info, StreamingContext context) @@ -387,7 +387,7 @@ namespace System { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.obj); } - return obj!.GetHashCodeOrdinalIgnoreCase(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return obj.GetHashCodeOrdinalIgnoreCase(); } public void GetObjectData(SerializationInfo info, StreamingContext context) diff --git a/src/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs b/src/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs index 91226416ab..0501529bdf 100644 --- a/src/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs +++ b/src/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs @@ -72,7 +72,7 @@ namespace System.Text object o = new object(); Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null); } - return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_InternalSyncObject; } } diff --git a/src/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs b/src/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs index aa3f65bfa9..282baf7590 100644 --- a/src/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs +++ b/src/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs @@ -15,11 +15,11 @@ namespace System.Text private static DecoderFallback? s_exceptionFallback; public static DecoderFallback ReplacementFallback => - s_replacementFallback ?? Interlocked.CompareExchange(ref s_replacementFallback, new DecoderReplacementFallback(), null) ?? s_replacementFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + s_replacementFallback ?? Interlocked.CompareExchange(ref s_replacementFallback, new DecoderReplacementFallback(), null) ?? s_replacementFallback; public static DecoderFallback ExceptionFallback => - s_exceptionFallback ?? Interlocked.CompareExchange<DecoderFallback?>(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + s_exceptionFallback ?? Interlocked.CompareExchange<DecoderFallback?>(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback; // Fallback // diff --git a/src/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs b/src/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs index 518ceb7056..2e9cd69d8c 100644 --- a/src/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs +++ b/src/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs @@ -72,7 +72,7 @@ namespace System.Text object o = new object(); Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null); } - return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_InternalSyncObject; } } diff --git a/src/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs b/src/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs index 8fa9e6d27a..fd32a19517 100644 --- a/src/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs +++ b/src/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs @@ -23,7 +23,7 @@ namespace System.Text if (s_replacementFallback == null) Interlocked.CompareExchange<EncoderFallback?>(ref s_replacementFallback, new EncoderReplacementFallback(), null); - return s_replacementFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_replacementFallback; } } @@ -35,7 +35,7 @@ namespace System.Text if (s_exceptionFallback == null) Interlocked.CompareExchange<EncoderFallback?>(ref s_exceptionFallback, new EncoderExceptionFallback(), null); - return s_exceptionFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_exceptionFallback; } } diff --git a/src/System.Private.CoreLib/shared/System/Text/EncodingTable.cs b/src/System.Private.CoreLib/shared/System/Text/EncodingTable.cs index 4c0bd4a87c..3927ce6c0e 100644 --- a/src/System.Private.CoreLib/shared/System/Text/EncodingTable.cs +++ b/src/System.Private.CoreLib/shared/System/Text/EncodingTable.cs @@ -159,7 +159,7 @@ namespace System.Text return null; } - CodePageDataItem? data = s_codePageToCodePageData![index]; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + CodePageDataItem? data = s_codePageToCodePageData[index]; if (data == null) { Interlocked.CompareExchange<CodePageDataItem?>(ref s_codePageToCodePageData[index], InternalGetCodePageDataItem(codePage, index), null); diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index 81cd160bdc..6cb56c8f5f 100644 --- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -644,7 +644,7 @@ namespace System.Text ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } - return new ReadOnlyMemory<char>(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return new ReadOnlyMemory<char>(_currentChunk.m_ChunkChars, 0, _currentChunk.m_ChunkLength); } } diff --git a/src/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs b/src/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs index 89bd8c58b4..eccf905a00 100644 --- a/src/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs +++ b/src/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs @@ -138,7 +138,7 @@ namespace System.Text ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (chars!.Length - index < count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (chars.Length - index < count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } @@ -165,7 +165,7 @@ namespace System.Text fixed (char* pChars = chars) { - return GetByteCountCommon(pChars, chars!.Length); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return GetByteCountCommon(pChars, chars.Length); } } @@ -275,12 +275,12 @@ namespace System.Text resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (s!.Length - charIndex < charCount) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (s.Length - charIndex < charCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.s, ExceptionResource.ArgumentOutOfRange_IndexCount); } - if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if ((uint)byteIndex > bytes.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); } @@ -325,12 +325,12 @@ namespace System.Text resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (chars!.Length - charIndex < charCount) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (chars.Length - charIndex < charCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.chars, ExceptionResource.ArgumentOutOfRange_IndexCount); } - if ((uint)byteIndex > bytes!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if ((uint)byteIndex > bytes.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.byteIndex, ExceptionResource.ArgumentOutOfRange_Index); } @@ -443,7 +443,7 @@ namespace System.Text ThrowHelper.ThrowArgumentOutOfRangeException((index < 0) ? ExceptionArgument.index : ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (bytes!.Length - index < count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (bytes.Length - index < count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } @@ -510,12 +510,12 @@ namespace System.Text resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (bytes!.Length - byteIndex < byteCount) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (bytes.Length - byteIndex < byteCount) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } - if ((uint)charIndex > (uint)chars!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if ((uint)charIndex > (uint)chars.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.charIndex, ExceptionResource.ArgumentOutOfRange_Index); } @@ -672,7 +672,7 @@ namespace System.Text resource: ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } - if (bytes!.Length - index < count) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (bytes.Length - index < count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.bytes, ExceptionResource.ArgumentOutOfRange_IndexCountBuffer); } diff --git a/src/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs b/src/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs index 4c1705641d..513f6f05bb 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs @@ -133,10 +133,10 @@ namespace System.Threading // 2. if IsCancellationRequested = false, then NotifyCancellation will see that the event exists, and will call Set(). if (IsCancellationRequested) { - _kernelEvent!.Set(); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + _kernelEvent.Set(); } - return _kernelEvent!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return _kernelEvent; } } diff --git a/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs b/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs index 4a80c4f361..f8fdf6791a 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs @@ -272,7 +272,7 @@ namespace System.Threading } } - return target!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + return target!; // TODO-NULLABLE: Compiler can't infer target's non-nullness (https://github.com/dotnet/roslyn/issues/37300) } /// <summary> @@ -284,6 +284,6 @@ namespace System.Threading private static object EnsureLockInitialized([NotNull] ref object? syncLock) => syncLock ?? Interlocked.CompareExchange(ref syncLock, new object(), null) ?? - syncLock!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + syncLock; } } diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs index bed2f81a91..48a5ee4a06 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs @@ -339,7 +339,7 @@ namespace System.Threading.Tasks } // Create and schedule the future. - Task<TResult> f = new Task<TResult>(function!, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task<TResult> f = new Task<TResult>(function, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); f.ScheduleAndStart(false); return f; @@ -359,7 +359,7 @@ namespace System.Threading.Tasks } // Create and schedule the future. - Task<TResult> f = new Task<TResult>(function!, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task<TResult> f = new Task<TResult>(function, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); f.ScheduleAndStart(false); return f; @@ -727,13 +727,13 @@ namespace System.Threading.Tasks out internalOptions); Task continuationTask = new ContinuationTaskFromResultTask<TResult>( - this, continuationAction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationAction, null, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); return continuationTask; } @@ -920,13 +920,13 @@ namespace System.Threading.Tasks out internalOptions); Task continuationTask = new ContinuationTaskFromResultTask<TResult>( - this, continuationAction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationAction, state, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); return continuationTask; } @@ -1136,13 +1136,13 @@ namespace System.Threading.Tasks out internalOptions); Task<TNewResult> continuationFuture = new ContinuationResultTaskFromResultTask<TResult, TNewResult>( - this, continuationFunction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationFunction, null, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationFuture, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions); return continuationFuture; } @@ -1359,13 +1359,13 @@ namespace System.Threading.Tasks out internalOptions); Task<TNewResult> continuationFuture = new ContinuationResultTaskFromResultTask<TResult, TNewResult>( - this, continuationFunction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationFunction, state, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationFuture, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationFuture, scheduler, cancellationToken, continuationOptions); return continuationFuture; } 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 904bf531a7..f8db2bac0b 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs @@ -661,7 +661,7 @@ namespace System.Threading.Tasks // RespectParentCancellation. Task t = new Task(new Action<object>(delegate { - FromAsyncCoreLogic(asyncResult!, endFunction, endAction, promise, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + FromAsyncCoreLogic(asyncResult, endFunction, endAction, promise, requiresSynchronization: true); }), (object?)null, null, default, TaskCreationOptions.None, InternalTaskOptions.None, null); @@ -672,9 +672,9 @@ namespace System.Threading.Tasks if (Task.s_asyncDebuggingEnabled) Task.AddToActiveTasks(t); - if (asyncResult!.IsCompleted) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (asyncResult.IsCompleted) { - try { t.InternalRunSynchronously(scheduler!, waitForCompletion: false); } // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + try { t.InternalRunSynchronously(scheduler, waitForCompletion: false); } catch (Exception e) { promise.TrySetException(e); } // catch and log any scheduler exceptions } else @@ -683,7 +683,7 @@ namespace System.Threading.Tasks asyncResult.AsyncWaitHandle, delegate { - try { t.InternalRunSynchronously(scheduler!, waitForCompletion: false); } // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + try { t.InternalRunSynchronously(scheduler, waitForCompletion: false); } catch (Exception e) { promise.TrySetException(e); } // catch and log any scheduler exceptions }, null, @@ -766,7 +766,7 @@ namespace System.Threading.Tasks Task<TResult> promise = new Task<TResult>(state, creationOptions); if (AsyncCausalityTracer.LoggingOn) - AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name); if (Task.s_asyncDebuggingEnabled) Task.AddToActiveTasks(promise); @@ -774,7 +774,7 @@ namespace System.Threading.Tasks try { //if we don't require synchronization, a faster set result path is taken - var asyncResult = beginMethod!(iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + var asyncResult = beginMethod(iar => { if (!iar.CompletedSynchronously) FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true); @@ -883,7 +883,7 @@ namespace System.Threading.Tasks Task<TResult> promise = new Task<TResult>(state, creationOptions); if (AsyncCausalityTracer.LoggingOn) - AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name); if (Task.s_asyncDebuggingEnabled) Task.AddToActiveTasks(promise); @@ -891,7 +891,7 @@ namespace System.Threading.Tasks try { //if we don't require synchronization, a faster set result path is taken - var asyncResult = beginMethod!(arg1, iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + var asyncResult = beginMethod(arg1, iar => { if (!iar.CompletedSynchronously) FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true); @@ -1008,7 +1008,7 @@ namespace System.Threading.Tasks Task<TResult> promise = new Task<TResult>(state, creationOptions); if (AsyncCausalityTracer.LoggingOn) - AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name); if (Task.s_asyncDebuggingEnabled) Task.AddToActiveTasks(promise); @@ -1016,7 +1016,7 @@ namespace System.Threading.Tasks try { //if we don't require synchronization, a faster set result path is taken - var asyncResult = beginMethod!(arg1, arg2, iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + var asyncResult = beginMethod(arg1, arg2, iar => { if (!iar.CompletedSynchronously) FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true); @@ -1141,7 +1141,7 @@ namespace System.Threading.Tasks Task<TResult> promise = new Task<TResult>(state, creationOptions); if (AsyncCausalityTracer.LoggingOn) - AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod!.Method.Name); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + AsyncCausalityTracer.TraceOperationCreation(promise, "TaskFactory.FromAsync: " + beginMethod.Method.Name); if (Task.s_asyncDebuggingEnabled) Task.AddToActiveTasks(promise); @@ -1149,7 +1149,7 @@ namespace System.Threading.Tasks try { //if we don't require synchronization, a faster set result path is taken - var asyncResult = beginMethod!(arg1, arg2, arg3, iar => // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + var asyncResult = beginMethod(arg1, arg2, arg3, iar => { if (!iar.CompletedSynchronously) FromAsyncCoreLogic(iar, endFunction, endAction, promise, requiresSynchronization: true); @@ -1254,11 +1254,11 @@ namespace System.Threading.Tasks // Validate argument if (asyncResult == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.asyncResult); - var promise = asyncResult!.AsyncState as FromAsyncTrimPromise<TInstance>; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + var promise = asyncResult.AsyncState as FromAsyncTrimPromise<TInstance>; if (promise == null) ThrowHelper.ThrowArgumentException(ExceptionResource.InvalidOperation_WrongAsyncResultOrEndCalledMultiple, ExceptionArgument.asyncResult); // 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 thisRef = promise.m_thisRef; var endMethod = promise.m_endMethod; promise.m_thisRef = default; promise.m_endMethod = null; @@ -1269,7 +1269,7 @@ namespace System.Threading.Tasks if (!asyncResult.CompletedSynchronously) { Debug.Assert(thisRef != null); - promise.Complete(thisRef, endMethod!, asyncResult, requiresSynchronization: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + promise.Complete(thisRef, endMethod, asyncResult, requiresSynchronization: true); } } @@ -1612,7 +1612,7 @@ namespace System.Threading.Tasks if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); // Check tasks array and make defensive copy - Task<TAntecedentResult>[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy<TAntecedentResult>(tasks!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task<TAntecedentResult>[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy<TAntecedentResult>(tasks); // Bail early if cancellation has been requested. if (cancellationToken.IsCancellationRequested @@ -1631,7 +1631,7 @@ namespace System.Threading.Tasks return starter.ContinueWith<TResult>( // use a cached delegate GenericDelegateCache<TAntecedentResult, TResult>.CWAllFuncDelegate, - continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -1640,7 +1640,7 @@ namespace System.Threading.Tasks return starter.ContinueWith<TResult>( // use a cached delegate GenericDelegateCache<TAntecedentResult, TResult>.CWAllActionDelegate, - continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationAction, scheduler, cancellationToken, continuationOptions); } } @@ -1658,7 +1658,7 @@ namespace System.Threading.Tasks if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); // Check tasks array and make defensive copy - Task[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy(tasks!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task[] tasksCopy = TaskFactory.CheckMultiContinuationTasksAndCopy(tasks); // Bail early if cancellation has been requested. if (cancellationToken.IsCancellationRequested @@ -1684,7 +1684,7 @@ namespace System.Threading.Tasks Debug.Assert(state is Func<Task[], TResult>); return ((Func<Task[], TResult>)state)(completedTasks.Result); }, - continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -1699,7 +1699,7 @@ namespace System.Threading.Tasks Debug.Assert(state is Action<Task[]>); ((Action<Task[]>)state)(completedTasks.Result); return default!; }, - continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationAction, scheduler, cancellationToken, continuationOptions); } } @@ -1982,7 +1982,7 @@ namespace System.Threading.Tasks // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); - if (tasks!.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); //ArgumentNullException of continuationFunction or continuationAction is checked by the caller Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null"); @@ -2010,7 +2010,7 @@ namespace System.Threading.Tasks Debug.Assert(state is Func<Task, TResult>); return ((Func<Task, TResult>)state)(completedTask.Result); }, - continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -2024,7 +2024,7 @@ namespace System.Threading.Tasks ((Action<Task>)state)(completedTask.Result); return default!; }, - continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationAction, scheduler, cancellationToken, continuationOptions); } } @@ -2038,7 +2038,7 @@ namespace System.Threading.Tasks // check arguments TaskFactory.CheckMultiTaskContinuationOptions(continuationOptions); if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); - if (tasks!.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (tasks.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); //ArgumentNullException of continuationFunction or continuationAction is checked by the caller Debug.Assert((continuationFunction != null) != (continuationAction != null), "Expected exactly one of endFunction/endAction to be non-null"); if (scheduler == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); @@ -2060,7 +2060,7 @@ namespace System.Threading.Tasks return starter.ContinueWith<TResult>( // Use a cached delegate GenericDelegateCache<TAntecedentResult, TResult>.CWAnyFuncDelegate, - continuationFunction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationFunction, scheduler, cancellationToken, continuationOptions); } else { @@ -2068,7 +2068,7 @@ namespace System.Threading.Tasks return starter.ContinueWith<TResult>( // Use a cached delegate GenericDelegateCache<TAntecedentResult, TResult>.CWAnyActionDelegate, - continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationAction, scheduler, cancellationToken, continuationOptions); } } } diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs index 6f25d4ccb9..705f196fb7 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs @@ -1037,7 +1037,7 @@ namespace System.Threading.Tasks ThrowHelper.ThrowArgumentNullException(ExceptionArgument.scheduler); } - InternalRunSynchronously(scheduler!, waitForCompletion: true); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + InternalRunSynchronously(scheduler, waitForCompletion: true); } // @@ -1512,7 +1512,7 @@ namespace System.Threading.Tasks } } - return contingentProps.m_completionEvent!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return contingentProps.m_completionEvent; } } @@ -1802,7 +1802,7 @@ namespace System.Threading.Tasks lock (props) { - props.m_exceptionsHolder!.Add(exceptionObject, representsCancellation); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + props.m_exceptionsHolder.Add(exceptionObject, representsCancellation); } } @@ -3634,13 +3634,13 @@ namespace System.Threading.Tasks CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions); Task continuationTask = new ContinuationTaskFromTask( - this, continuationAction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationAction, null, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); return continuationTask; } @@ -3824,13 +3824,13 @@ namespace System.Threading.Tasks CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions); Task continuationTask = new ContinuationTaskFromTask( - this, continuationAction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationAction, state, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); return continuationTask; } @@ -4027,13 +4027,13 @@ namespace System.Threading.Tasks CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions); Task<TResult> continuationTask = new ContinuationResultTaskFromTask<TResult>( - this, continuationFunction!, null, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationFunction, null, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); return continuationTask; } @@ -4234,13 +4234,13 @@ namespace System.Threading.Tasks CreationOptionsFromContinuationOptions(continuationOptions, out creationOptions, out internalOptions); Task<TResult> continuationTask = new ContinuationResultTaskFromTask<TResult>( - this, continuationFunction!, state, // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this, continuationFunction, state, creationOptions, internalOptions ); // Register the continuation. If synchronous execution is requested, this may // actually invoke the continuation before returning. - ContinueWithCore(continuationTask, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ContinueWithCore(continuationTask, scheduler, cancellationToken, continuationOptions); return continuationTask; } @@ -4745,7 +4745,7 @@ namespace System.Threading.Tasks bool returnValue = true; // Collects incomplete tasks in "waitedOnTaskList" - for (int i = tasks!.Length - 1; i >= 0; i--) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int i = tasks.Length - 1; i >= 0; i--) { Task task = tasks[i]; @@ -4754,7 +4754,7 @@ namespace System.Threading.Tasks ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks); } - bool taskIsCompleted = task!.IsCompleted; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + bool taskIsCompleted = task.IsCompleted; if (!taskIsCompleted) { // try inlining the task only if we have an infinite timeout and an empty cancellation token @@ -5110,7 +5110,7 @@ namespace System.Threading.Tasks // Make a pass through the loop to check for any tasks that may have // already been completed, and to verify that no tasks are null. - for (int taskIndex = 0; taskIndex < tasks!.Length; taskIndex++) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + for (int taskIndex = 0; taskIndex < tasks.Length; taskIndex++) { Task task = tasks[taskIndex]; @@ -5119,7 +5119,7 @@ namespace System.Threading.Tasks ThrowHelper.ThrowArgumentException(ExceptionResource.Task_WaitMulti_NullTask, ExceptionArgument.tasks); } - if (signaledTaskIndex == -1 && task!.IsCompleted) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (signaledTaskIndex == -1 && task.IsCompleted) { // We found our first completed task. Store it, but we can't just return here, // as we still need to validate the whole array for nulls. @@ -5171,7 +5171,7 @@ namespace System.Threading.Tasks if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); var task = new Task(); - bool succeeded = task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + bool succeeded = task.TrySetException(exception); Debug.Assert(succeeded, "This should always succeed on a new task."); return task; } @@ -5185,7 +5185,7 @@ namespace System.Threading.Tasks if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); var task = new Task<TResult>(); - bool succeeded = task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + bool succeeded = task.TrySetException(exception); Debug.Assert(succeeded, "This should always succeed on a new task."); return task; } @@ -5345,7 +5345,7 @@ namespace System.Threading.Tasks return Task.FromCanceled(cancellationToken); // Kick off initial Task, which will call the user-supplied function and yield a Task. - Task<Task?> task1 = Task<Task?>.Factory.StartNew(function!, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task<Task?> task1 = Task<Task?>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // Create a promise-style Task to be used as a proxy for the operation // Set lookForOce == true so that unwrap logic can be on the lookout for OCEs thrown as faults from task1, to support in-delegate cancellation. @@ -5390,7 +5390,7 @@ namespace System.Threading.Tasks return Task.FromCanceled<TResult>(cancellationToken); // Kick off initial Task, which will call the user-supplied function and yield a Task. - Task<Task<TResult>?> task1 = Task<Task<TResult>?>.Factory.StartNew(function!, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task<Task<TResult>?> task1 = Task<Task<TResult>?>.Factory.StartNew(function, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // Create a promise-style Task to be used as a proxy for the operation // Set lookForOce == true so that unwrap logic can be on the lookout for OCEs thrown as faults from task1, to support in-delegate cancellation. @@ -5617,7 +5617,7 @@ namespace System.Threading.Tasks foreach (var task in tasks) { if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - taskArray[index++] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + taskArray[index++] = task; } return InternalWhenAll(taskArray); } @@ -5625,10 +5625,10 @@ namespace System.Threading.Tasks // Do some argument checking and convert tasks to a List (and later an array). if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); List<Task> taskList = new List<Task>(); - foreach (Task task in tasks!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (Task task in tasks) { if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - taskList.Add(task!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + taskList.Add(task); } // Delegate the rest to InternalWhenAll() @@ -5667,7 +5667,7 @@ namespace System.Threading.Tasks // Do some argument checking and make a defensive copy of the tasks array if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); - int taskCount = tasks!.Length; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int taskCount = tasks.Length; if (taskCount == 0) return InternalWhenAll(tasks); // Small optimization in the case of an empty array. Task[] tasksCopy = new Task[taskCount]; @@ -5675,7 +5675,7 @@ namespace System.Threading.Tasks { Task task = tasks[i]; if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - tasksCopy[i] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + tasksCopy[i] = task; } // The rest can be delegated to InternalWhenAll() @@ -5861,7 +5861,7 @@ namespace System.Threading.Tasks foreach (var task in tasks) { if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - taskArray[index++] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + taskArray[index++] = task; } return InternalWhenAll<TResult>(taskArray); } @@ -5869,10 +5869,10 @@ namespace System.Threading.Tasks // Do some argument checking and convert tasks into a List (later an array) if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); List<Task<TResult>> taskList = new List<Task<TResult>>(); - foreach (Task<TResult> task in tasks!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (Task<TResult> task in tasks) { if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - taskList.Add(task!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + taskList.Add(task); } // Delegate the rest to InternalWhenAll<TResult>(). @@ -5914,7 +5914,7 @@ namespace System.Threading.Tasks // Do some argument checking and make a defensive copy of the tasks array if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); - int taskCount = tasks!.Length; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + int taskCount = tasks.Length; if (taskCount == 0) return InternalWhenAll<TResult>(tasks); // small optimization in the case of an empty task array Task<TResult>[] tasksCopy = new Task<TResult>[taskCount]; @@ -5922,7 +5922,7 @@ namespace System.Threading.Tasks { Task<TResult> task = tasks[i]; if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - tasksCopy[i] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + tasksCopy[i] = task; } // Delegate the rest to InternalWhenAll<TResult>() @@ -6081,7 +6081,7 @@ namespace System.Threading.Tasks public static Task<Task> WhenAny(params Task[] tasks) { if (tasks == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tasks); - if (tasks!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (tasks.Length == 0) { ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_EmptyTaskList, ExceptionArgument.tasks); } @@ -6094,7 +6094,7 @@ namespace System.Threading.Tasks { Task task = tasks[i]; if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - tasksCopy[i] = task!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + tasksCopy[i] = task; } // Previously implemented CommonCWAnyLogic() can handle the rest @@ -6123,10 +6123,10 @@ namespace System.Threading.Tasks // Make a defensive copy, as the user may manipulate the tasks collection // after we return but before the WhenAny asynchronously completes. List<Task> taskList = new List<Task>(); - foreach (Task task in tasks!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (Task task in tasks) { if (task == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Task_MultiTaskContinuation_NullTask, ExceptionArgument.tasks); - taskList.Add(task!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + taskList.Add(task); } if (taskList.Count == 0) diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs index b0c79e61ba..71a7e22ebd 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs @@ -150,7 +150,7 @@ namespace System.Threading.Tasks { if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); - bool rval = _task.TrySetException(exception!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + bool rval = _task.TrySetException(exception); if (!rval && !_task.IsCompleted) SpinUntilCompleted(); return rval; } @@ -180,11 +180,11 @@ namespace System.Threading.Tasks if (exceptions == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exceptions); List<Exception> defensiveCopy = new List<Exception>(); - foreach (Exception e in exceptions!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (Exception e in exceptions) { if (e == null) ThrowHelper.ThrowArgumentException(ExceptionResource.TaskCompletionSourceT_TrySetException_NullException, ExceptionArgument.exceptions); - defensiveCopy.Add(e!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + defensiveCopy.Add(e); } if (defensiveCopy.Count == 0) @@ -216,7 +216,7 @@ namespace System.Threading.Tasks { if (exception == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.exception); - if (!TrySetException(exception!)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (!TrySetException(exception)) { ThrowHelper.ThrowInvalidOperationException(ExceptionResource.TaskT_TransitionToFinal_AlreadyCompleted); } diff --git a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs index f79a87ac06..4c7a3c4ea2 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs @@ -298,7 +298,7 @@ namespace System.Threading.Tasks Interlocked.CompareExchange(ref s_activeTaskSchedulers, new ConditionalWeakTable<TaskScheduler, object?>(), null); activeTaskSchedulers = s_activeTaskSchedulers; } - activeTaskSchedulers!.Add(this, null); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + activeTaskSchedulers.Add(this, null); } /// <summary> @@ -445,7 +445,7 @@ namespace System.Threading.Tasks /// Each handler is passed a <see cref="T:System.Threading.Tasks.UnobservedTaskExceptionEventArgs"/> /// instance, which may be used to examine the exception and to mark it as observed. /// </remarks> - public static event EventHandler<UnobservedTaskExceptionEventArgs> UnobservedTaskException; + public static event EventHandler<UnobservedTaskExceptionEventArgs> UnobservedTaskException; // TODO-NULLABLE: Should all events use nullable delegate types? //////////////////////////////////////////////////////////// // diff --git a/src/System.Private.CoreLib/shared/System/Threading/Thread.cs b/src/System.Private.CoreLib/shared/System/Threading/Thread.cs index eeb2f413ce..28b2e6eb8f 100644 --- a/src/System.Private.CoreLib/shared/System/Threading/Thread.cs +++ b/src/System.Private.CoreLib/shared/System/Threading/Thread.cs @@ -152,7 +152,7 @@ namespace System.Threading } Interlocked.CompareExchange(ref s_asyncLocalPrincipal, new AsyncLocal<IPrincipal?>(), null); } - s_asyncLocalPrincipal!.Value = value; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + s_asyncLocalPrincipal.Value = value; } } diff --git a/src/System.Private.CoreLib/shared/System/TimeZone.cs b/src/System.Private.CoreLib/shared/System/TimeZone.cs index 0775e5b1fa..841ba76132 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZone.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZone.cs @@ -42,7 +42,7 @@ namespace System object o = new object(); Interlocked.CompareExchange<object?>(ref s_InternalSyncObject, o, null); } - return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_InternalSyncObject; } } diff --git a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs index 0ec94702df..8cff79351c 100644 --- a/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs +++ b/src/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs @@ -563,8 +563,8 @@ namespace System // read LastEntry {(yearN, 1, 1) - MaxValue } // read the FirstEntry and LastEntry key values (ex: "1980", "2038") - int first = (int)dynamicKey.GetValue(FirstEntryValue, -1)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected - int last = (int)dynamicKey.GetValue(LastEntryValue, -1)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + int first = (int)dynamicKey.GetValue(FirstEntryValue, -1); + int last = (int)dynamicKey.GetValue(LastEntryValue, -1); if (first == -1 || last == -1 || first > last) { diff --git a/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs index d2c04156fd..8eadef1a03 100644 --- a/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Array.CoreCLR.cs @@ -29,10 +29,10 @@ namespace System if (length < 0) ThrowHelper.ThrowLengthArgumentOutOfRange_ArgumentOutOfRange_NeedNonNegNum(); - RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); - return InternalCreate((void*)t!.TypeHandle.Value, 1, &length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return InternalCreate((void*)t.TypeHandle.Value, 1, &length, null); } public static unsafe Array CreateInstance(Type elementType, int length1, int length2) @@ -44,13 +44,13 @@ namespace System if (length2 < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); - RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); int* pLengths = stackalloc int[2]; pLengths[0] = length1; pLengths[1] = length2; - return InternalCreate((void*)t!.TypeHandle.Value, 2, pLengths, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return InternalCreate((void*)t.TypeHandle.Value, 2, pLengths, null); } public static unsafe Array CreateInstance(Type elementType, int length1, int length2, int length3) @@ -64,14 +64,14 @@ namespace System if (length3 < 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.length3, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); - RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); int* pLengths = stackalloc int[3]; pLengths[0] = length1; pLengths[1] = length2; pLengths[2] = length3; - return InternalCreate((void*)t!.TypeHandle.Value, 3, pLengths, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return InternalCreate((void*)t.TypeHandle.Value, 3, pLengths, null); } public static unsafe Array CreateInstance(Type elementType, params int[] lengths) @@ -80,10 +80,10 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); if (lengths == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths); - if (lengths!.Length == 0) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (lengths.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank); - RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); @@ -96,7 +96,7 @@ namespace System ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, i, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); fixed (int* pLengths = &lengths[0]) - return InternalCreate((void*)t!.TypeHandle.Value, lengths.Length, pLengths, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return InternalCreate((void*)t.TypeHandle.Value, lengths.Length, pLengths, null); } public static unsafe Array CreateInstance(Type elementType, int[] lengths, int[] lowerBounds) @@ -107,12 +107,12 @@ namespace System ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lengths); if (lowerBounds == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.lowerBounds); - if (lengths!.Length != lowerBounds!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (lengths.Length != lowerBounds!.Length) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RanksAndBounds); if (lengths.Length == 0) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_NeedAtLeast1Rank); - RuntimeType? t = elementType!.UnderlyingSystemType as RuntimeType; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + RuntimeType? t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType); @@ -126,7 +126,7 @@ namespace System fixed (int* pLengths = &lengths[0]) fixed (int* pLowerBounds = &lowerBounds[0]) - return InternalCreate((void*)t!.TypeHandle.Value, lengths.Length, pLengths, pLowerBounds); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return InternalCreate((void*)t.TypeHandle.Value, lengths.Length, pLengths, pLowerBounds); } [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -142,7 +142,7 @@ namespace System if (destinationArray == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.destinationArray); - Copy(sourceArray!, sourceArray!.GetLowerBound(0), destinationArray!, destinationArray!.GetLowerBound(0), length, false); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Copy(sourceArray, sourceArray.GetLowerBound(0), destinationArray, destinationArray.GetLowerBound(0), length, false); } // Copies length elements from sourceArray, starting at sourceIndex, to @@ -178,7 +178,7 @@ namespace System if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - ref byte p = ref GetRawArrayGeometry(array!, out uint numComponents, out uint elementSize, out int lowerBound, out bool containsGCPointers); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ref byte p = ref GetRawArrayGeometry(array, out uint numComponents, out uint elementSize, out int lowerBound, out bool containsGCPointers); int offset = index - lowerBound; @@ -202,7 +202,7 @@ namespace System { if (indices == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); - if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (Rank != indices.Length) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); TypedReference elemref = new TypedReference(); @@ -293,7 +293,7 @@ namespace System { if (indices == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.indices); - if (Rank != indices!.Length) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (Rank != indices.Length) ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankIndices); TypedReference elemref = new TypedReference(); diff --git a/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs index 96a04fd502..19ee5e0859 100644 --- a/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs +++ b/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs @@ -294,7 +294,7 @@ namespace System { if (objAttr[i] != null) { - attributes[count] = (Attribute)objAttr[i]!; // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) + attributes[count] = (Attribute)objAttr[i]!; // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) count++; } } diff --git a/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs b/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs index c1de2ae6e0..a6c242fe94 100644 --- a/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs +++ b/src/System.Private.CoreLib/src/System/Collections/ObjectModel/ReadOnlyDictionary.cs @@ -273,7 +273,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); } @@ -318,7 +318,7 @@ namespace System.Collections.ObjectModel { foreach (var item in m_dictionary) { - objects![index++] = new KeyValuePair<TKey, TValue>(item.Key, item.Value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + objects[index++] = new KeyValuePair<TKey, TValue>(item.Key, item.Value); } } catch (ArrayTypeMismatchException) @@ -349,7 +349,7 @@ namespace System.Collections.ObjectModel Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null); } } - return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return m_syncRoot; } } @@ -430,7 +430,7 @@ namespace System.Collections.ObjectModel { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } - m_collection = collection!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + m_collection = collection; } #region ICollection<T> Members @@ -518,7 +518,7 @@ namespace System.Collections.ObjectModel Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null); } } - return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return m_syncRoot; } } @@ -538,7 +538,7 @@ namespace System.Collections.ObjectModel { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } - m_collection = collection!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + m_collection = collection; } #region ICollection<T> Members @@ -626,7 +626,7 @@ namespace System.Collections.ObjectModel Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null); } } - return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return m_syncRoot; } } @@ -647,7 +647,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } - if (array!.Rank != 1) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (array.Rank != 1) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_RankMultiDimNotSupported); } @@ -707,7 +707,7 @@ namespace System.Collections.ObjectModel { foreach (var item in collection) { - objects![index++] = item; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + objects[index++] = item; } } catch (ArrayTypeMismatchException) diff --git a/src/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/System.Private.CoreLib/src/System/MulticastDelegate.cs index 311c1629b8..67b3ef443b 100644 --- a/src/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -579,7 +579,7 @@ namespace System { if (target == null) ThrowNullThisInDelegateToInstance(); - this._target = target!; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + this._target = target; this._methodPtr = methodPtr; } diff --git a/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs b/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs index 4b7c508034..a350c70c27 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/Emit/ILGenerator.cs @@ -1564,7 +1564,7 @@ namespace System.Reflection.Emit { m_localSymInfos[i] = new LocalSymInfo(); } - m_localSymInfos[i]!.AddLocalSymInfo(strName, signature, slot, startOffset, endOffset); // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) + m_localSymInfos[i]!.AddLocalSymInfo(strName, signature, slot, startOffset, endOffset); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) } internal void AddUsingNamespaceToCurrentScope( @@ -1575,7 +1575,7 @@ namespace System.Reflection.Emit { m_localSymInfos[i] = new LocalSymInfo(); } - m_localSymInfos[i]!.AddUsingNamespace(strNamespace); // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) + m_localSymInfos[i]!.AddUsingNamespace(strNamespace); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) } internal void AddScopeInfo(ScopeAction sa, int iOffset) @@ -1642,7 +1642,7 @@ namespace System.Reflection.Emit } if (m_localSymInfos[i] != null) { - m_localSymInfos[i]!.EmitLocalSymInfo(symWriter); // TODO-NULLABLE Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) + m_localSymInfos[i]!.EmitLocalSymInfo(symWriter); // TODO-NULLABLE: Indexer nullability tracked (https://github.com/dotnet/roslyn/issues/34644) } } } diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs index 92cd2b83ab..e55d46637b 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeAssembly.cs @@ -50,11 +50,11 @@ namespace System.Reflection { Interlocked.CompareExchange<object?>(ref m_syncRoot, new object(), null); } - return m_syncRoot!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return m_syncRoot; } } - public override event ModuleResolveEventHandler ModuleResolve + public override event ModuleResolveEventHandler ModuleResolve // TODO-NULLABLE: Should all events use nullable delegate types? { add { diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsMethod.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsMethod.cs index 996802013a..10ef6e5db9 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsMethod.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsMethod.cs @@ -173,7 +173,7 @@ namespace System.Runtime.InteropServices { if (wrapper.Delegate.GetType() == d.GetType()) { - wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d); return; } } diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs index 6714f7b33c..5788afbdd2 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/WindowsRuntime/EventRegistrationTokenTable.cs @@ -243,7 +243,7 @@ namespace System.Runtime.InteropServices.WindowsRuntime { Interlocked.CompareExchange(ref refEventTable, new EventRegistrationTokenTable<T>(), null); } - return refEventTable!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return refEventTable; } } } diff --git a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs index 8ceeb93b18..d04c8bf23d 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs @@ -99,7 +99,7 @@ namespace System.Runtime.Loader _assemblyPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); foreach (string assemblyPath in assemblyPaths) { - _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath)!, assemblyPath); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath), assemblyPath); } _nativeSearchPaths = SplitPathsList(nativeSearchPathsList); diff --git a/src/System.Private.CoreLib/src/System/StubHelpers.cs b/src/System.Private.CoreLib/src/System/StubHelpers.cs index 0f9ee4e4a2..0deff2c84a 100644 --- a/src/System.Private.CoreLib/src/System/StubHelpers.cs +++ b/src/System.Private.CoreLib/src/System/StubHelpers.cs @@ -1622,7 +1622,7 @@ namespace System.StubHelpers ThrowHelper.ThrowArgumentNullException(ExceptionArgument.pHandle, ExceptionResource.ArgumentNull_SafeHandle); } - pHandle!.DangerousAddRef(ref success); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + pHandle.DangerousAddRef(ref success); return pHandle.DangerousGetHandle(); } @@ -1636,7 +1636,7 @@ namespace System.StubHelpers try { - pHandle!.DangerousRelease(); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + pHandle.DangerousRelease(); } catch { diff --git a/src/System.Private.CoreLib/src/System/Utf8String.Construction.cs b/src/System.Private.CoreLib/src/System/Utf8String.Construction.cs index 18988b7a20..074cc60003 100644 --- a/src/System.Private.CoreLib/src/System/Utf8String.Construction.cs +++ b/src/System.Private.CoreLib/src/System/Utf8String.Construction.cs @@ -49,7 +49,7 @@ namespace System Utf8String newString = FastAllocate(value.Length); Buffer.Memmove(ref newString.DangerousGetMutableReference(), ref MemoryMarshal.GetReference(value), (uint)value.Length); - return Utf8Utility.ValidateAndFixupUtf8String(newString)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + return Utf8Utility.ValidateAndFixupUtf8String(newString); } /// <summary> |