From 4ec5b8de9808b04929f63e6bed05125d197af4ff Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 17 Jul 2019 13:01:37 -0400 Subject: [PATCH] Remove now unnecessary !s / TODO-NULLABLE comments (dotnet/coreclr#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 Signed-off-by: dotnet-bot --- .../Interop/Windows/Kernel32/Interop.CreateFile.cs | 2 +- .../Windows/Kernel32/Interop.CreateFile2.cs | 2 +- .../Windows/Kernel32/Interop.FindFirstFileEx.cs | 2 +- .../Kernel32/Interop.GetFileAttributesEx.cs | 2 +- .../shared/System/AppContext.cs | 8 +- .../shared/System/AppDomain.cs | 22 ++-- .../System.Private.CoreLib/shared/System/Array.cs | 130 ++++++++++----------- .../shared/System/ArraySegment.cs | 2 +- .../shared/System/BitConverter.cs | 16 +-- .../Collections/Concurrent/ConcurrentQueue.cs | 8 +- .../System/Collections/Generic/Dictionary.cs | 46 ++++---- .../shared/System/Collections/Generic/List.cs | 12 +- .../HashHelpers.SerializationInfoTable.cs | 2 +- .../System/Collections/ObjectModel/Collection.cs | 6 +- .../Collections/ObjectModel/ReadOnlyCollection.cs | 6 +- .../shared/System/DateTimeOffset.cs | 4 +- .../System/Diagnostics/Contracts/Contracts.cs | 2 +- .../System/Diagnostics/Tracing/EventSource.cs | 8 +- .../shared/System/Environment.Win32.cs | 2 +- .../shared/System/Environment.cs | 2 +- .../shared/System/Exception.cs | 2 +- .../System/Globalization/CultureData.Windows.cs | 2 +- .../shared/System/Progress.cs | 2 +- .../shared/System/Reflection/Assembly.cs | 2 +- .../Runtime/CompilerServices/AsyncMethodBuilder.cs | 10 +- .../CompilerServices/ConditionalWeakTable.cs | 12 +- .../Runtime/CompilerServices/ContractHelper.cs | 2 +- .../Runtime/CompilerServices/RuntimeHelpers.cs | 2 +- .../Runtime/InteropServices/NativeLibrary.cs | 2 +- .../System/Runtime/Loader/AssemblyLoadContext.cs | 14 +-- .../shared/System/String.Searching.cs | 2 +- .../shared/System/StringComparer.cs | 8 +- .../shared/System/Text/DecoderBestFitFallback.cs | 2 +- .../shared/System/Text/DecoderFallback.cs | 4 +- .../shared/System/Text/EncoderBestFitFallback.cs | 2 +- .../shared/System/Text/EncoderFallback.cs | 4 +- .../shared/System/Text/EncodingTable.cs | 2 +- .../shared/System/Text/StringBuilder.cs | 2 +- .../shared/System/Text/UTF8Encoding.cs | 20 ++-- .../System/Threading/CancellationTokenSource.cs | 4 +- .../shared/System/Threading/LazyInitializer.cs | 4 +- .../shared/System/Threading/Tasks/Future.cs | 20 ++-- .../shared/System/Threading/Tasks/FutureFactory.cs | 54 ++++----- .../shared/System/Threading/Tasks/Task.cs | 66 +++++------ .../System/Threading/Tasks/TaskCompletionSource.cs | 8 +- .../shared/System/Threading/Tasks/TaskScheduler.cs | 4 +- .../shared/System/Threading/Thread.cs | 2 +- .../shared/System/TimeZone.cs | 2 +- .../shared/System/TimeZoneInfo.Win32.cs | 4 +- 49 files changed, 274 insertions(+), 274 deletions(-) diff --git a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs index b1589acff28..0e7519d42f9 100644 --- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs index 82d62cc4d3e..323de99c2af 100644 --- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs index 7d5203d44f5..bb1ddf78576 100644 --- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs b/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs index 65649e497d7..ee2370038f1 100644 --- a/netcore/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/AppContext.cs b/netcore/System.Private.CoreLib/shared/System/AppContext.cs index 8601d3f26ba..605326ca1f3 100644 --- a/netcore/System.Private.CoreLib/shared/System/AppContext.cs +++ b/netcore/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 FirstChanceException; + public static event System.EventHandler 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(), null); } - lock (s_switches!) // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + lock (s_switches) { s_switches[switchName] = isEnabled; } diff --git a/netcore/System.Private.CoreLib/shared/System/AppDomain.cs b/netcore/System.Private.CoreLib/shared/System/AppDomain.cs index d48d34922f9..6795e556f34 100644 --- a/netcore/System.Private.CoreLib/shared/System/AppDomain.cs +++ b/netcore/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 FirstChanceException + public event EventHandler 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)mi.CreateDelegate(typeof(Func))); } - principal = s_getUnauthenticatedPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + principal = s_getUnauthenticatedPrincipal(); break; case PrincipalPolicy.WindowsPrincipal: @@ -425,7 +425,7 @@ namespace System (Func)mi.CreateDelegate(typeof(Func))); } - principal = s_getWindowsPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected + principal = s_getWindowsPrincipal(); break; } } diff --git a/netcore/System.Private.CoreLib/shared/System/Array.cs b/netcore/System.Private.CoreLib/shared/System/Array.cs index 11479d88e28..0613abeb0e6 100644 --- a/netcore/System.Private.CoreLib/shared/System/Array.cs +++ b/netcore/System.Private.CoreLib/shared/System/Array.cs @@ -37,7 +37,7 @@ namespace System } // T[] implements IList. - return new ReadOnlyCollection(array!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return new ReadOnlyCollection(array); } public static void Resize([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(array!, 0, array!.Length, value, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return BinarySearch(array, 0, array.Length, value, null); } public static int BinarySearch(T[] array, T value, System.Collections.Generic.IComparer? comparer) { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - return BinarySearch(array!, 0, array!.Length, value, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return BinarySearch(array, 0, array.Length, value, comparer); } public static int BinarySearch(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.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 list = new List(); - 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[] array, int startIndex, Predicate 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[] array, int startIndex, int count, Predicate 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[] array, int startIndex, Predicate 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[] array, int startIndex, int count, Predicate 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[] 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[] 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[] 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[] 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[] 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(array!, 0, array!.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(array, 0, array.Length, null); } public static void Sort(TKey[] keys, TValue[]? items) { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - Sort(keys!, items, 0, keys!.Length, null); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(keys, items, 0, keys.Length, null); } public static void Sort(T[] array, int index, int length) @@ -1512,14 +1512,14 @@ namespace System { if (array == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); - Sort(array!, 0, array!.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(array, 0, array.Length, comparer); } public static void Sort(TKey[] keys, TValue[]? items, System.Collections.Generic.IComparer? comparer) { if (keys == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.keys); - Sort(keys!, items, 0, keys!.Length, comparer); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Sort(keys, items, 0, keys.Length, comparer); } public static void Sort(T[] array, int index, int length, System.Collections.Generic.IComparer? 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.Sort(array!, 0, array!.Length, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ArraySortHelper.Sort(array, 0, array.Length, comparison!); } public static bool TrueForAll(T[] array, Predicate 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/netcore/System.Private.CoreLib/shared/System/ArraySegment.cs b/netcore/System.Private.CoreLib/shared/System/ArraySegment.cs index 941d73ca114..9c383a0e49c 100644 --- a/netcore/System.Private.CoreLib/shared/System/ArraySegment.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/BitConverter.cs b/netcore/System.Private.CoreLib/shared/System/BitConverter.cs index f6f6b983795..8841ca9b1c2 100644 --- a/netcore/System.Private.CoreLib/shared/System/BitConverter.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs index e62e37272a2..adc22effff5 100644 --- a/netcore/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueue.cs +++ b/netcore/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(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); } /// @@ -164,7 +164,7 @@ namespace System.Collections.Concurrent /// cref="ICollection"/>. This property is not supported. /// /// The SyncRoot property is not supported. - 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; } } /// Returns an enumerator that iterates through a collection. /// An that can be used to iterate through the collection. @@ -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/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs index a10bb894a8b..f2372deeea2 100644 --- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs +++ b/netcore/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 and not a subclass, to maintain // back-compat with subclasses that may have overridden the enumerator behavior. - if (dictionary!.GetType() == typeof(Dictionary)) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + if (dictionary.GetType() == typeof(Dictionary)) { Dictionary d = (Dictionary)dictionary; int count = d._count; @@ -131,7 +131,7 @@ namespace System.Collections.Generic ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } - foreach (KeyValuePair pair in collection!) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + foreach (KeyValuePair 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.Default, typeof(IEqualityComparer)); 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? 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? 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(entries[i].key, entries[i].value); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + objects[index++] = new KeyValuePair(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/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs index 5e13e3eb379..46d710a7f7b 100644 --- a/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs +++ b/netcore/System.Private.CoreLib/shared/System/Collections/Generic/List.cs @@ -346,7 +346,7 @@ namespace System.Collections.Generic List list = new List(_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 list = new List(); 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 en = collection!.GetEnumerator()) // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + using (IEnumerator 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.Sort(_items, 0, _size, comparison!); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + ArraySortHelper.Sort(_items, 0, _size, comparison); } _version++; } diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs b/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs index 64cf029d1c7..0a2fbb90a3e 100644 --- a/netcore/System.Private.CoreLib/shared/System/Collections/HashHelpers.SerializationInfoTable.cs +++ b/netcore/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(), null); - return s_serializationInfoTable!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_serializationInfoTable; } } } diff --git a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs index 21af1c3593b..0b258b78462 100644 --- a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs b/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs index 69b34241694..52a18e891ba 100644 --- a/netcore/System.Private.CoreLib/shared/System/Collections/ObjectModel/ReadOnlyCollection.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs b/netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs index 20457028c29..6cc68de64d4 100644 --- a/netcore/System.Private.CoreLib/shared/System/DateTimeOffset.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs index af6c1a333fb..df338d16fb6 100644 --- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Contracts/Contracts.cs +++ b/netcore/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. /// - public static event EventHandler ContractFailed + public static event EventHandler ContractFailed // TODO-NULLABLE: Should all events use nullable delegate types? { add { diff --git a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs index b7492347a8e..58e74a12eba 100644 --- a/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs +++ b/netcore/System.Private.CoreLib/shared/System/Diagnostics/Tracing/EventSource.cs @@ -479,7 +479,7 @@ namespace System.Diagnostics.Tracing /// /// Fires when a Command (e.g. Enable) comes from a an EventListener. /// - public event EventHandler EventCommandExecuted + public event EventHandler 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. /// - public event EventHandler EventSourceCreated + public event EventHandler 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. /// - public event EventHandler EventWritten = null!; + public event EventHandler 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(2), null); - return s_EventSources!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_EventSources; } } diff --git a/netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs b/netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs index 3cad6fbf8c4..78d49b1bcc4 100644 --- a/netcore/System.Private.CoreLib/shared/System/Environment.Win32.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Environment.cs b/netcore/System.Private.CoreLib/shared/System/Environment.cs index d99a5a667a6..2b638fde9eb 100644 --- a/netcore/System.Private.CoreLib/shared/System/Environment.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Exception.cs b/netcore/System.Private.CoreLib/shared/System/Exception.cs index cb136451926..80dec57b103 100644 --- a/netcore/System.Private.CoreLib/shared/System/Exception.cs +++ b/netcore/System.Private.CoreLib/shared/System/Exception.cs @@ -166,7 +166,7 @@ namespace System return s; } - protected event EventHandler SerializeObjectState + protected event EventHandler 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/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs b/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs index 8d117ebab16..2e528e69a40 100644 --- a/netcore/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Progress.cs b/netcore/System.Private.CoreLib/shared/System/Progress.cs index 12557da4e97..36095c96c1f 100644 --- a/netcore/System.Private.CoreLib/shared/System/Progress.cs +++ b/netcore/System.Private.CoreLib/shared/System/Progress.cs @@ -56,7 +56,7 @@ namespace System /// Handlers registered with this event will be invoked on the /// captured when the instance was constructed. /// - public event EventHandler ProgressChanged = null!; + public event EventHandler ProgressChanged = null!; // TODO-NULLABLE: Should all events use nullable delegate types? /// Reports a progress change. /// The value of the updated progress. diff --git a/netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs index 69820dea997..0b7a1892191 100644 --- a/netcore/System.Private.CoreLib/shared/System/Reflection/Assembly.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index 35f97023278..3c9ecc3a12e 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs index a916d719fc5..b1a760af8cd 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs +++ b/netcore/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); } /// Adds a key to the table. @@ -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/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs index 4cb70c052e0..e654458cc85 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ContractHelper.cs +++ b/netcore/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. /// - internal static event EventHandler InternalContractFailed; + internal static event EventHandler InternalContractFailed; // TODO-NULLABLE: Should all events use nullable delegate types? /// /// Rewriter will call this method on a contract failure to allow listeners to be notified. diff --git a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs index b251c0b05d5..60fa072752f 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs index 20624990576..33dee03fb84 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/InteropServices/NativeLibrary.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs b/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs index c9526862765..1c19e0971c5 100644 --- a/netcore/System.Private.CoreLib/shared/System/Runtime/Loader/AssemblyLoadContext.cs +++ b/netcore/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 ResolvingUnmanagedDll + public event Func 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 Resolving + public event Func Resolving // TODO-NULLABLE: Should all events use nullable delegate types? { add { @@ -198,7 +198,7 @@ namespace System.Runtime.Loader } } - public event Action Unloading + public event Action 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/netcore/System.Private.CoreLib/shared/System/String.Searching.cs b/netcore/System.Private.CoreLib/shared/System/String.Searching.cs index ab98daf75d5..cce119b1d00 100644 --- a/netcore/System.Private.CoreLib/shared/System/String.Searching.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/StringComparer.cs b/netcore/System.Private.CoreLib/shared/System/StringComparer.cs index ef7281f061d..3774a713dc1 100644 --- a/netcore/System.Private.CoreLib/shared/System/StringComparer.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs index 91226416ab3..0501529bdfb 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs +++ b/netcore/System.Private.CoreLib/shared/System/Text/DecoderBestFitFallback.cs @@ -72,7 +72,7 @@ namespace System.Text object o = new object(); Interlocked.CompareExchange(ref s_InternalSyncObject, o, null); } - return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_InternalSyncObject; } } diff --git a/netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs index aa3f65bfa9b..282baf75907 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/DecoderFallback.cs +++ b/netcore/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(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + s_exceptionFallback ?? Interlocked.CompareExchange(ref s_exceptionFallback, new DecoderExceptionFallback(), null) ?? s_exceptionFallback; // Fallback // diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs index 518ceb7056c..2e9cd69d8c7 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs +++ b/netcore/System.Private.CoreLib/shared/System/Text/EncoderBestFitFallback.cs @@ -72,7 +72,7 @@ namespace System.Text object o = new object(); Interlocked.CompareExchange(ref s_InternalSyncObject, o, null); } - return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_InternalSyncObject; } } diff --git a/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs index 8fa9e6d27a0..fd32a19517e 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs +++ b/netcore/System.Private.CoreLib/shared/System/Text/EncoderFallback.cs @@ -23,7 +23,7 @@ namespace System.Text if (s_replacementFallback == null) Interlocked.CompareExchange(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(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/netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs b/netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs index 4c0bd4a87cd..3927ce6c0e6 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/EncodingTable.cs +++ b/netcore/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(ref s_codePageToCodePageData[index], InternalGetCodePageDataItem(codePage, index), null); diff --git a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs index 81cd160bdc3..6cb56c8f5f1 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs +++ b/netcore/System.Private.CoreLib/shared/System/Text/StringBuilder.cs @@ -644,7 +644,7 @@ namespace System.Text ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumOpCantHappen(); } - return new ReadOnlyMemory(_currentChunk!.m_ChunkChars, 0, _currentChunk.m_ChunkLength); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + return new ReadOnlyMemory(_currentChunk.m_ChunkChars, 0, _currentChunk.m_ChunkLength); } } diff --git a/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs b/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs index 89bd8c58b4b..eccf905a009 100644 --- a/netcore/System.Private.CoreLib/shared/System/Text/UTF8Encoding.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs index 4c1705641da..513f6f05bbb 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/CancellationTokenSource.cs +++ b/netcore/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/netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs b/netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs index 4a80c4f361b..f8fdf6791a9 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs +++ b/netcore/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) } /// @@ -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/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs index bed2f81a912..48a5ee4a069 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs +++ b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs @@ -339,7 +339,7 @@ namespace System.Threading.Tasks } // Create and schedule the future. - Task f = new Task(function!, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task f = new Task(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 f = new Task(function!, state, parent, cancellationToken, creationOptions, internalOptions | InternalTaskOptions.QueuedByRuntime, scheduler); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task f = new Task(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( - 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( - 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 continuationFuture = new ContinuationResultTaskFromResultTask( - 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 continuationFuture = new ContinuationResultTaskFromResultTask( - 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/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs index 904bf531a74..f8db2bac0b2 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs +++ b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs @@ -661,7 +661,7 @@ namespace System.Threading.Tasks // RespectParentCancellation. Task t = new Task(new Action(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 promise = new Task(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 promise = new Task(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 promise = new Task(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 promise = new Task(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; // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + var promise = asyncResult.AsyncState as FromAsyncTrimPromise; 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[] 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 @@ -1631,7 +1631,7 @@ namespace System.Threading.Tasks return starter.ContinueWith( // use a cached delegate GenericDelegateCache.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( // use a cached delegate GenericDelegateCache.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); return ((Func)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); ((Action)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); return ((Func)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)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( // Use a cached delegate GenericDelegateCache.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( // Use a cached delegate GenericDelegateCache.CWAnyActionDelegate, - continuationAction, scheduler!, cancellationToken, continuationOptions); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + continuationAction, scheduler, cancellationToken, continuationOptions); } } } diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs index 6f25d4ccb94..705f196fb7b 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs +++ b/netcore/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 continuationTask = new ContinuationResultTaskFromTask( - 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 continuationTask = new ContinuationResultTaskFromTask( - 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(); - 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 task1 = Task.Factory.StartNew(function!, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task task1 = 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(cancellationToken); // Kick off initial Task, which will call the user-supplied function and yield a Task. - Task?> task1 = Task?>.Factory.StartNew(function!, cancellationToken, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); // TODO-NULLABLE: Remove ! when [DoesNotReturn] respected + Task?> task1 = 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. @@ -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 taskList = new List(); - 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(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> taskList = new List>(); - 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(). @@ -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(tasks); // small optimization in the case of an empty task array Task[] tasksCopy = new Task[taskCount]; @@ -5922,7 +5922,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; } // Delegate the rest to InternalWhenAll() @@ -6081,7 +6081,7 @@ namespace System.Threading.Tasks public static 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 taskList = new List(); - 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/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs index b0c79e61ba4..71a7e22ebdd 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskCompletionSource.cs +++ b/netcore/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 defensiveCopy = new List(); - 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/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs index f79a87ac060..4c7a3c4ea28 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs +++ b/netcore/System.Private.CoreLib/shared/System/Threading/Tasks/TaskScheduler.cs @@ -298,7 +298,7 @@ namespace System.Threading.Tasks Interlocked.CompareExchange(ref s_activeTaskSchedulers, new ConditionalWeakTable(), null); activeTaskSchedulers = s_activeTaskSchedulers; } - activeTaskSchedulers!.Add(this, null); // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + activeTaskSchedulers.Add(this, null); } /// @@ -445,7 +445,7 @@ namespace System.Threading.Tasks /// Each handler is passed a /// instance, which may be used to examine the exception and to mark it as observed. /// - public static event EventHandler UnobservedTaskException; + public static event EventHandler UnobservedTaskException; // TODO-NULLABLE: Should all events use nullable delegate types? //////////////////////////////////////////////////////////// // diff --git a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs b/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs index eeb2f413ce9..28b2e6eb8f5 100644 --- a/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs +++ b/netcore/System.Private.CoreLib/shared/System/Threading/Thread.cs @@ -152,7 +152,7 @@ namespace System.Threading } Interlocked.CompareExchange(ref s_asyncLocalPrincipal, new AsyncLocal(), null); } - s_asyncLocalPrincipal!.Value = value; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + s_asyncLocalPrincipal.Value = value; } } diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZone.cs b/netcore/System.Private.CoreLib/shared/System/TimeZone.cs index 0775e5b1fa0..841ba76132e 100644 --- a/netcore/System.Private.CoreLib/shared/System/TimeZone.cs +++ b/netcore/System.Private.CoreLib/shared/System/TimeZone.cs @@ -42,7 +42,7 @@ namespace System object o = new object(); Interlocked.CompareExchange(ref s_InternalSyncObject, o, null); } - return s_InternalSyncObject!; // TODO-NULLABLE: Remove ! when compiler specially-recognizes CompareExchange for nullability + return s_InternalSyncObject; } } diff --git a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs b/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs index 0ec94702df5..8cff79351c9 100644 --- a/netcore/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs +++ b/netcore/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) { -- 2.11.4.GIT