Skip to content

Commit 4dac0d1

Browse files
author
Nathan Hawes
authored
Merge pull request #27218 from nathawes/r53958454-getFixedTypeRecursive-code-completion-crash
[code-completion] Remove special handling for completion on the RHS of an assignment
2 parents 29044e5 + 54defbc commit 4dac0d1

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
@@ -1214,7 +1214,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
12141214
std::vector<RequestedCachedModule> RequestedModules;
12151215
CodeCompletionConsumer &Consumer;
12161216
CodeCompletionExpr *CodeCompleteTokenExpr = nullptr;
1217-
AssignExpr *AssignmentExpr;
12181217
CompletionKind Kind = CompletionKind::None;
12191218
Expr *ParsedExpr = nullptr;
12201219
SourceLoc DotLoc;
@@ -1368,7 +1367,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13681367
void completeImportDecl(std::vector<std::pair<Identifier, SourceLoc>> &Path) override;
13691368
void completeUnresolvedMember(CodeCompletionExpr *E,
13701369
SourceLoc DotLoc) override;
1371-
void completeAssignmentRHS(AssignExpr *E) override;
13721370
void completeCallArg(CodeCompletionExpr *E, bool isFirst) override;
13731371
void completeReturnStmt(CodeCompletionExpr *E) override;
13741372
void completeYieldStmt(CodeCompletionExpr *E,
@@ -4672,13 +4670,6 @@ void CodeCompletionCallbacksImpl::completeUnresolvedMember(CodeCompletionExpr *E
46724670
this->DotLoc = DotLoc;
46734671
}
46744672

4675-
void CodeCompletionCallbacksImpl::completeAssignmentRHS(AssignExpr *E) {
4676-
AssignmentExpr = E;
4677-
ParsedExpr = E->getDest();
4678-
CurDeclContext = P.CurDeclContext;
4679-
Kind = CompletionKind::AssignmentRHS;
4680-
}
4681-
46824673
void CodeCompletionCallbacksImpl::completeCallArg(CodeCompletionExpr *E,
46834674
bool isFirst) {
46844675
CurDeclContext = P.CurDeclContext;
@@ -4907,7 +4898,6 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink,
49074898
addDeclKeywords(Sink);
49084899
addStmtKeywords(Sink, MaybeFuncBody);
49094900
LLVM_FALLTHROUGH;
4910-
case CompletionKind::AssignmentRHS:
49114901
case CompletionKind::ReturnStmtExpr:
49124902
case CompletionKind::YieldStmtExpr:
49134903
case CompletionKind::PostfixExprBeginning:
@@ -5374,14 +5364,6 @@ void CodeCompletionCallbacksImpl::doneParsing() {
53745364
Lookup.getUnresolvedMemberCompletions(ContextInfo.getPossibleTypes());
53755365
break;
53765366
}
5377-
case CompletionKind::AssignmentRHS : {
5378-
SourceLoc Loc = P.Context.SourceMgr.getCodeCompletionLoc();
5379-
if (auto destType = ParsedExpr->getType())
5380-
Lookup.setExpectedTypes(destType->getRValueType(),
5381-
/*isSingleExpressionBody*/ false);
5382-
Lookup.getValueCompletionsInDeclContext(Loc, DefaultFilter);
5383-
break;
5384-
}
53855367
case CompletionKind::CallArg : {
53865368
ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr);
53875369

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)