-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add syntax for fully qualifying names in shadowed modules #26949
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci please smoke test |
c59c4a5
to
f7d0c50
Compare
@swift-ci please smoke test |
This isn’t used for anything yet.
When describing a type, you can prefix it with the @qualified attribute to indicate that it is already fully qualified—that is, the first identifier is the module it can be found in. This can allow you to address types and modules that have been shadowed by identically-named declarations. This commit includes a test, but some parts of it do not pass yet.
This allows you to write `@qualified Module.TypeName(…)` to initialize an instance, which makes additional tests pass.
Replaces several ad-hoc boolean parameters passed to various `parseType*` methods with a ParseTypeOptions option set.
Change ParseTypeFlags::HandleCodeCompletion to ParseTypeFlags::IgnoreCodeCompletion, which allows an empty set of ParseTypeOptions to be the correct default.
This flag makes parseType() parse exactly one identifier unless there is some surrounding syntax to disambiguate the length. It’s not used yet.
This causes regressions we’ll clean up in future changes to PreCheckExpression.
This allows us to handle both @qualified Module.TypeName and @qualified Module.funcName non-invasively with the same code paths.
f7d0c50
to
9c263ea
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
This comment has been minimized.
This comment has been minimized.
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
For-realsies work on this is in #28834. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR allows you to write
@qualified ModuleName.TypeName
to access the indicated type reliably, even ifModuleName
has the same name as a type in scope. It's meant to be used with modules like XCTest, where theXCTest.XCTest
class shadows the module itself, preventing you from fully qualifying the name of any declaration in the module.Caveats abound:
This PR includes some basic tests of the feature, but not all of them pass yet. In particular,@qualified
is currently too greedy in expression context, and making it less so might require a little refactoring.-verify-syntax-tree
unhappy.Fixes SR-898.