From fd8ba69119e37b762acb0d3583394b90c29a82d7 Mon Sep 17 00:00:00 2001 From: Manuel de la Pena Date: Sun, 26 Sep 2021 21:01:53 -0400 Subject: [PATCH] [Foundation] Remove warning due to the Equals accepting a null value. Removes the following warning during the builds: ``` warning CS8767: Nullability of reference types in type of parameter 'host' of 'bool NSHost.Equals(NSHost host)' doesn't match implicitly implemented member 'bool IEquatable.Equals(NSHost? other)' (possibly because of nullability attributes) ``` Test was added to ensure that we did not throw an exception. --- src/foundation.cs | 2 +- tests/monotouch-test/Foundation/NSHostTest.cs | 22 +++++++++++++++++++ tests/xtro-sharpie/macOS-Foundation.ignore | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/monotouch-test/Foundation/NSHostTest.cs diff --git a/src/foundation.cs b/src/foundation.cs index 4518599ce784..b70d2b66f2ef 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -13775,7 +13775,7 @@ partial interface NSHost { NSHost _FromAddress (string address); [Export ("isEqualToHost:")] - bool Equals (NSHost host); + bool Equals ([NullAllowed] NSHost host); [Export ("name")] string Name { get; } diff --git a/tests/monotouch-test/Foundation/NSHostTest.cs b/tests/monotouch-test/Foundation/NSHostTest.cs new file mode 100644 index 000000000000..ec9368072fa6 --- /dev/null +++ b/tests/monotouch-test/Foundation/NSHostTest.cs @@ -0,0 +1,22 @@ +#if __MACOS__ +using System; +using System.Collections; +using System.Collections.Generic; + +using NUnit.Framework; + +using Foundation; + +#nullable enable + +namespace MonoTouchFixtures.Foundation { + public class NSHostTest { + + public void EqualsNullAllowed () + { + using var host = NSHost.FromAddress ("http://microsoft.com"); + Assert.False (host.Equals (null)); + } + } +} +#endif diff --git a/tests/xtro-sharpie/macOS-Foundation.ignore b/tests/xtro-sharpie/macOS-Foundation.ignore index ab74c230b79f..f3e410f800e9 100644 --- a/tests/xtro-sharpie/macOS-Foundation.ignore +++ b/tests/xtro-sharpie/macOS-Foundation.ignore @@ -834,3 +834,6 @@ !missing-null-allowed! 'System.Void Foundation.NSUserNotification::set_Subtitle(System.String)' is missing an [NullAllowed] on parameter #0 !missing-null-allowed! 'System.Void Foundation.NSUserNotification::set_Title(System.String)' is missing an [NullAllowed] on parameter #0 !missing-null-allowed! 'System.Void Foundation.NSUserNotification::set_UserInfo(Foundation.NSDictionary)' is missing an [NullAllowed] on parameter #0 + +# added because the method does the right thing yet it was not marked by apple, there is a test for it +!extra-null-allowed! 'System.Boolean Foundation.NSHost::Equals(Foundation.NSHost)' has a extraneous [NullAllowed] on parameter #0