Skip to content

Add missing imports for MemberImportVisibility - #3395

Open
maxches99 wants to merge 3 commits into
swiftlang:mainfrom
maxches99:fix-3301-member-import-visibility
Open

Add missing imports for MemberImportVisibility#3395
maxches99 wants to merge 3 commits into
swiftlang:mainfrom
maxches99:fix-3301-member-import-visibility

Conversation

@maxches99

Copy link
Copy Markdown

Building swift-syntax with the MemberImportVisibility upcoming feature enabled currently fails: a number of files use declarations from modules that are only imported transitively — mostly the string-interpolation conformances from SwiftSyntaxBuilder and the indentation helpers from SwiftBasicFormat.

This PR adds the missing direct imports so that

swift build --build-tests -Xswiftc -enable-upcoming-feature -Xswiftc MemberImportVisibility

builds cleanly. All changes are plain import additions, with two exceptions:

  • SwiftSyntaxMacroExpansion used SwiftBasicFormat without declaring it in Package.swift (the module was only available transitively; its CMakeLists.txt already links it), so the dependency is now declared.
  • The existing import SwiftBasicFormat in MacroExpansion.swift becomes internal import to avoid an "ambiguous implicit access level for import" error once other files in the module import it as internal.

No CMakeLists.txt changes are needed — all affected modules already link the corresponding libraries.

The full test suite passes with the feature enabled, and swift format lint is clean on the touched files. A possible follow-up would be to enable the feature in Package.swift so new violations can't creep in.

Fixes #3301

Building swift-syntax with the MemberImportVisibility upcoming feature
enabled fails because a number of files use declarations from modules
that are only imported transitively. Add the missing direct imports.

Also declare SwiftBasicFormat as a dependency of
SwiftSyntaxMacroExpansion in Package.swift; the module was previously
only available transitively, and its CMakeLists.txt already links it.

Fixes swiftlang#3301
@hamishknight

Copy link
Copy Markdown
Contributor

Thanks!

A possible follow-up would be to enable the feature in Package.swift so new violations can't creep in.

I think we should do that in this PR to ensure we don't regress

Now that all targets build with the upcoming feature, turn it on for the
package so that missing imports can't creep back in. Toolchains that
don't know the feature ignore the flag.
@maxches99

Copy link
Copy Markdown
Author

Done — enabled it for all regular and test targets in Package.swift. Older toolchains that don't know the upcoming feature ignore the flag, so this shouldn't affect them.

@hamishknight hamishknight left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Can you also update CMakeLists.txt to match? (sorry I should have mentioned this in my original comment)

Comment thread Package.swift Outdated

// Require every file to import the modules that define the members it uses, so that missing
// imports can't creep back in. Toolchains that don't know the upcoming feature ignore the flag.
for target in package.targets where target.type == .regular || target.type == .test {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we need to be this restrictive on the target kind, let's do type != .plugin instead, matching what we do for sourcekit-lsp (https://github.com/swiftlang/sourcekit-lsp/blob/a31d272f3cb392b443f42e1f97042a2a607073ec/Package.swift#L706)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done — switched to type != .plugin and added the flag to CMakeLists.txt. Verified the CMake build locally with the feature enabled.

Pass the upcoming feature in CMakeLists.txt as well, so the CMake build
enforces the same imports as the SwiftPM build. Also relax the target
filter in Package.swift to everything but plugins, matching sourcekit-lsp.
@xedin
xedin requested a review from tshortli August 3, 2026 22:10
@tshortli
tshortli requested a review from hamishknight August 3, 2026 23: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.

Missing imports when enabling MemberImportVisibility

2 participants