Skip to content

Handle left Token being null in == and !=. #1802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/System.CommandLine/Parsing/Token.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace System.CommandLine.Parsing
/// <summary>
/// A unit of significant text on the command line.
/// </summary>
public class Token : IEquatable<Token>
public sealed class Token : IEquatable<Token>
{
internal const int ImplicitPosition = -1;

Expand Down Expand Up @@ -66,14 +66,14 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position)
/// <param name="left">The first <see cref="Token"/>.</param>
/// <param name="right">The second <see cref="Token"/>.</param>
/// <returns><see langword="true" /> if the objects are equal.</returns>
public static bool operator ==(Token left, Token right) => left.Equals(right);
public static bool operator ==(Token left, Token right) => left?.Equals(right) ?? right is null;

/// <summary>
/// Checks if two specified <see cref="Token"/> instances have different values.
/// </summary>
/// <param name="left">The first <see cref="Token"/>.</param>
/// <param name="right">The second <see cref="Token"/>.</param>
/// <returns><see langword="true" /> if the objects are not equal.</returns>
public static bool operator !=(Token left, Token right) => !left.Equals(right);
public static bool operator !=(Token left, Token right) => !(left == right);
}
}