mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Completion] Don't suggest nested type in where clause
We allow the unqualifed use of the enclosing nominal type in a where
clause, but only when it isn't a nested type, e.g:
```
struct S<T> {
typealias T = T
struct R<U> {
typealias U = U
}
}
extension S where S.T == Int {} // allowed
extension S.R where R.U == Int {} // not allowed
```
Tweak the completion logic such that we don't suggest the type for
the nested case, instead it must be qualified.
This commit is contained in:
@@ -3006,11 +3006,14 @@ void CompletionLookup::getGenericRequirementCompletions(
|
||||
/*includeDerivedRequirements*/ false,
|
||||
/*includeProtocolExtensionMembers*/ true);
|
||||
// We not only allow referencing nested types/typealiases directly, but also
|
||||
// qualified by the current type. Thus also suggest current self type so the
|
||||
// qualified by the current type, as long as it's a top-level type (nested
|
||||
// types need to be qualified). Thus also suggest current self type so the
|
||||
// user can do a memberwise lookup on it.
|
||||
if (auto SelfType = typeContext->getSelfNominalTypeDecl()) {
|
||||
addNominalTypeRef(SelfType, DeclVisibilityKind::LocalDecl,
|
||||
DynamicLookupInfo());
|
||||
if (auto *NTD = typeContext->getSelfNominalTypeDecl()) {
|
||||
if (!NTD->getDeclContext()->isTypeContext()) {
|
||||
addNominalTypeRef(NTD, DeclVisibilityKind::LocalDecl,
|
||||
DynamicLookupInfo());
|
||||
}
|
||||
}
|
||||
|
||||
// Self is also valid in all cases in which it can be used in function
|
||||
|
||||
Reference in New Issue
Block a user