File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -350,9 +350,23 @@ ParserStatus Parser::parseGenericWhereClause(
350
350
SecondType = makeParserResult (new (Context) ErrorTypeRepr (PreviousLoc));
351
351
352
352
// Add the requirement
353
- Requirements.push_back (RequirementRepr::getSameType (FirstType.get (),
354
- EqualLoc,
355
- SecondType.get ()));
353
+ if (FirstType.hasCodeCompletion ()) {
354
+ // If the first type has a code completion token, don't record a same
355
+ // type constraint because otherwise if we have
356
+ // K.#^COMPLETE^# == Foo
357
+ // we parse this as
358
+ // K == Foo
359
+ // and thus simplify K to Foo. But we didn't want to state that K is Foo
360
+ // but that K has a member of type Foo.
361
+ // FIXME: The proper way to fix this would be to represent the code
362
+ // completion token in the TypeRepr.
363
+ Requirements.push_back (RequirementRepr::getTypeConstraint (
364
+ FirstType.get (), EqualLoc,
365
+ new (Context) ErrorTypeRepr (SecondType.get ()->getLoc ())));
366
+ } else {
367
+ Requirements.push_back (RequirementRepr::getSameType (
368
+ FirstType.get (), EqualLoc, SecondType.get ()));
369
+ }
356
370
} else if (FirstType.hasCodeCompletion ()) {
357
371
// Recover by adding dummy constraint.
358
372
Requirements.push_back (RequirementRepr::getTypeConstraint (
Original file line number Diff line number Diff line change 41
41
// 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
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
43
43
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=EXT_SECONDTYPE | %FileCheck %s -check-prefix=EXT_SECONDTYPE
44
+ // 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
44
45
45
46
class A1 < T1, T2, T3> { }
46
47
@@ -264,3 +265,10 @@ extension WithAssoc where Int == #^EXT_SECONDTYPE^#
264
265
// EXT_SECONDTYPE: Begin completions
265
266
// EXT_SECONDTYPE-DAG: Decl[AssociatedType]/CurrNominal: T;
266
267
// EXT_SECONDTYPE: End completions
268
+
269
+ func foo< K: WithAssoc > ( _ key: K . Type ) where K. #^WHERE_CLAUSE_WITH_EQUAL^# == S1 { }
270
+
271
+ // WHERE_CLAUSE_WITH_EQUAL: Begin completions, 2 items
272
+ // WHERE_CLAUSE_WITH_EQUAL-DAG: Decl[AssociatedType]/CurrNominal: T;
273
+ // WHERE_CLAUSE_WITH_EQUAL-DAG: Keyword/None: Type[#K.Type#];
274
+ // WHERE_CLAUSE_WITH_EQUAL: End completions
You can’t perform that action at this time.
0 commit comments