Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hasFeature(RetroactiveAttribute) check in iOS 14 #4359

Merged
merged 3 commits into from
Oct 8, 2024
Merged

Conversation

vegaro
Copy link
Contributor

@vegaro vegaro commented Oct 7, 2024

iOS 14 tests are failing with:

❌  /Users/distiller/purchases-ios/Sources/Purchasing/StoreKit1/ProductsFetcherSK1.swift:259:5: unexpected platform condition (expected 'os', 'arch', or 'swift')

#if hasFeature(RetroactiveAttribute)
    ^

see https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/22627/workflows/1c541690-3b85-4aa2-ad9e-dc7f15ada779/jobs/262246/steps

I think adding a swift compiler check would fix this, but seeing this issues I realized we should maybe change the check to #if $RetroactiveAttribute
swiftlang/swift#69643
https://forums.swift.org/t/hasattribute-only-supports-declaration-attributes/68202

@vegaro vegaro added the pr:fix A bug fix label Oct 7, 2024
@vegaro
Copy link
Contributor Author

vegaro commented Oct 7, 2024

@RCGitBot please test

@vegaro vegaro requested review from MarkVillacampa and a team October 7, 2024 20:09
@vegaro vegaro marked this pull request as ready for review October 7, 2024 20:09
@vegaro vegaro mentioned this pull request Oct 7, 2024
#if hasFeature(RetroactiveAttribute)
#if $RetroactiveAttribute
Copy link
Member

Choose a reason for hiding this comment

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

just when I thought I understood Swift

@MarkVillacampa
Copy link
Member

MarkVillacampa commented Oct 8, 2024

Turns out hasFeature was introduced in Swift 5.8, which was first bundled with Xcode 14.3, so it's a pity we need to use Xcode 14.2 in order to run in macOS 12 because iOS 14 sims only run there.

According to SE-0362 which introduced the hasFeature condition, variables with $ are still defined by the compiler to support older tools, however it is not recommended:
https://github.com/swiftlang/swift-evolution/blob/main/proposals/0362-piecemeal-future-features.md#x-instead-of-hasfeaturex

I think a more future-proof fix in this case would be to first check for the swift version, and then the feature. Something like:

#if swift(>=5.8)
#if hasFeature(ReroactiveAttribute)
XXXXXX
#endif
#endif

This is what Apple's swift-nio project is doing

@vegaro
Copy link
Contributor Author

vegaro commented Oct 8, 2024

@RCGitBot please test

@vegaro vegaro merged commit c960e58 into main Oct 8, 2024
35 checks passed
@vegaro vegaro deleted the fix-ios-14-check branch October 8, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:fix A bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants