Skip to content

Conversation

@AZero13
Copy link
Contributor

@AZero13 AZero13 commented Dec 10, 2025

We seem to be passing upper to lower and lower to upper when converting. That does not seem right.

// Verify that if bounds were swapped, the predicate would be wrong
// (This would be i >= upperDate AND i < lowerDate, which is always false)
let wrongPredicate = NSPredicate(format: "i >= %@ AND i < %@", upperDate as NSDate, lowerDate as NSDate)
#expect(!wrongPredicate.evaluate(with: objInRange), "Swapped bounds would incorrectly reject valid date")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What benefit did you find with adding this additional test? Is it testing Predicate to NSPredicate conversion in some way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It proves the ordering of bounds matters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on what you mean by that? I don't fully understand what this is proving here regarding the conversion code that you updated. It doesn't look like this code goes through the Predicate/NSPredicate conversion code but instead looks like it's just testing NSPredicate itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It exercises the _RangeValue conversion path for captured ranges.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It checks that when extracting bounds from a captured Range (via range.lowerBound and range.upperBound at line 326), they are used in the correct order when building the NSPredicate (lower for >=, upper for <).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah the last two parts are redundant.

@AZero13 AZero13 requested a review from jmschonfeld December 10, 2025 22:19
@AZero13 AZero13 force-pushed the swap branch 2 times, most recently from 556e32b to c7fbf09 Compare December 11, 2025 14:27
@AZero13 AZero13 changed the title Swap ranges upper and lower Fix bounds ordering for captured Range values in Predicate to NSPredicate conversion Dec 11, 2025
…cate conversion

We seem to be passing upper to lower and lower to upper when converting. That does not seem right.
@jmschonfeld
Copy link
Contributor

@swift-ci please test

@jmschonfeld jmschonfeld merged commit c921a20 into swiftlang:main Dec 11, 2025
21 checks passed
@AZero13 AZero13 deleted the swap branch December 11, 2025 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants