Skip to content

Commit 84233f1

Browse files
authored
CoreLib missed Equals nullable annotations (#52167)
* add NotNullWhen attribute
1 parent d49bcbe commit 84233f1

File tree

8 files changed

+16
-10
lines changed

8 files changed

+16
-10
lines changed

src/libraries/System.Private.CoreLib/src/System/DateOnly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Globalization;
6+
using System.Diagnostics.CodeAnalysis;
67

78
namespace System
89
{
@@ -237,7 +238,7 @@ public int CompareTo(object? value)
237238
/// </summary>
238239
/// <param name="value">The object to compare to this instance.</param>
239240
/// <returns>true if value is an instance of DateOnly and equals the value of this instance; otherwise, false.</returns>
240-
public override bool Equals(object? value) => value is DateOnly dateOnly && _dayNumber == dateOnly._dayNumber;
241+
public override bool Equals([NotNullWhen(true)] object? value) => value is DateOnly dateOnly && _dayNumber == dateOnly._dayNumber;
241242

242243
/// <summary>
243244
/// Returns the hash code for this instance.

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Label.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
**
1414
===========================================================*/
1515

16+
using System.Diagnostics.CodeAnalysis;
17+
1618
namespace System.Reflection.Emit
1719
{
1820
// The Label class is an opaque representation of a label used by the
@@ -31,7 +33,7 @@ namespace System.Reflection.Emit
3133

3234
public override int GetHashCode() => m_label;
3335

34-
public override bool Equals(object? obj) =>
36+
public override bool Equals([NotNullWhen(true)] object? obj) =>
3537
obj is Label other && Equals(other);
3638

3739
public bool Equals(Label obj) =>

src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/Opcode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Threading;
5+
using System.Diagnostics.CodeAnalysis;
56

67
namespace System.Reflection.Emit
78
{
@@ -108,7 +109,7 @@ public string? Name
108109
}
109110
}
110111

111-
public override bool Equals(object? obj) =>
112+
public override bool Equals([NotNullWhen(true)] object? obj) =>
112113
obj is OpCode other && Equals(other);
113114

114115
public bool Equals(OpCode obj) => obj.Value == Value;

src/libraries/System.Private.CoreLib/src/System/Reflection/Pointer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Runtime.Serialization;
6+
using System.Diagnostics.CodeAnalysis;
67

78
namespace System.Reflection
89
{
@@ -39,7 +40,7 @@ public static object Box(void* ptr, Type type)
3940
return ((Pointer)ptr)._ptr;
4041
}
4142

42-
public override unsafe bool Equals(object? obj)
43+
public override unsafe bool Equals([NotNullWhen(true)] object? obj)
4344
{
4445
if (obj is Pointer pointer)
4546
{

src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Diagnostics;
55
using System.Globalization;
6+
using System.Diagnostics.CodeAnalysis;
67

78
namespace System
89
{
@@ -307,7 +308,7 @@ public int CompareTo(object? value)
307308
/// </summary>
308309
/// <param name="value">The object to compare to this instance.</param>
309310
/// <returns>true if value is an instance of TimeOnly and equals the value of this instance; otherwise, false.</returns>
310-
public override bool Equals(object? value) => value is TimeOnly timeOnly && _ticks == timeOnly._ticks;
311+
public override bool Equals([NotNullWhen(true)] object? value) => value is TimeOnly timeOnly && _ticks == timeOnly._ticks;
311312

312313
/// <summary>
313314
/// Returns the hash code for this instance.

src/libraries/System.Reflection.Emit.ILGeneration/ref/System.Reflection.Emit.ILGeneration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public virtual void UsingNamespace(string usingNamespace) { }
5959
public readonly partial struct Label : System.IEquatable<System.Reflection.Emit.Label>
6060
{
6161
private readonly int _dummyPrimitive;
62-
public override bool Equals(object? obj) { throw null; }
62+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
6363
public bool Equals(System.Reflection.Emit.Label obj) { throw null; }
6464
public override int GetHashCode() { throw null; }
6565
public static bool operator ==(System.Reflection.Emit.Label a, System.Reflection.Emit.Label b) { throw null; }

src/libraries/System.Reflection.Primitives/ref/System.Reflection.Primitives.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public enum FlowControl
3030
public System.Reflection.Emit.StackBehaviour StackBehaviourPop { get { throw null; } }
3131
public System.Reflection.Emit.StackBehaviour StackBehaviourPush { get { throw null; } }
3232
public short Value { get { throw null; } }
33-
public override bool Equals(object? obj) { throw null; }
33+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
3434
public bool Equals(System.Reflection.Emit.OpCode obj) { throw null; }
3535
public override int GetHashCode() { throw null; }
3636
public static bool operator ==(System.Reflection.Emit.OpCode a, System.Reflection.Emit.OpCode b) { throw null; }

src/libraries/System.Runtime/ref/System.Runtime.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ public static partial class Convert
13281328
public int CompareTo(System.DateOnly value) { throw null; }
13291329
public int CompareTo(object? value) { throw null; }
13301330
public bool Equals(System.DateOnly value) { throw null; }
1331-
public override bool Equals(object? value) { throw null; }
1331+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
13321332
public override int GetHashCode() { throw null; }
13331333
public static System.DateOnly Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; }
13341334
public static System.DateOnly ParseExact(System.ReadOnlySpan<char> s, System.ReadOnlySpan<char> format, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; }
@@ -3845,7 +3845,7 @@ public ThreadStaticAttribute() { }
38453845
public int CompareTo(System.TimeOnly value) { throw null; }
38463846
public int CompareTo(object? value) { throw null; }
38473847
public bool Equals(System.TimeOnly value) { throw null; }
3848-
public override bool Equals(object? value) { throw null; }
3848+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
38493849
public override int GetHashCode() { throw null; }
38503850
public static System.TimeOnly Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; }
38513851
public static System.TimeOnly ParseExact(System.ReadOnlySpan<char> s, System.ReadOnlySpan<char> format, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; }
@@ -8842,7 +8842,7 @@ internal Pointer() { }
88428842
public unsafe static object Box(void* ptr, System.Type type) { throw null; }
88438843
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
88448844
public unsafe static void* Unbox(object ptr) { throw null; }
8845-
public override bool Equals(object? obj) { throw null; }
8845+
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
88468846
public override int GetHashCode() { throw null; }
88478847
}
88488848
[System.FlagsAttribute]

0 commit comments

Comments
 (0)