diff --git a/include/swift/IDE/CodeCompletion.h b/include/swift/IDE/CodeCompletion.h index 427013647a6c8..e6b2d63290a49 100644 --- a/include/swift/IDE/CodeCompletion.h +++ b/include/swift/IDE/CodeCompletion.h @@ -498,7 +498,6 @@ enum class CompletionKind { AttributeBegin, AttributeDeclParen, PoundAvailablePlatform, - AssignmentRHS, CallArg, ReturnStmtExpr, YieldStmtExpr, diff --git a/include/swift/Parse/CodeCompletionCallbacks.h b/include/swift/Parse/CodeCompletionCallbacks.h index 6117ea5d9a2a9..cf18c459c642e 100644 --- a/include/swift/Parse/CodeCompletionCallbacks.h +++ b/include/swift/Parse/CodeCompletionCallbacks.h @@ -200,8 +200,6 @@ class CodeCompletionCallbacks { virtual void completeUnresolvedMember(CodeCompletionExpr *E, SourceLoc DotLoc) {}; - virtual void completeAssignmentRHS(AssignExpr *E) {}; - virtual void completeCallArg(CodeCompletionExpr *E, bool isFirst) {}; virtual void completeReturnStmt(CodeCompletionExpr *E) {}; diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index a716698f704ad..35ffe0227728f 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -1213,7 +1213,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks { std::vector RequestedModules; CodeCompletionConsumer &Consumer; CodeCompletionExpr *CodeCompleteTokenExpr = nullptr; - AssignExpr *AssignmentExpr; CompletionKind Kind = CompletionKind::None; Expr *ParsedExpr = nullptr; SourceLoc DotLoc; @@ -1367,7 +1366,6 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks { void completeImportDecl(std::vector> &Path) override; void completeUnresolvedMember(CodeCompletionExpr *E, SourceLoc DotLoc) override; - void completeAssignmentRHS(AssignExpr *E) override; void completeCallArg(CodeCompletionExpr *E, bool isFirst) override; void completeReturnStmt(CodeCompletionExpr *E) override; void completeYieldStmt(CodeCompletionExpr *E, @@ -4671,13 +4669,6 @@ void CodeCompletionCallbacksImpl::completeUnresolvedMember(CodeCompletionExpr *E this->DotLoc = DotLoc; } -void CodeCompletionCallbacksImpl::completeAssignmentRHS(AssignExpr *E) { - AssignmentExpr = E; - ParsedExpr = E->getDest(); - CurDeclContext = P.CurDeclContext; - Kind = CompletionKind::AssignmentRHS; -} - void CodeCompletionCallbacksImpl::completeCallArg(CodeCompletionExpr *E, bool isFirst) { CurDeclContext = P.CurDeclContext; @@ -4906,7 +4897,6 @@ void CodeCompletionCallbacksImpl::addKeywords(CodeCompletionResultSink &Sink, addDeclKeywords(Sink); addStmtKeywords(Sink, MaybeFuncBody); LLVM_FALLTHROUGH; - case CompletionKind::AssignmentRHS: case CompletionKind::ReturnStmtExpr: case CompletionKind::YieldStmtExpr: case CompletionKind::PostfixExprBeginning: @@ -5373,14 +5363,6 @@ void CodeCompletionCallbacksImpl::doneParsing() { Lookup.getUnresolvedMemberCompletions(ContextInfo.getPossibleTypes()); break; } - case CompletionKind::AssignmentRHS : { - SourceLoc Loc = P.Context.SourceMgr.getCodeCompletionLoc(); - if (auto destType = ParsedExpr->getType()) - Lookup.setExpectedTypes(destType->getRValueType(), - /*isSingleExpressionBody*/ false); - Lookup.getValueCompletionsInDeclContext(Loc, DefaultFilter); - break; - } case CompletionKind::CallArg : { ExprContextInfo ContextInfo(CurDeclContext, CodeCompleteTokenExpr); diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 211cf97860f73..ef530a814a7d8 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -279,28 +279,6 @@ ParserResult Parser::parseExprSequence(Diag<> Message, auto *assign = new (Context) AssignExpr(equalsLoc); SequencedExprs.push_back(assign); Message = diag::expected_expr_assignment; - if (Tok.is(tok::code_complete)) { - if (CodeCompletion) { - auto RHS = new (Context) ErrorExpr( - SourceRange(Tok.getRange().getStart(), Tok.getRange().getEnd())); - assign->setSrc(RHS); - SequencedExprs.pop_back(); - assign->setDest(SequencedExprs.back()); - SequencedExprs.pop_back(); - SequencedExprs.push_back(assign); - CodeCompletion->completeAssignmentRHS(assign); - } - consumeToken(); - if (!SequencedExprs.empty() && (SequencedExprs.size() & 1) == 0) { - // Make sure we have odd number of sequence exprs. - SequencedExprs.pop_back(); - } - auto Result = SequencedExprs.size() == 1 ? - makeParserResult(SequencedExprs[0]): - makeParserResult(SequenceExpr::create(Context, SequencedExprs)); - Result.setHasCodeCompletion(); - return Result; - } break; } diff --git a/test/IDE/complete_associated_types.swift b/test/IDE/complete_associated_types.swift index 711c615cf7525..6da3919844627 100644 --- a/test/IDE/complete_associated_types.swift +++ b/test/IDE/complete_associated_types.swift @@ -20,6 +20,15 @@ // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_1 > %t.types.txt // RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_1 < %t.types.txt +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_UNASSIGNABLE > %t.types.txt +// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_UNASSIGNABLE < %t.types.txt + +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_UNASSIGNABLE_2 > %t.types.txt +// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_UNASSIGNABLE < %t.types.txt + +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=BROKEN_CONFORMANCE_ASSIGNABLE > %t.types.txt +// RUN: %FileCheck %s -check-prefix=BROKEN_CONFORMANCE_ASSIGNABLE < %t.types.txt + // FIXME: extensions that introduce conformances? protocol FooBaseProtocolWithAssociatedTypes { @@ -300,3 +309,44 @@ func testBrokenConformances1() { // BROKEN_CONFORMANCE_1-DAG: Decl[InstanceMethod]/Super: deduceFooBaseC({#(self): StructWithBrokenConformance#})[#() -> StructWithBrokenConformance.FooBaseDeducedTypeC#]{{; name=.+$}} // BROKEN_CONFORMANCE_1-DAG: Decl[InstanceMethod]/Super: deduceFooBaseD({#(self): StructWithBrokenConformance#})[#() -> StructWithBrokenConformance.FooBaseDeducedTypeD#]{{; name=.+$}} // BROKEN_CONFORMANCE_1: End completions + + +protocol MyProto { + associatedtype Element +} + +extension MyProto { + var matches: (Int, (Int, Int)) { fatalError() } + func first() -> Element { + fatalError() + } +} + +// Does not conform - Element not specified +struct A: MyProto { + func foo() { + self.first = #^BROKEN_CONFORMANCE_UNASSIGNABLE^# + } + + func foo2() { + var (a, b): (Int, Int) + let exact = (1, (2, 4)) + (a, (b, self.first)) = #^BROKEN_CONFORMANCE_UNASSIGNABLE_2^# + } + + func foo3() { + var (a, b, c): (Int, Int, Int) + let exact = (1, (2, 4)) + (a, (b, c)) = #^BROKEN_CONFORMANCE_ASSIGNABLE^# + } +} +// BROKEN_CONFORMANCE_UNASSIGNABLE: Begin completions +// BROKEN_CONFORMANCE_UNASSIGNABLE-NOT: TypeRelation +// BROKEN_CONFORMANCE_UNASSIGNABLE: Decl[InstanceMethod]/Super: first()[#MyProto.Element#]; name=first() +// BROKEN_CONFORMANCE_UNASSIGNABLE-NOT: TypeRelation +// BROKEN_CONFORMANCE_UNASSIGNABLE: End completions + +// BROKEN_CONFORMANCE_ASSIGNABLE: Begin completions +// BROKEN_CONFORMANCE_ASSIGNABLE-DAG: Decl[LocalVar]/Local/TypeRelation[Identical]: exact[#(Int, (Int, Int))#]; name=exact +// BROKEN_CONFORMANCE_ASSIGNABLE-DAG: Decl[InstanceVar]/Super/TypeRelation[Identical]: matches[#(Int, (Int, Int))#]; name=matches +// BROKEN_CONFORMANCE_ASSIGNABLE: End completions diff --git a/tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp b/tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp index 4a376bf277898..2fc29e21328b1 100644 --- a/tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp +++ b/tools/SourceKit/lib/SwiftLang/CodeCompletionOrganizer.cpp @@ -176,7 +176,6 @@ bool SourceKit::CodeCompletion::addCustomCompletions( } break; case CompletionKind::PostfixExprBeginning: - case CompletionKind::AssignmentRHS: case CompletionKind::CallArg: case CompletionKind::ReturnStmtExpr: case CompletionKind::YieldStmtExpr: