Remove stale nullable !s and pragmas (#25640)
authorStephen Toub <stoub@microsoft.com>
Thu, 11 Jul 2019 17:05:51 +0000 (13:05 -0400)
committerGitHub <noreply@github.com>
Thu, 11 Jul 2019 17:05:51 +0000 (13:05 -0400)
Also update TODO-NULLABLE comments to be more specific where appropriate.

29 files changed:
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile.cs
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.CreateFile2.cs
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.FindFirstFileEx.cs
src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetFileAttributesEx.cs
src/System.Private.CoreLib/shared/System/AppDomain.cs
src/System.Private.CoreLib/shared/System/Collections/Concurrent/ConcurrentQueueSegment.cs
src/System.Private.CoreLib/shared/System/Collections/Generic/Dictionary.cs
src/System.Private.CoreLib/shared/System/Collections/Generic/EqualityComparer.cs
src/System.Private.CoreLib/shared/System/Collections/Generic/List.cs
src/System.Private.CoreLib/shared/System/Collections/ListDictionaryInternal.cs
src/System.Private.CoreLib/shared/System/Environment.Win32.cs
src/System.Private.CoreLib/shared/System/Globalization/CultureData.Windows.cs
src/System.Private.CoreLib/shared/System/Globalization/TextElementEnumerator.cs
src/System.Private.CoreLib/shared/System/Resources/ResourceReader.cs
src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs
src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConditionalWeakTable.cs
src/System.Private.CoreLib/shared/System/Threading/AsyncLocal.cs
src/System.Private.CoreLib/shared/System/Threading/LazyInitializer.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/Future.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/FutureFactory.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/Sources/ManualResetValueTaskSourceCore.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/Task.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs
src/System.Private.CoreLib/shared/System/Threading/ThreadLocal.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.Unix.cs
src/System.Private.CoreLib/shared/System/TimeZoneInfo.Win32.cs
src/System.Private.CoreLib/src/System/Runtime/InteropServices/ComEventsMethod.cs
src/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
src/System.Private.CoreLib/src/System/Utf8String.Construction.cs

index de68a36..b1589ac 100644 (file)
@@ -33,7 +33,7 @@ internal partial class Interop
             int dwFlagsAndAttributes,
             IntPtr hTemplateFile)
         {
-            lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
             return CreateFilePrivate(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
         }
     }
index 49e7485..82d62cc 100644 (file)
@@ -26,7 +26,7 @@ internal partial class Interop
             FileMode dwCreationDisposition,
             ref Kernel32.CREATEFILE2_EXTENDED_PARAMETERS pCreateExParams)
         {
-            lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            lpFileName = PathInternal.EnsureExtendedPrefixIfNeeded(lpFileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
             return CreateFile2Private(lpFileName, dwDesiredAccess, dwShareMode, dwCreationDisposition, ref pCreateExParams);
         }
     }
index 52dcd54..7d5203d 100644 (file)
@@ -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 nullable attributes are respected
+            fileName = PathInternal.EnsureExtendedPrefixIfNeeded(fileName)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
 
             // 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);
index e3f18fe..65649e4 100644 (file)
@@ -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 nullable attributes are respected
+            name = PathInternal.EnsureExtendedPrefixIfNeeded(name)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
             return GetFileAttributesExPrivate(name, fileInfoLevel, ref lpFileInformation);
         }
     }
index 2d8cd9c..88856a5 100644 (file)
@@ -409,7 +409,7 @@ namespace System
                                 (Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>)));
                         }
 
-                        principal = s_getUnauthenticatedPrincipal!(); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                        principal = s_getUnauthenticatedPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
                         break;
 
                     case PrincipalPolicy.WindowsPrincipal:
@@ -425,7 +425,7 @@ namespace System
                                 (Func<IPrincipal>)mi.CreateDelegate(typeof(Func<IPrincipal>)));
                         }
 
-                        principal = s_getWindowsPrincipal!(); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                        principal = s_getWindowsPrincipal!(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
                         break;
                 }
             }
index fcf0539..9c0501d 100644 (file)
@@ -166,7 +166,7 @@ namespace System.Collections.Concurrent
                             // If we're preserving, though, we don't zero out the slot, as we need it for
                             // enumerations, peeking, ToArray, etc.  And we don't update the sequence number,
                             // so that an enqueuer will see it as full and be forced to move to a new segment.
-                            slots[slotsIndex].Item = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                            slots[slotsIndex].Item = default;
                             Volatile.Write(ref slots[slotsIndex].SequenceNumber, currentHead + slots.Length);
                         }
                         return true;
index 181e2d2..a10bb89 100644 (file)
@@ -1411,7 +1411,7 @@ namespace System.Collections.Generic
                     _dictionary = dictionary;
                     _version = dictionary._version;
                     _index = 0;
-                    _currentKey = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    _currentKey = default;
                 }
 
                 public void Dispose()
@@ -1437,7 +1437,7 @@ namespace System.Collections.Generic
                     }
 
                     _index = _dictionary._count + 1;
-                    _currentKey = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    _currentKey = default;
                     return false;
                 }
 
@@ -1464,7 +1464,7 @@ namespace System.Collections.Generic
                     }
 
                     _index = 0;
-                    _currentKey = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    _currentKey = default;
                 }
             }
         }
@@ -1594,7 +1594,7 @@ namespace System.Collections.Generic
                     _dictionary = dictionary;
                     _version = dictionary._version;
                     _index = 0;
-                    _currentValue = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    _currentValue = default;
                 }
 
                 public void Dispose()
@@ -1619,7 +1619,7 @@ namespace System.Collections.Generic
                         }
                     }
                     _index = _dictionary._count + 1;
-                    _currentValue = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    _currentValue = default;
                     return false;
                 }
 
@@ -1645,7 +1645,7 @@ namespace System.Collections.Generic
                         ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion();
                     }
                     _index = 0;
-                    _currentValue = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    _currentValue = default;
                 }
             }
         }
index d62d03b..bf4fbe1 100644 (file)
@@ -17,9 +17,7 @@ namespace System.Collections.Generic
         public abstract bool Equals([AllowNull] T x, [AllowNull] T y);
         public abstract int GetHashCode([DisallowNull] T obj);
 
-#pragma warning disable CS8617 // TODO-NULLABLE: Covariance in interfaces (https://github.com/dotnet/roslyn/issues/35227)
         int IEqualityComparer.GetHashCode(object? obj)
-#pragma warning restore CS8617
         {
             if (obj == null) return 0;
             if (obj is T) return GetHashCode((T)obj);
index 4a27224..5e13e3e 100644 (file)
@@ -1092,7 +1092,7 @@ namespace System.Collections.Generic
                 _list = list;
                 _index = 0;
                 _version = list._version;
-                _current = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                _current = default;
             }
 
             public void Dispose()
@@ -1120,7 +1120,7 @@ namespace System.Collections.Generic
                 }
 
                 _index = _list._size + 1;
-                _current = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                _current = default;
                 return false;
             }
 
@@ -1146,7 +1146,7 @@ namespace System.Collections.Generic
                 }
 
                 _index = 0;
-                _current = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                _current = default;
             }
         }
     }
index 7fd1614..3493970 100644 (file)
@@ -283,9 +283,7 @@ namespace System.Collections
                 current = null;
             }
 
-#pragma warning disable CS8612 // TODO-NULLABLE: Covariance in interfaces (https://github.com/dotnet/roslyn/issues/35227)
             public object Current
-#pragma warning restore CS8612
             {
                 get
                 {
index d536f5c..3cad6fb 100644 (file)
@@ -80,7 +80,7 @@ namespace System
                 {
                     foreach (string name in environmentKey.GetValueNames())
                     {
-                        string? value = environmentKey.GetValue(name, "")!.ToString(); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                        string? value = environmentKey.GetValue(name, "")!.ToString(); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
                         try
                         {
                             results.Add(name, value);
index 28315b9..8d117eb 100644 (file)
@@ -432,7 +432,7 @@ namespace System.Globalization
             {
                 for (int i = 0; i < array.Length; i++)
                 {
-                    array[i] = ReescapeWin32String(array[i])!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    array[i] = ReescapeWin32String(array[i])!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
                 }
             }
 
index 48437f3..60d2a10 100644 (file)
@@ -50,9 +50,7 @@ namespace System.Globalization
             return true;
         }
 
-#pragma warning disable CS8612 // TODO-NULLABLE: Covariance in interfaces (https://github.com/dotnet/roslyn/issues/35227)
         public object Current => GetTextElement();
-#pragma warning restore CS8612
 
         public string GetTextElement()
         {
index 274f163..55b6d77 100644 (file)
@@ -1030,9 +1030,7 @@ namespace System.Resources
                 }
             }
 
-#pragma warning disable CS8612 // TODO-NULLABLE: Covariance in interfaces (https://github.com/dotnet/roslyn/issues/35227)
             public object Current => Entry;
-#pragma warning restore CS8612
 
             // Warning: This requires that you call the Key or Entry property FIRST before calling it!
             internal int DataPosition => _dataPosition;
index fd66c18..35f9702 100644 (file)
@@ -315,7 +315,7 @@ namespace System.Runtime.CompilerServices
     {
 #if !PROJECTN
         /// <summary>A cached task for default(TResult).</summary>
-        internal readonly static Task<TResult> s_defaultResultTask = AsyncTaskCache.CreateCacheableTask(default(TResult)!); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+        internal readonly static Task<TResult> s_defaultResultTask = AsyncTaskCache.CreateCacheableTask<TResult>(default);
 #endif
 
         /// <summary>The lazily-initialized built task.</summary>
index 4c346ff..a916d71 100644 (file)
@@ -339,7 +339,7 @@ namespace System.Runtime.CompilerServices
                                 _currentIndex++;
                                 if (c.TryGetEntry(_currentIndex, out TKey? key, out TValue value))
                                 {
-                                    _current = new KeyValuePair<TKey, TValue>(key!, value); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                                    _current = new KeyValuePair<TKey, TValue>(key, value);
                                     return true;
                                 }
                             }
index cf279ac..e21e14e 100644 (file)
@@ -63,7 +63,7 @@ namespace System.Threading
             get
             {
                 object? obj = ExecutionContext.GetLocalValue(this);
-                return (obj == null) ? default! : (T)obj; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                return (obj == null) ? default : (T)obj;
             }
             set
             {
index 0ee21a2..4a80c4f 100644 (file)
@@ -272,7 +272,7 @@ namespace System.Threading
                 }
             }
 
-            return target!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            return target!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
         }
 
         /// <summary>
index 1a7899d..bed2f81 100644 (file)
@@ -62,7 +62,7 @@ namespace System.Threading.Tasks
     public class Task<TResult> : Task
     {
         // The value itself, if set.
-        [MaybeNull] internal TResult m_result = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+        [MaybeNull] internal TResult m_result = default!;
 
         private static readonly TaskFactory<TResult> s_Factory = new TaskFactory<TResult>();
 
index 6464676..904bf53 100644 (file)
@@ -1324,7 +1324,7 @@ namespace System.Threading.Tasks
         {
             TaskCreationOptions tco;
             Task.CreationOptionsFromContinuationOptions(continuationOptions, out tco, out _);
-            return new Task<TResult>(true, default!, tco, ct); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            return new Task<TResult>(true, default, tco, ct);
         }
 
         //
index e72328a..a773749 100644 (file)
@@ -48,7 +48,7 @@ namespace System.Threading.Tasks.Sources
             // Reset/update state for the next use/await of this instance.
             _version++;
             _completed = false;
-            _result = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            _result = default;
             _error = null;
             _executionContext = null;
             _capturedContext = null;
index 135f588..6f25d4c 100644 (file)
@@ -5208,7 +5208,7 @@ namespace System.Threading.Tasks
         {
             if (!cancellationToken.IsCancellationRequested)
                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.cancellationToken);
-            return new Task<TResult>(true, default!, TaskCreationOptions.None, cancellationToken); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            return new Task<TResult>(true, default, TaskCreationOptions.None, cancellationToken);
         }
 
         /// <summary>Creates a <see cref="Task"/> that's completed due to cancellation with the specified exception.</summary>
@@ -6694,7 +6694,7 @@ namespace System.Threading.Tasks
                     if (Task.s_asyncDebuggingEnabled)
                         RemoveFromActiveTasks(this);
 
-                    result = TrySetResult(taskTResult != null ? taskTResult.Result : default!); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    result = TrySetResult(taskTResult != null ? taskTResult.Result : default);
                     break;
             }
             return result;
index cfb8040..7ffb4bb 100644 (file)
@@ -449,7 +449,7 @@ namespace System.Threading.Tasks
 
             _obj = task;
 
-            _result = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            _result = default;
             _continueOnCapturedContext = true;
             _token = 0;
         }
@@ -468,7 +468,7 @@ namespace System.Threading.Tasks
             _obj = source;
             _token = token;
 
-            _result = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            _result = default;
             _continueOnCapturedContext = true;
         }
 
index 1126ea3..8e8506f 100644 (file)
@@ -202,7 +202,7 @@ namespace System.Threading
 
                     // And clear the references from the slot table to the linked slot and the value so that
                     // both can get garbage collected.
-                    slotArray[id].Value!._value = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    slotArray[id].Value!._value = default;
                     slotArray[id].Value = null;
                 }
             }
@@ -675,7 +675,7 @@ namespace System.Threading
             internal volatile LinkedSlotVolatile[]? _slotArray;
 
             // The value for this slot.
-            [AllowNull, MaybeNull] internal T _value = default!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            [AllowNull, MaybeNull] internal T _value = default;
         }
 
         /// <summary>
index f5faca7..b04ae34 100644 (file)
@@ -396,7 +396,7 @@ namespace System
             if (symlinkPath != null)
             {
                 // symlinkPath can be relative path, use Path to get the full absolute path.
-                symlinkPath = Path.GetFullPath(symlinkPath, Path.GetDirectoryName(tzFilePath)!); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                symlinkPath = Path.GetFullPath(symlinkPath, Path.GetDirectoryName(tzFilePath)!);
 
                 string timeZoneDirectory = GetTimeZoneDirectory();
                 if (symlinkPath.StartsWith(timeZoneDirectory, StringComparison.Ordinal))
index e1cfe4e..0ec9470 100644 (file)
@@ -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 nullable attributes are respected
-                    int last = (int)dynamicKey.GetValue(LastEntryValue, -1)!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                    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
 
                     if (first == -1 || last == -1 || first > last)
                     {
index b8a6dd8..9968020 100644 (file)
@@ -173,7 +173,7 @@ namespace System.Runtime.InteropServices
                 {
                     if (wrapper.Delegate.GetType() == d.GetType())
                     {
-                        wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d)!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                        wrapper.Delegate = Delegate.Combine(wrapper.Delegate, d)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
                         return;
                     }
                 }
index c2f1bf3..8ceeb93 100644 (file)
@@ -99,7 +99,7 @@ namespace System.Runtime.Loader
             _assemblyPaths = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
             foreach (string assemblyPath in assemblyPaths)
             {
-                _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath)!, assemblyPath); // TODO-NULLABLE: Remove ! when nullable attributes are respected
+                _assemblyPaths.Add(Path.GetFileNameWithoutExtension(assemblyPath)!, assemblyPath); // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
             }
 
             _nativeSearchPaths = SplitPathsList(nativeSearchPathsList);
index c448b5b..18988b7 100644 (file)
@@ -49,7 +49,7 @@ namespace System
 
             Utf8String newString = FastAllocate(value.Length);
             Buffer.Memmove(ref newString.DangerousGetMutableReference(), ref MemoryMarshal.GetReference(value), (uint)value.Length);
-            return Utf8Utility.ValidateAndFixupUtf8String(newString)!; // TODO-NULLABLE: Remove ! when nullable attributes are respected
+            return Utf8Utility.ValidateAndFixupUtf8String(newString)!; // TODO-NULLABLE: Remove ! when [NotNullIfNotNull] respected
         }
 
         /// <summary>