From b409cb4ad530f2fad224e9083c8dc1c2114f15d1 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 19 Jul 2024 18:06:20 -0400 Subject: [PATCH] Fix nullability warning and address PR feedback --- .../System.Private.CoreLib/src/System/Delegate.CoreCLR.cs | 2 +- .../src/System/MulticastDelegate.CoreCLR.cs | 2 +- .../src/System/Globalization/JapaneseCalendar.Icu.cs | 2 +- .../System.Private.CoreLib/src/System/Threading/Tasks/Task.cs | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs index d1d2b16f38f93..98a8b8d76fb54 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs @@ -156,7 +156,7 @@ public override int GetHashCode() protected virtual MethodInfo GetMethodImpl() { - if ((_methodBase == null) || _methodBase is not MethodInfo) + if (_methodBase is null or not MethodInfo) { IRuntimeMethodInfo method = FindMethodHandle(); RuntimeType? declaringType = RuntimeMethodHandle.GetDeclaringType(method); diff --git a/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.CoreCLR.cs index cdc8ce38ca6de..57eeeea78ea92 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.CoreCLR.cs @@ -515,7 +515,7 @@ protected override MethodInfo GetMethodImpl() { // we handle unmanaged function pointers here because the generic ones (used for WinRT) would otherwise // be treated as open delegates by the base implementation, resulting in failure to get the MethodInfo - if ((_methodBase == null) || _methodBase is not MethodInfo) + if (_methodBase is null or not MethodInfo) { IRuntimeMethodInfo method = FindMethodHandle(); RuntimeType declaringType = RuntimeMethodHandle.GetDeclaringType(method); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs index 3bc7b1862f940..86ac958b0da48 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/JapaneseCalendar.Icu.cs @@ -103,7 +103,7 @@ public partial class JapaneseCalendar : Calendar // Check if we are getting the English Name at the end of the returned list. // ICU usually return long list including all Era names written in Japanese characters except the recent eras which actually we support will be returned in English. // We have the following check as older ICU versions doesn't carry the English names (e.g. ICU version 50). - if (abbrevEnglishEraNames[^1].Length == 0 || abbrevEnglishEraNames[^1][0] > '\u007F') + if (abbrevEnglishEraNames[^1] is { Length: 0 } or [> '\u007F', ..]) { // Couldn't get English names. abbrevEnglishEraNames = s_abbreviatedEnglishEraNames; diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index 2035ea5463ad9..56d8acf0cd8ff 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -3252,7 +3252,8 @@ internal void RecordInternalCancellationRequest(CancellationToken tokenToRecord, if (cancellationException != null) { #if DEBUG - if (cancellationException is not OperationCanceledException oce) + var oce = cancellationException as OperationCanceledException; + if (oce == null) { var edi = cancellationException as ExceptionDispatchInfo; Debug.Assert(edi != null, "Expected either an OCE or an EDI");