Skip to content

Commit de85804

Browse files
authored
Merge pull request #6087 from akyrtzi/fix-ide-crash-084
2 parents df756f8 + fc67874 commit de85804

File tree

8 files changed

+11
-16
lines changed

8 files changed

+11
-16
lines changed

include/swift/AST/Expr.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,10 +749,6 @@ class CodeCompletionExpr : public Expr {
749749
Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Ty),
750750
Range(Range) {}
751751

752-
CodeCompletionExpr(CharSourceRange Range, Type Ty = Type()) :
753-
Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Ty),
754-
Range(SourceRange(Range.getStart(), Range.getEnd())) {}
755-
756752
SourceRange getSourceRange() const { return Range; }
757753

758754
static bool classof(const Expr *E) {

lib/Parse/ParseExpr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
14021402
#include "swift/Parse/Tokens.def"
14031403

14041404
case tok::code_complete:
1405-
Result = makeParserResult(new (Context) CodeCompletionExpr(Tok.getRange()));
1405+
Result = makeParserResult(new (Context) CodeCompletionExpr(Tok.getLoc()));
14061406
Result.setHasCodeCompletion();
14071407
if (CodeCompletion &&
14081408
// We cannot code complete anything after var/let.
@@ -2747,7 +2747,7 @@ Parser::parseExprCallSuffix(ParserResult<Expr> fn, bool isExprBasic) {
27472747
// callback.
27482748
if (peekToken().is(tok::code_complete) && CodeCompletion) {
27492749
consumeToken(tok::l_paren);
2750-
auto CCE = new (Context) CodeCompletionExpr(Tok.getRange());
2750+
auto CCE = new (Context) CodeCompletionExpr(Tok.getLoc());
27512751
auto Result = makeParserResult(
27522752
CallExpr::create(Context, fn.get(), SourceLoc(),
27532753
{ CCE },

lib/Parse/ParsePattern.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ ParserResult<Pattern> Parser::parseTypedPattern() {
749749
if (!Ty.isNull()) {
750750
// Attempt to diagnose initializer calls incorrectly written
751751
// as typed patterns, such as "var x: [Int]()".
752-
if (Tok.isFollowingLParen()) {
752+
// Disable this tentative parse when in code-completion mode, otherwise
753+
// code-completion may enter the delayed-decl state twice.
754+
if (Tok.isFollowingLParen() && !L->isCodeCompletion()) {
753755
BacktrackingScope backtrack(*this);
754756

755757
// Create a local context if needed so we can parse trailing closures.

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,9 @@ ParserStatus Parser::parseStmtCondition(StmtCondition &Condition,
12241224

12251225
// Handle code completion after the #.
12261226
if (Tok.is(tok::pound) && peekToken().is(tok::code_complete)) {
1227-
auto PoundPos = consumeToken();
1227+
consumeToken(); // '#' token.
12281228
auto CodeCompletionPos = consumeToken();
1229-
auto Expr = new (Context) CodeCompletionExpr(CharSourceRange(SourceMgr,
1230-
PoundPos, CodeCompletionPos));
1229+
auto Expr = new (Context) CodeCompletionExpr(CodeCompletionPos);
12311230
if (CodeCompletion)
12321231
CodeCompletion->completeAfterPound(Expr, ParentKind);
12331232
result.push_back(Expr);

validation-test/IDE/crashers/084-swift-parser-consumedecl.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.

validation-test/IDE/crashers/104-swift-gettypeofcompletioncontextexpr.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
let:n(f{var _=#^A^#
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
{let:e(var d#^A^#

0 commit comments

Comments
 (0)