Skip to content

Commit 1d98a75

Browse files
vlada-shubinajonsequitur
authored andcommitted
fixed null reference exception in Token operator overload
1 parent eda3d19 commit 1d98a75

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/System.CommandLine/Parsing/Token.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position)
6666
/// <param name="left">The first <see cref="Token"/>.</param>
6767
/// <param name="right">The second <see cref="Token"/>.</param>
6868
/// <returns><see langword="true" /> if the objects are equal.</returns>
69-
public static bool operator ==(Token left, Token right) => left.Equals(right);
69+
public static bool operator ==(Token? left, Token? right) => left is null ? right is null : left.Equals(right);
7070

7171
/// <summary>
7272
/// Checks if two specified <see cref="Token"/> instances have different values.
7373
/// </summary>
7474
/// <param name="left">The first <see cref="Token"/>.</param>
7575
/// <param name="right">The second <see cref="Token"/>.</param>
7676
/// <returns><see langword="true" /> if the objects are not equal.</returns>
77-
public static bool operator !=(Token left, Token right) => !left.Equals(right);
77+
public static bool operator !=(Token? left, Token? right) => left is null ? right is not null : !left.Equals(right);
78+
7879
}
7980
}

0 commit comments

Comments
 (0)