Skip to content

Commit f73054a

Browse files
committed
[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.
1 parent 0fc825b commit f73054a

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/IDE/CompletionLookup.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,11 +3006,14 @@ void CompletionLookup::getGenericRequirementCompletions(
30063006
/*includeDerivedRequirements*/ false,
30073007
/*includeProtocolExtensionMembers*/ true);
30083008
// We not only allow referencing nested types/typealiases directly, but also
3009-
// qualified by the current type. Thus also suggest current self type so the
3009+
// qualified by the current type, as long as it's a top-level type (nested
3010+
// types need to be qualified). Thus also suggest current self type so the
30103011
// user can do a memberwise lookup on it.
3011-
if (auto SelfType = typeContext->getSelfNominalTypeDecl()) {
3012-
addNominalTypeRef(SelfType, DeclVisibilityKind::LocalDecl,
3013-
DynamicLookupInfo());
3012+
if (auto *NTD = typeContext->getSelfNominalTypeDecl()) {
3013+
if (!NTD->getDeclContext()->isTypeContext()) {
3014+
addNominalTypeRef(NTD, DeclVisibilityKind::LocalDecl,
3015+
DynamicLookupInfo());
3016+
}
30143017
}
30153018

30163019
// Self is also valid in all cases in which it can be used in function

test/IDE/complete_where_clause.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,17 @@ struct TA2<T: Assoc> {
209209
// NOMINAL_TYPEALIAS_NESTED2-DAG: Decl[GenericTypeParam]/Local: T[#T#];
210210
}
211211
extension TA2.Inner1 where #^NOMINAL_TYPEALIAS_NESTED1_EXT^# {}
212-
// NOMINAL_TYPEALIAS_NESTED1_EXT: Begin completions, 6 items
212+
// NOMINAL_TYPEALIAS_NESTED1_EXT: Begin completions, 5 items
213213
// NOMINAL_TYPEALIAS_NESTED1_EXT-DAG: Decl[GenericTypeParam]/Local: T[#T#];
214214
// NOMINAL_TYPEALIAS_NESTED1_EXT-DAG: Decl[GenericTypeParam]/Local: U[#U#];
215215
// NOMINAL_TYPEALIAS_NESTED1_EXT-DAG: Decl[TypeAlias]/CurrNominal: X1[#T#];
216216
// NOMINAL_TYPEALIAS_NESTED1_EXT-DAG: Decl[TypeAlias]/CurrNominal: X2[#T.Q#];
217-
// FIXME : We shouldn't be suggesting Inner1 because it's not fully-qualified
218-
// NOMINAL_TYPEALIAS_NESTED1_EXT-DAG: Decl[Struct]/Local: Inner1[#TA2<T>.Inner1<U>#];
219217
// NOMINAL_TYPEALIAS_NESTED1_EXT-DAG: Keyword[Self]/CurrNominal: Self[#TA2<T>.Inner1<U>#];
220218
extension TA2.Inner2 where #^NOMINAL_TYPEALIAS_NESTED2_EXT^# {}
221-
// NOMINAL_TYPEALIAS_NESTED2_EXT: Begin completions, 5 items
219+
// NOMINAL_TYPEALIAS_NESTED2_EXT: Begin completions, 4 items
222220
// NOMINAL_TYPEALIAS_NESTED2_EXT-DAG: Decl[GenericTypeParam]/Local: T[#T#];
223221
// NOMINAL_TYPEALIAS_NESTED2_EXT-DAG: Decl[TypeAlias]/CurrNominal: X1[#T#];
224222
// NOMINAL_TYPEALIAS_NESTED2_EXT-DAG: Decl[TypeAlias]/CurrNominal: X2[#T.Q#];
225-
// FIXME : We shouldn't be suggesting Inner2 because it's not fully-qualified
226-
// NOMINAL_TYPEALIAS_NESTED2_EXT-DAG: Decl[Struct]/Local: Inner2[#TA2<T>.Inner2#];
227223
// NOMINAL_TYPEALIAS_NESTED2_EXT-DAG: Keyword[Self]/CurrNominal: Self[#TA2<T>.Inner2#];
228224

229225
protocol WithAssoc {

0 commit comments

Comments
 (0)