Skip to content

Sema: Report public conformances to non-publicly imported protocols #74142

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
merged 3 commits into from
Jun 14, 2024

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Jun 5, 2024

Exportability checking for non-public imports relies on classic access-level checks for some of the work. However while conforming to a local internal protocol from a public type is allow we should disallow it for imported types, even when imported as internal.

Track exportability issues on conformances to protocols separately from the general category. Use that information to improve the diagnostics and report these issues for access-level on imports.

rdar://128420980

@xymus xymus requested review from elsh and tshortli June 5, 2024 16:10
@xymus
Copy link
Contributor Author

xymus commented Jun 5, 2024

@swift-ci Please smoke test

@@ -3645,7 +3645,8 @@ ERROR(decl_from_hidden_module,none,
"in an extension with public or '@usableFromInline' members|"
"in an extension with conditional conformances|"
"in an extension with public, package, or '@usableFromInline' members|"
"in an extension with conditional conformances}1; "
"in an extension with conditional conformances|"
"in an exported conformance}1; "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This diagnostic text is not ideal but I'd rather keep it simple until this is merged back to 6.0 to avoid complications.

@nkcsgexi
Copy link
Contributor

nkcsgexi commented Jun 5, 2024

Thank you!

@xymus
Copy link
Contributor Author

xymus commented Jun 5, 2024

@swift-ci Please smoke test

reason != ExportabilityReason::ExtensionWithPackageMembers &&
reason != ExportabilityReason::ExtensionWithConditionalConformances &&
reason != ExportabilityReason::ExtensionWithPackageConditionalConformances)
bool reportHere =
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it maybe make sense to use a switch to cover ExportabilityReason? It seems like it could clean this up a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I was trying to find ways to simplify this logic and didn't consider this alternative. It's updated.

@xymus
Copy link
Contributor Author

xymus commented Jun 11, 2024

@swift-ci Please smoke test

Exportability checking for non-public imports relies on classic
access-level checks for some of the work. However while conforming
to a local internal protocol from a public type is allow we should
disallow it for imported types, even when imported as internal.

Track exportability issues on conformances to protocols separately
from the general category. Use that information to improve the
diagnostics and report these issues for access-level on imports.

rdar://128420980
@xymus xymus force-pushed the access-level-conformances branch from 6ae12d7 to 275c534 Compare June 12, 2024 21:56
@xymus
Copy link
Contributor Author

xymus commented Jun 12, 2024

Rebased following the revert from #74302. I left behind some of the expected errors for once the revert is reverted in a separate commit.

@swift-ci Please smoke test

@xymus xymus force-pushed the access-level-conformances branch from 275c534 to e5bc35b Compare June 13, 2024 22:20
@xymus
Copy link
Contributor Author

xymus commented Jun 13, 2024

@swift-ci Please smoke test

@xymus xymus merged commit 4dc0603 into swiftlang:main Jun 14, 2024
3 checks passed
@xymus xymus deleted the access-level-conformances branch June 14, 2024 02:34
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.

3 participants