From de3c570548fe2b8c42affbf49dcc72ea809896af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Andra=C5=A1ec?= Date: Tue, 6 Aug 2024 10:01:20 +0200 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20force=20cast=20to=20`NSComparis?= =?UTF-8?q?onPredicate`=20in=20TERNARY=20operator=20(#4232)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 +- Sources/Sentry/SentryPredicateDescriptor.m | 9 ++++----- Tests/SentryTests/SentryPredicateDescriptorTests.swift | 5 +++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828a1f83fb0..5e7f3ec1cec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ - Long-lasting TTID/TTFD spans (#4225). Avoid long TTID spans when the FrameTracker isn't running, which is the case when the app is in the background. - Missing mach info for crash reports (#4230) - Crash reports not generated on visionOS (#4229) - +- Don’t force cast to `NSComparisonPredicate` in TERNARY operator (#4232) ### Improvements diff --git a/Sources/Sentry/SentryPredicateDescriptor.m b/Sources/Sentry/SentryPredicateDescriptor.m index ca6c3a77f95..229aeddd57f 100644 --- a/Sources/Sentry/SentryPredicateDescriptor.m +++ b/Sources/Sentry/SentryPredicateDescriptor.m @@ -75,11 +75,10 @@ - (NSString *)expressionDescription:(NSExpression *)predicate break; case NSConditionalExpressionType: if (@available(macOS 10.11, *)) { - return [NSString - stringWithFormat:@"TERNARY(%@,%@,%@)", - [self comparisonPredicateDescription:(NSComparisonPredicate *)predicate.predicate], - [self expressionDescription:predicate.trueExpression], - [self expressionDescription:predicate.falseExpression]]; + return [NSString stringWithFormat:@"TERNARY(%@,%@,%@)", + [self predicateDescription:predicate.predicate], + [self expressionDescription:predicate.trueExpression], + [self expressionDescription:predicate.falseExpression]]; } else { // this is not supposed to happen, NSConditionalExpressionType was introduced in // macOS 10.11 but we need this version check because cocoapod lint check is failing diff --git a/Tests/SentryTests/SentryPredicateDescriptorTests.swift b/Tests/SentryTests/SentryPredicateDescriptorTests.swift index 05a01765223..67954f64cfe 100644 --- a/Tests/SentryTests/SentryPredicateDescriptorTests.swift +++ b/Tests/SentryTests/SentryPredicateDescriptorTests.swift @@ -115,6 +115,11 @@ class SentryPredicateDescriptorTests: XCTestCase { assertPredicate(predicate: pred, expectedResult: "field1 == %@ AND (field3 == %@ OR field2 == %@)") } + func test_compoundInTenary() { + let pred = NSPredicate(format: "TERNARY(field1 > 10 AND field1 < 20, 1, 0) == 1") + assertPredicate(predicate: pred, expectedResult: "TERNARY(field1 > %@ AND field1 < %@,%@,%@) == %@") + } + func test_UNKNOWN() { let pred = NSPredicate { _, _ in return false