Skip to content

Sema: Omit internal from MemberImportVisibility fix-its when appropriate #81781

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

Conversation

tshortli
Copy link
Contributor

Omit an explicit access level from MemberImportVisibility fix-its under the following conditions:

  • InternalImportsByDefault is enabled.
  • The required import needs an internal access level or lower.
  • The module is not yet imported explicitly in any other file.

Resolves rdar://149577615.

@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

tshortli added 2 commits May 26, 2025 22:56
…opriate.

Omit an explicit access level from `MemberImportVisibility` fix-its under the
following conditions:

- `InternalImportsByDefault` is enabled.
- The required import needs an `internal` access level or lower.
- The module is not yet imported explicitly in any other file.

Resolves rdar://149577615.
@tshortli tshortli force-pushed the member-import-visibility-fixit-implicitly-internal branch from 5c9cad5 to dbb1d78 Compare May 27, 2025 05:57
@tshortli
Copy link
Contributor Author

@swift-ci please smoke test

@tshortli
Copy link
Contributor Author

@swift-ci please smoke test Windows

auto accessLevelForImport = [&]() -> std::optional<AccessLevel> {
auto maxAccessLevel = sf.getMaxAccessLevelUsingImport(mod);
if (internalImportsByDefaultEnabled) {
if (!foundImport && maxAccessLevel <= AccessLevel::Internal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check for imports in other files here? In internal-imports-by-default mode the access-level in other files shouldn't mater, the inconsistency diagnostics is disabled in that mode.

Copy link
Contributor Author

@tshortli tshortli May 27, 2025

Choose a reason for hiding this comment

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

My thinking is that we should follow the style that the developer is already using. If they write explicit access levels on imports of the module in other files, then the fix-it should too (which is handled by the logic below).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, that makes sense.

@tshortli tshortli enabled auto-merge May 27, 2025 16:45
@tshortli tshortli merged commit 54e0973 into swiftlang:main May 27, 2025
3 checks passed
@tshortli tshortli deleted the member-import-visibility-fixit-implicitly-internal branch May 27, 2025 19:31
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