Skip to content

Add access level import diagnostic for named pattern. #77832

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 1 commit into from
Dec 10, 2024

Conversation

rmaz
Copy link
Contributor

@rmaz rmaz commented Nov 25, 2024

This PR adds a missing access level diagnostic when type checking named patterns by extracting the TypeRepr from the pattern's initializer.

@rmaz
Copy link
Contributor Author

rmaz commented Nov 25, 2024

@swift-ci please test

@tshortli tshortli requested a review from xymus December 3, 2024 16:55
@rmaz rmaz force-pushed the namedpatterndiag branch from f27dcdd to 2fe5e0b Compare December 6, 2024 19:08
@rmaz
Copy link
Contributor Author

rmaz commented Dec 6, 2024

@tshortli what about this approach? It's a larger change as I had to add a parameter to the CheckTypeAccessCallback to pass out the Decl that imported the module with the access restriction, and clang-format was not happy with the indentation of most of the changed callbacks.

@rmaz
Copy link
Contributor Author

rmaz commented Dec 6, 2024

@swift-ci please test

@rmaz
Copy link
Contributor Author

rmaz commented Dec 9, 2024

@swift-ci please smoke test Linux Platform

if (auto *declRefTR = dyn_cast_or_null<DeclRefTypeRepr>(complainRepr))
complainDecl = declRefTR->getBoundDecl();

noteLimitingImport(userDecl, ctx, limitImport, complainDecl);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a small detail, but I think we still want the diagnostic to point to the TypeRepr instead of the Decl when there is a TypeRepr available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behavior should be the same here, its just the unwrapping of the TypeRepr happens one level above in noteLimitingImport(..., const TypeRepr *complainRepr)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, if the exact source location that the diagnostic points to is not changing then this is fine. I was expecting that it would point directly to the type written in source (which would be different than the location of the decl), but I guess it doesn't already do that.

This PR adds a missing access level diagnostic when type checking
named patterns by walking the interface type to find the importing
decl to emit the diagnostic for.
@rmaz rmaz force-pushed the namedpatterndiag branch from 2fe5e0b to 5bcf1bf Compare December 9, 2024 20:30
@rmaz
Copy link
Contributor Author

rmaz commented Dec 9, 2024

@swift-ci please test Windows Platform
@swift-ci please smoke test Linux Platform
@swift-ci please smoke test macOS Platform

@rmaz
Copy link
Contributor Author

rmaz commented Dec 9, 2024

@swift-ci please test Windows Platform

@rmaz
Copy link
Contributor Author

rmaz commented Dec 9, 2024

@swift-ci please smoke test Linux Platform

@rmaz rmaz merged commit 6a6cc48 into swiftlang:main Dec 10, 2024
3 checks passed
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