From bce7fa15950b099aa1780f939b2600b6167fdf37 Mon Sep 17 00:00:00 2001 From: Earl Robsham Date: Fri, 30 May 2025 13:02:42 -0400 Subject: [PATCH] Bring `-compare:` implementations inline with macos updates the implementation of `-compare:` vs a `nil` argument to return the same results as the same code running on macos (output from a sample program on macos): ``` NSString 'compare:' nil arg: NSOrderedDescending NSDate 'compare:' nil arg: NSOrderedSame NSNumber 'compare:' nil arg: exceptions `-[__NSCFNumber compare:]: nil argument` ``` --- Source/GSString.m | 12 +++--------- Source/NSDate.m | 3 +-- Source/NSString.m | 3 +-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Source/GSString.m b/Source/GSString.m index c7c185e574..b907905af4 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -3662,9 +3662,7 @@ - (NSComparisonResult) compare: (NSString*)aString } GS_RANGE_CHECK(aRange, _count); if (aString == nil) - [NSException raise: NSInvalidArgumentException - format: @"[%@ -%@] nil string argument", - NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; + return NSOrderedDescending; if (GSObjCIsInstance(aString) == NO) [NSException raise: NSInvalidArgumentException format: @"[%@ -%@] not a string argument", @@ -4041,9 +4039,7 @@ - (NSComparisonResult) compare: (NSString*)aString } GS_RANGE_CHECK(aRange, _count); if (aString == nil) - [NSException raise: NSInvalidArgumentException - format: @"[%@ -%@] nil string argument", - NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; + return NSOrderedDescending; if (GSObjCIsInstance(aString) == NO) [NSException raise: NSInvalidArgumentException format: @"[%@ -%@] not a string argument", @@ -4497,9 +4493,7 @@ - (NSComparisonResult) compare: (NSString*)aString } GS_RANGE_CHECK(aRange, _count); if (aString == nil) - [NSException raise: NSInvalidArgumentException - format: @"[%@ -%@] nil string argument", - NSStringFromClass([self class]), NSStringFromSelector(_cmd)]; + return NSOrderedDescending; if (GSObjCIsInstance(aString) == NO) [NSException raise: NSInvalidArgumentException format: @"[%@ -%@] not a string argument", diff --git a/Source/NSDate.m b/Source/NSDate.m index 0a9e384540..1a3ab4f232 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -396,8 +396,7 @@ - (NSComparisonResult) compare: (NSDate*)otherDate } if (unlikely(otherDate == nil)) { - [NSException raise: NSInvalidArgumentException - format: @"nil argument for compare:"]; + return NSOrderedSame; } if (IS_CONCRETE_CLASS(otherDate)) diff --git a/Source/NSString.m b/Source/NSString.m index 5d06cc0edd..9540990281 100644 --- a/Source/NSString.m +++ b/Source/NSString.m @@ -5914,8 +5914,7 @@ - (NSComparisonResult) compare: (NSString *)string GS_RANGE_CHECK(compareRange, [self length]); if (nil == string) { - [NSException raise: NSInvalidArgumentException - format: @"compare with nil"]; + return NSOrderedDescending; } /* A nil locale should trigger POSIX collation (i.e. 'A'-'Z' sort