Skip to content

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

beccadax
Copy link
Contributor

@beccadax beccadax commented Aug 30, 2019

This PR allows you to write @qualified ModuleName.TypeName to access the indicated type reliably, even if ModuleName has the same name as a type in scope. It's meant to be used with modules like XCTest, where the XCTest.XCTest class shadows the module itself, preventing you from fully qualifying the name of any declaration in the module.

Caveats abound:

  • We don't know if we actually want this feature yet. If we do, it'll certainly require an evolution proposal.
  • We definitely don't know if this is the syntax we'll want for it—a type attribute is merely the easiest thing to implement.
  • 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.
  • This PR also currently makes -verify-syntax-tree unhappy.
  • The unqualified lookup changes are probably unnecessary and/or poorly implemented.

Fixes SR-898.

@beccadax beccadax changed the title Add syntax for fully qualifying type names Add syntax for fully qualifying names in shadowed modules Aug 30, 2019
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

@beccadax beccadax force-pushed the are-you-a-qualified-typist branch from c59c4a5 to f7d0c50 Compare August 31, 2019 06:27
@beccadax
Copy link
Contributor Author

@swift-ci please smoke test

2 similar comments
@beccadax
Copy link
Contributor Author

beccadax commented Sep 1, 2019

@swift-ci please smoke test

@beccadax
Copy link
Contributor Author

beccadax commented Sep 2, 2019

@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.
@beccadax beccadax force-pushed the are-you-a-qualified-typist branch from f7d0c50 to 9c263ea Compare September 3, 2019 09:03
@beccadax
Copy link
Contributor Author

beccadax commented Sep 3, 2019

@swift-ci please smoke test

1 similar comment
@beccadax
Copy link
Contributor Author

beccadax commented Sep 3, 2019

@swift-ci please smoke test

@beccadax

This comment has been minimized.

@beccadax
Copy link
Contributor Author

beccadax commented Sep 3, 2019

@swift-ci please test source compatibility

1 similar comment
@beccadax
Copy link
Contributor Author

beccadax commented Sep 3, 2019

@swift-ci please test source compatibility

@beccadax
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant