Skip to content

Commit 1650052

Browse files
committed
[CodeCompletion] Fix missing completions in type member access of right-hand side in generic where clause
Fixes the issue in #61064 (comment)
1 parent 11ef6e5 commit 1650052

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

lib/Parse/ParseGeneric.cpp

+21-11
Original file line numberDiff line numberDiff line change
@@ -361,19 +361,29 @@ ParserStatus Parser::parseGenericWhereClause(
361361
SecondType = makeParserResult(ErrorTypeRepr::create(Context, PreviousLoc));
362362

363363
// Add the requirement
364+
//
365+
// If the a type has a code completion token, don't record a same
366+
// type constraint, because otherwise if we have
367+
// K.#^COMPLETE^# == Foo
368+
// we parse this as
369+
// K == Foo
370+
// and thus simplify K to Foo. But we didn't want to state that K is Foo
371+
// but that K has a member of type Foo.
372+
// FIXME: The proper way to fix this would be to represent the code
373+
// completion token in the TypeRepr.
364374
if (FirstType.hasCodeCompletion()) {
365-
// If the first type has a code completion token, don't record a same
366-
// type constraint because otherwise if we have
367-
// K.#^COMPLETE^# == Foo
368-
// we parse this as
369-
// K == Foo
370-
// and thus simplify K to Foo. But we didn't want to state that K is Foo
371-
// but that K has a member of type Foo.
372-
// FIXME: The proper way to fix this would be to represent the code
373-
// completion token in the TypeRepr.
375+
SecondType = makeParserResult(
376+
SecondType,
377+
ErrorTypeRepr::create(Context, SecondType.get()->getLoc()));
378+
}
379+
if (SecondType.hasCodeCompletion()) {
380+
FirstType = makeParserResult(
381+
FirstType,
382+
ErrorTypeRepr::create(Context, FirstType.get()->getLoc()));
383+
}
384+
if (FirstType.hasCodeCompletion() || SecondType.hasCodeCompletion()) {
374385
Requirements.push_back(RequirementRepr::getTypeConstraint(
375-
FirstType.get(), EqualLoc,
376-
ErrorTypeRepr::create(Context, SecondType.get()->getLoc()),
386+
FirstType.get(), EqualLoc, SecondType.get(),
377387
isRequirementExpansion));
378388
} else {
379389
Requirements.push_back(RequirementRepr::getSameType(

test/IDE/complete_where_clause.swift

+2-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NOMINAL_TYPEALIAS_NESTED1_EXT | %FileCheck %s -check-prefix=NOMINAL_TYPEALIAS_NESTED1_EXT
4040
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=NOMINAL_TYPEALIAS_NESTED2_EXT | %FileCheck %s -check-prefix=NOMINAL_TYPEALIAS_NESTED2_EXT
4141
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=EXT_ASSOC_MEMBER_1 | %FileCheck %s -check-prefix=EXT_ASSOC_MEMBER
42-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=EXT_ASSOC_MEMBER_2 | %FileCheck %s -check-prefix=EXT_ASSOC_MEMBER_2
42+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=EXT_ASSOC_MEMBER_2 | %FileCheck %s -check-prefix=EXT_ASSOC_MEMBER
4343
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=EXT_SECONDTYPE | %FileCheck %s -check-prefix=EXT_SECONDTYPE
4444
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=WHERE_CLAUSE_WITH_EQUAL | %FileCheck %s -check-prefix=WHERE_CLAUSE_WITH_EQUAL
4545

@@ -234,11 +234,8 @@ extension WithAssoc where T.#^EXT_ASSOC_MEMBER_1^#
234234
// EXT_ASSOC_MEMBER-DAG: Decl[AssociatedType]/CurrNominal: Q;
235235
// EXT_ASSOC_MEMBER-DAG: Keyword/None: Type[#Self.T.Type#];
236236

237-
// This is kind of funny because we parse it as 'Int == T', so completing 'T'
238-
// shows members of 'Int'.
239237
extension WithAssoc where Int == T.#^EXT_ASSOC_MEMBER_2^#
240-
// EXT_ASSOC_MEMBER_2: Begin completions, {{.*}} items
241-
// EXT_ASSOC_MEMBER_2: Keyword/None: Type[#Int.Type#];
238+
// Same as EXT_ASSOC_MEMBER
242239

243240
extension WithAssoc where Int == #^EXT_SECONDTYPE^#
244241
// EXT_SECONDTYPE-DAG: Decl[AssociatedType]/CurrNominal: T;

0 commit comments

Comments
 (0)