Skip to content

Use access level on import in resource_bundle_accessor.swift#1447

Closed
snprajwal wants to merge 1 commit into
swiftlang:mainfrom
snprajwal:fix-foundation-import
Closed

Use access level on import in resource_bundle_accessor.swift#1447
snprajwal wants to merge 1 commit into
swiftlang:mainfrom
snprajwal:fix-foundation-import

Conversation

@snprajwal

Copy link
Copy Markdown

When a Swift package specifies a resource as part of a build target, SwiftPM synthesizes a resource_bundle_accessor.swift to provide runtime hooks to access the resource. This generated file imports Foundation but does not specify an access level. With Swift 6.0, access-level-on-import is part of the language mode, meaning that if a target specified a resource and contained a non-public import of Foundation, the build would fail with:

error: ambiguous implicit access level for import of 'Foundation'

This patch updates the generation logic to include an explicit public access level modifier for the Foundation import in bundle_resource_accessor.swift if the Swift version is >= 6.0.

Fixes swiftlang/swift-package-manager#10163

Additional testing

  1. Create a package with swift-tools-version: 6.0.
  2. Add a target with resources: [.copy("SomeFolder")] so SwiftPM synthesizes resource_bundle_accessor.swift.
  3. In one of that target's source files, add internal import Foundation.
  4. Run swift build --build-system swiftbuild.

Without this patch, the build fails with the above specified error. With this patch, the build succeeds.

When a Swift package specifies a resource as part of a build target,
SwiftPM synthesizes a resource_bundle_accessor.swift to provide runtime
hooks to access the resource. This generated file imports Foundation but
does not specify an access level. With Swift 6.0, access-level-on-import
is part of the language mode, meaning that if a target specified a
resource and contained a non-public import of Foundation, the build
would fail with:

```
error: ambiguous implicit access level for import of 'Foundation'
```

This patch updates the generation logic to include an explicit `public`
access level modifier for the Foundation import in
`bundle_resource_accessor.swift` if the Swift version is >= 6.0.
@snprajwal

Copy link
Copy Markdown
Author

@swift-ci please test

@owenv owenv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Determining the access level based on the language mode alone would be a breaking change. Realistically, I think this will probably need to become configurable via the package manifest and go through the evolution process

@snprajwal

Copy link
Copy Markdown
Author

That makes sense, thanks. I'll pitch a better fix for this on the forums, and take it forward from there. Closing this PR for now.

@snprajwal snprajwal closed this Jul 2, 2026
@snprajwal snprajwal deleted the fix-foundation-import branch July 2, 2026 21:33
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.

Ambiguous implicit access level for Foundation import in resource_bundle_accessor.swift

2 participants