From 1654f4ec4d7094dd8c062cbac9f4eb4026157721 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 1 May 2021 23:35:40 +0300 Subject: [PATCH 1/2] add NotNullWhen attribute --- .../ref/System.Collections.Immutable.cs | 2 +- .../System/Collections/Immutable/ImmutableArray_1.Minimal.cs | 2 +- .../ref/System.Collections.Specialized.cs | 4 ++-- .../src/System/Collections/Specialized/BitVector32.cs | 4 ++-- .../System/Collections/Generic/SortedSetEqualityComparer.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs b/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs index f050f59517d5e0..2da1db4d2828f4 100644 --- a/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs +++ b/src/libraries/System.Collections.Immutable/ref/System.Collections.Immutable.cs @@ -143,7 +143,7 @@ public void CopyTo(int sourceIndex, T[] destination, int destinationIndex, int l public void CopyTo(T[] destination) { } public void CopyTo(T[] destination, int destinationIndex) { } public bool Equals(System.Collections.Immutable.ImmutableArray other) { throw null; } - public override bool Equals(object? obj) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; } public System.Collections.Immutable.ImmutableArray.Enumerator GetEnumerator() { throw null; } public override int GetHashCode() { throw null; } public int IndexOf(T item) { throw null; } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Minimal.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Minimal.cs index 31e093c67b7e13..a2294fcc22b326 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Minimal.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableArray_1.Minimal.cs @@ -306,7 +306,7 @@ public override int GetHashCode() /// /// true if the specified is equal to this instance; otherwise, false. /// - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { return obj is IImmutableArray other && this.array == other.Array; } diff --git a/src/libraries/System.Collections.Specialized/ref/System.Collections.Specialized.cs b/src/libraries/System.Collections.Specialized/ref/System.Collections.Specialized.cs index 82d3c5b0b0c856..f4da000b1c04cc 100644 --- a/src/libraries/System.Collections.Specialized/ref/System.Collections.Specialized.cs +++ b/src/libraries/System.Collections.Specialized/ref/System.Collections.Specialized.cs @@ -18,7 +18,7 @@ public partial struct BitVector32 public static int CreateMask(int previous) { throw null; } public static System.Collections.Specialized.BitVector32.Section CreateSection(short maxValue) { throw null; } public static System.Collections.Specialized.BitVector32.Section CreateSection(short maxValue, System.Collections.Specialized.BitVector32.Section previous) { throw null; } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public override string ToString() { throw null; } public static string ToString(System.Collections.Specialized.BitVector32 value) { throw null; } @@ -28,7 +28,7 @@ public readonly partial struct Section public short Mask { get { throw null; } } public short Offset { get { throw null; } } public bool Equals(System.Collections.Specialized.BitVector32.Section obj) { throw null; } - public override bool Equals(object? o) { throw null; } + public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? o) { throw null; } public override int GetHashCode() { throw null; } public static bool operator ==(System.Collections.Specialized.BitVector32.Section a, System.Collections.Specialized.BitVector32.Section b) { throw null; } public static bool operator !=(System.Collections.Specialized.BitVector32.Section a, System.Collections.Specialized.BitVector32.Section b) { throw null; } diff --git a/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs b/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs index 9ffd7f1d9930bc..eb1da95abcf747 100644 --- a/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs +++ b/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs @@ -184,7 +184,7 @@ private static Section CreateSectionHelper(short maxValue, short priorMask, shor return new Section(CreateMaskFromHighValue(maxValue), offset); } - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { if (!(o is BitVector32)) { @@ -253,7 +253,7 @@ public short Offset } } - public override bool Equals(object? o) + public override bool Equals([NotNullWhen(true)] object? o) { if (o is Section) return Equals((Section)o); diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs index ffc0b8bafd2731..e39a1ad7e6890a 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs @@ -47,7 +47,7 @@ public int GetHashCode(SortedSet obj) } // Equals method for the comparer itself. - public override bool Equals(object? obj) + public override bool Equals([NotNullWhen(true)] object? obj) { SortedSetEqualityComparer? comparer = obj as SortedSetEqualityComparer; return comparer != null && _comparer == comparer._comparer; From e6c32b798b1818e40c3df79c7eb8b1492c946348 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sat, 1 May 2021 23:36:58 +0300 Subject: [PATCH 2/2] add usings --- .../src/System/Collections/Specialized/BitVector32.cs | 1 + .../src/System/Collections/Generic/SortedSetEqualityComparer.cs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs b/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs index eb1da95abcf747..12853ebe3622d4 100644 --- a/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs +++ b/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/BitVector32.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Text; +using System.Diagnostics.CodeAnalysis; namespace System.Collections.Specialized { diff --git a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs index e39a1ad7e6890a..62b4dfefd1d7d5 100644 --- a/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs +++ b/src/libraries/System.Collections/src/System/Collections/Generic/SortedSetEqualityComparer.cs @@ -1,6 +1,8 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace System.Collections.Generic { ///