Skip to content

Commit 54defbc

Browse files
author
Nathan Hawes
committed
[code-completion] Remove special handling for completion on the RHS of an assignment
This simplifies the code and prevents an assertion failure this code was hitting computing the type relations between the result types and what it determined as the expected type. Resolves rdar://problem/53958454
1 parent 258f372 commit 54defbc

File tree

6 files changed

+50
-44
lines changed

6 files changed

+50
-44
lines changed

include/swift/IDE/CodeCompletion.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ enum class CompletionKind {
498498
AttributeBegin,
499499
AttributeDeclParen,
500500
PoundAvailablePlatform,
501-
AssignmentRHS,
502501
CallArg,
503502
ReturnStmtExpr,
504503
YieldStmtExpr,

include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ class CodeCompletionCallbacks {
200200
virtual void completeUnresolvedMember(CodeCompletionExpr *E,
201201
SourceLoc DotLoc) {};
202202

203-
virtual void completeAssignmentRHS(AssignExpr *E) {};
204-
205203
virtual void completeCallArg(CodeCompletionExpr *E, bool isFirst) {};
206204

207205
virtual void completeReturnStmt(CodeCompletionExpr *E) {};

lib/IDE/CodeCompletion.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
12131213
std::vector<RequestedCachedModule> RequestedModules;
12141214
CodeCompletionConsumer &Consumer;
12151215
CodeCompletionExpr *CodeCompleteTokenExpr = nullptr;
1216-
AssignExpr *AssignmentExpr;
12171216
CompletionKind Kind = CompletionKind::None;
12181217
Expr *ParsedExpr = nullptr;
12191218
SourceLoc DotLoc;
@@ -1367,7 +1366,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13671366
void completeImportDecl(std::vector<std::pair<Identifier, SourceLoc>> &Path) override;
13681367
void completeUnresolvedMember(CodeCompletionExpr *E,
13691368
SourceLoc DotLoc) override;
1370-
void completeAssignmentRHS(AssignExpr *E) override;
13711369
void completeCallArg(CodeCompletionExpr *E, bool isFirst) override;
13721370
void completeReturnStmt(CodeCompletionExpr *E) override;
13731371
void completeYieldStmt(CodeCompletionExpr *E,
@@ -4671,13 +4669,6 @@ void CodeCompletionCallbacksImpl::completeUnresolvedMember(CodeCompletionExpr *E
46714669
this->DotLoc = DotLoc;
46724670
}
46734671

4674-
void CodeCompletionCallbacksImpl::completeAssignmentRHS(AssignExpr *E) {
4675-
AssignmentExpr = E;
4676-
ParsedExpr = E->getDest();
4677-
CurDeclContext = P.CurDeclContext;
4678-
Kind = CompletionKind::AssignmentRHS;
4679-
}
4680-
46814672
void CodeCompletionCallbacksImpl::completeCallArg(CodeCompletionExpr *E,
46824673
bool isFirst) {
46834674
CurDeclContext = P.CurDeclContext;
@@ -4906,7 +4897,6 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
49064897
addDeclKeywords(Sink);
49074898
addStmtKeywords(Sink, MaybeFuncBody);
49084899
LLVM_FALLTHROUGH;
4909-
case CompletionKind::AssignmentRHS:
49104900
case CompletionKind::ReturnStmtExpr:
49114901
case CompletionKind::YieldStmtExpr:
49124902
case CompletionKind::PostfixExprBeginning:
@@ -5373,14 +5363,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
53735363
Lookup.getUnresolvedMemberCompletions(ContextInfo.getPossibleTypes());
53745364
break;
53755365
}
5376-
case CompletionKind::AssignmentRHS : {
5377-
SourceLoc Loc = P.Context.SourceMgr.getCodeCompletionLoc();
5378-
if (auto destType = ParsedExpr->getType())
5379-
Lookup.setExpectedTypes(destType->getRValueType(),
5380-
/*isSingleExpressionBody*/ false);
5381-
Lookup.getValueCompletionsInDeclContext(Loc, DefaultFilter);
5382-
break;
5383-
}
53845366
case CompletionKind::CallArg : {
53855367
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
53865368

lib/Parse/ParseExpr.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,6 @@ ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
279279
auto *assign = new (Context) AssignExpr(equalsLoc);
280280
SequencedExprs.push_back(assign);
281281
Message = diag::expected_expr_assignment;
282-
if (Tok.is(tok::code_complete)) {
283-
if (CodeCompletion) {
284-
auto RHS = new (Context) ErrorExpr(
285-
SourceRange(Tok.getRange().getStart(), Tok.getRange().getEnd()));
286-
assign->setSrc(RHS);
287-
SequencedExprs.pop_back();
288-
assign->setDest(SequencedExprs.back());
289-
SequencedExprs.pop_back();
290-
SequencedExprs.push_back(assign);
291-
CodeCompletion->completeAssignmentRHS(assign);
292-
}
293-
consumeToken();
294-
if (!SequencedExprs.empty() && (SequencedExprs.size() & 1) == 0) {
295-
// Make sure we have odd number of sequence exprs.
296-
SequencedExprs.pop_back();
297-
}
298-
auto Result = SequencedExprs.size() == 1 ?
299-
makeParserResult(SequencedExprs[0]):
300-
makeParserResult(SequenceExpr::create(Context, SequencedExprs));
301-
Result.setHasCodeCompletion();
302-
return Result;
303-
}
304282
break;
305283
}
306284

test/IDE/complete_associated_types.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_1 > %t.types.txt
2121
// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_1 < %t.types.txt
2222

23+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_UNASSIGNABLE > %t.types.txt
24+
// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_UNASSIGNABLE < %t.types.txt
25+
26+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_UNASSIGNABLE_2 > %t.types.txt
27+
// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_UNASSIGNABLE < %t.types.txt
28+
29+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_ASSIGNABLE > %t.types.txt
30+
// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_ASSIGNABLE < %t.types.txt
31+
2332
// FIXME: extensions that introduce conformances?
2433

2534
protocol FooBaseProtocolWithAssociatedTypes {
@@ -300,3 +309,44 @@ func testBrokenConformances1() {
300309
// BROKEN_CONFORMANCE_1-DAG: Decl[InstanceMethod]/Super: deduceFooBaseC({#(self): StructWithBrokenConformance#})[#() -> StructWithBrokenConformance.FooBaseDeducedTypeC#]{{; name=.+$}}
301310
// BROKEN_CONFORMANCE_1-DAG: Decl[InstanceMethod]/Super: deduceFooBaseD({#(self): StructWithBrokenConformance#})[#() -> StructWithBrokenConformance.FooBaseDeducedTypeD#]{{; name=.+$}}
302311
// BROKEN_CONFORMANCE_1: End completions
312+
313+
314+
protocol MyProto {
315+
associatedtype Element
316+
}
317+
318+
extension MyProto {
319+
var matches: (Int, (Int, Int)) { fatalError() }
320+
func first() -> Element {
321+
fatalError()
322+
}
323+
}
324+
325+
// Does not conform - Element not specified
326+
struct A<T>: MyProto {
327+
func foo() {
328+
self.first = #^BROKEN_CONFORMANCE_UNASSIGNABLE^#
329+
}
330+
331+
func foo2() {
332+
var (a, b): (Int, Int)
333+
let exact = (1, (2, 4))
334+
(a, (b, self.first)) = #^BROKEN_CONFORMANCE_UNASSIGNABLE_2^#
335+
}
336+
337+
func foo3() {
338+
var (a, b, c): (Int, Int, Int)
339+
let exact = (1, (2, 4))
340+
(a, (b, c)) = #^BROKEN_CONFORMANCE_ASSIGNABLE^#
341+
}
342+
}
343+
// BROKEN_CONFORMANCE_UNASSIGNABLE: Begin completions
344+
// BROKEN_CONFORMANCE_UNASSIGNABLE-NOT: TypeRelation
345+
// BROKEN_CONFORMANCE_UNASSIGNABLE: Decl[InstanceMethod]/Super: first()[#MyProto.Element#]; name=first()
346+
// BROKEN_CONFORMANCE_UNASSIGNABLE-NOT: TypeRelation
347+
// BROKEN_CONFORMANCE_UNASSIGNABLE: End completions
348+
349+
// BROKEN_CONFORMANCE_ASSIGNABLE: Begin completions
350+
// BROKEN_CONFORMANCE_ASSIGNABLE-DAG: Decl[LocalVar]/Local/TypeRelation[Identical]: exact[#(Int, (Int, Int))#]; name=exact
351+
// BROKEN_CONFORMANCE_ASSIGNABLE-DAG: Decl[InstanceVar]/Super/TypeRelation[Identical]: matches[#(Int, (Int, Int))#]; name=matches
352+
// BROKEN_CONFORMANCE_ASSIGNABLE: End completions

tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ bool SourceKit::CodeCompletion::addCustomCompletions(
176176
}
177177
break;
178178
case CompletionKind::PostfixExprBeginning:
179-
case CompletionKind::AssignmentRHS:
180179
case CompletionKind::CallArg:
181180
case CompletionKind::ReturnStmtExpr:
182181
case CompletionKind::YieldStmtExpr:

0 commit comments

Comments
 (0)