Skip to content

Add missing Foundation imports to fix test build errors on iOS with MemberImportVisibility enabled #1108

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

Merged

Conversation

stmontgomery
Copy link
Contributor

This fixes several instances of a build error when attempting to build this package for iOS, or any non-macOS Apple platform. Here's one example

error: instance method 'contains' is not available due to missing import of defining module 'Foundation'
Tests/TestingTests/SwiftPMTests.swift:370:5: note: in expansion of macro 'expect' here
    #expect(testIDs.allSatisfy { $0.contains(".swift:") })

This general kind of build error is being emitted because we adopted SE-0444: Member import visibility by enabling the MemberImportVisibility experimental feature in #1020.

In that PR, I fixed several instances of missing imports, including some for Foundation in test files. But these errors are from usages of String.contains(), and it turns out there are multiple overloads of that function, with an older one in Foundation and a newer one directly in the stdlib Swift module. The latter has newer, iOS 13.0-aligned API availability, and when building our tests for macOS this issue was not noticed previously because SwiftPM artificially raises the deployment target of macOS test targets to match the testing frameworks included in Xcode (when the testing libraries are being used from the installed copy of Xcode).

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@stmontgomery stmontgomery added this to the Swift 6.x milestone May 7, 2025
@stmontgomery stmontgomery self-assigned this May 7, 2025
@stmontgomery stmontgomery requested a review from grynspan as a code owner May 7, 2025 22:19
@stmontgomery stmontgomery added the bug 🪲 Something isn't working label May 7, 2025
@stmontgomery stmontgomery added darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support build 🧱 Affects the project's build configuration or process labels May 7, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit 1932a1b into swiftlang:main May 7, 2025
3 checks passed
@stmontgomery stmontgomery deleted the missing-Foundation-imports branch May 7, 2025 22:37
@stmontgomery stmontgomery modified the milestones: Swift 6.x, Swift 6.2 May 8, 2025
@grynspan
Copy link
Contributor

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working build 🧱 Affects the project's build configuration or process darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants