Skip to content

Commit

Permalink
CoreLib missed Equals nullable annotations (#52167)
Browse files Browse the repository at this point in the history
* add NotNullWhen attribute
  • Loading branch information
hrrrrustic authored May 20, 2021
1 parent d49bcbe commit 84233f1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/libraries/System.Private.CoreLib/src/System/DateOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;

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

/// <summary>
/// Returns the hash code for this instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
**
===========================================================*/

using System.Diagnostics.CodeAnalysis;

namespace System.Reflection.Emit
{
// The Label class is an opaque representation of a label used by the
Expand All @@ -31,7 +33,7 @@ namespace System.Reflection.Emit

public override int GetHashCode() => m_label;

public override bool Equals(object? obj) =>
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is Label other && Equals(other);

public bool Equals(Label obj) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading;
using System.Diagnostics.CodeAnalysis;

namespace System.Reflection.Emit
{
Expand Down Expand Up @@ -108,7 +109,7 @@ public string? Name
}
}

public override bool Equals(object? obj) =>
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is OpCode other && Equals(other);

public bool Equals(OpCode obj) => obj.Value == Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Runtime.Serialization;
using System.Diagnostics.CodeAnalysis;

namespace System.Reflection
{
Expand Down Expand Up @@ -39,7 +40,7 @@ public static object Box(void* ptr, Type type)
return ((Pointer)ptr)._ptr;
}

public override unsafe bool Equals(object? obj)
public override unsafe bool Equals([NotNullWhen(true)] object? obj)
{
if (obj is Pointer pointer)
{
Expand Down
3 changes: 2 additions & 1 deletion src/libraries/System.Private.CoreLib/src/System/TimeOnly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics;
using System.Globalization;
using System.Diagnostics.CodeAnalysis;

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

/// <summary>
/// Returns the hash code for this instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public virtual void UsingNamespace(string usingNamespace) { }
public readonly partial struct Label : System.IEquatable<System.Reflection.Emit.Label>
{
private readonly int _dummyPrimitive;
public override bool Equals(object? obj) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public bool Equals(System.Reflection.Emit.Label obj) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Reflection.Emit.Label a, System.Reflection.Emit.Label b) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum FlowControl
public System.Reflection.Emit.StackBehaviour StackBehaviourPop { get { throw null; } }
public System.Reflection.Emit.StackBehaviour StackBehaviourPush { get { throw null; } }
public short Value { get { throw null; } }
public override bool Equals(object? obj) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public bool Equals(System.Reflection.Emit.OpCode obj) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Reflection.Emit.OpCode a, System.Reflection.Emit.OpCode b) { throw null; }
Expand Down
6 changes: 3 additions & 3 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ public static partial class Convert
public int CompareTo(System.DateOnly value) { throw null; }
public int CompareTo(object? value) { throw null; }
public bool Equals(System.DateOnly value) { throw null; }
public override bool Equals(object? value) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.DateOnly Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; }
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; }
Expand Down Expand Up @@ -3845,7 +3845,7 @@ public ThreadStaticAttribute() { }
public int CompareTo(System.TimeOnly value) { throw null; }
public int CompareTo(object? value) { throw null; }
public bool Equals(System.TimeOnly value) { throw null; }
public override bool Equals(object? value) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? value) { throw null; }
public override int GetHashCode() { throw null; }
public static System.TimeOnly Parse(System.ReadOnlySpan<char> s, System.IFormatProvider? provider = default, System.Globalization.DateTimeStyles style = System.Globalization.DateTimeStyles.None) { throw null; }
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; }
Expand Down Expand Up @@ -8842,7 +8842,7 @@ internal Pointer() { }
public unsafe static object Box(void* ptr, System.Type type) { throw null; }
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public unsafe static void* Unbox(object ptr) { throw null; }
public override bool Equals(object? obj) { throw null; }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
public override int GetHashCode() { throw null; }
}
[System.FlagsAttribute]
Expand Down

0 comments on commit 84233f1

Please sign in to comment.