From 404bcf3693f4ce4da571ff6816e65cbd3471e7c8 Mon Sep 17 00:00:00 2001 From: Vlada Shubina Date: Mon, 5 Sep 2022 11:50:28 +0200 Subject: [PATCH] fixed null reference exception in Token operator overload --- src/System.CommandLine/Parsing/Token.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/System.CommandLine/Parsing/Token.cs b/src/System.CommandLine/Parsing/Token.cs index 7b656c9886..9fae4842ac 100644 --- a/src/System.CommandLine/Parsing/Token.cs +++ b/src/System.CommandLine/Parsing/Token.cs @@ -66,7 +66,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// The first . /// The second . /// if the objects are equal. - public static bool operator ==(Token left, Token right) => left.Equals(right); + public static bool operator ==(Token? left, Token? right) => left is null ? right is null : left.Equals(right); /// /// Checks if two specified instances have different values. @@ -74,6 +74,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// The first . /// The second . /// if the objects are not equal. - public static bool operator !=(Token left, Token right) => !left.Equals(right); + public static bool operator !=(Token? left, Token? right) => left is null ? right is not null : !left.Equals(right); + } }