Skip to content

[CodeCompletion] Allow preChecking an expression twice in code completion #38474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions lib/Sema/TypeCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,31 +355,51 @@ static Expr *makeBinOp(ASTContext &Ctx, Expr *Op, Expr *LHS, Expr *RHS,

if (auto *ifExpr = dyn_cast<IfExpr>(Op)) {
// Resolve the ternary expression.
assert(!ifExpr->isFolded() && "already folded if expr in sequence?!");
if (!Ctx.CompletionCallback) {
// In code completion we might call preCheckExpression twice - once for
// the first pass and once for the second pass. This is fine since
// preCheckExpression idempotent.
assert(!ifExpr->isFolded() && "already folded if expr in sequence?!");
}
ifExpr->setCondExpr(LHS);
ifExpr->setElseExpr(RHS);
return ifExpr;
}

if (auto *assign = dyn_cast<AssignExpr>(Op)) {
// Resolve the assignment expression.
assert(!assign->isFolded() && "already folded assign expr in sequence?!");
if (!Ctx.CompletionCallback) {
// In code completion we might call preCheckExpression twice - once for
// the first pass and once for the second pass. This is fine since
// preCheckExpression idempotent.
assert(!assign->isFolded() && "already folded assign expr in sequence?!");
}
assign->setDest(LHS);
assign->setSrc(RHS);
return assign;
}

if (auto *as = dyn_cast<ExplicitCastExpr>(Op)) {
// Resolve the 'as' or 'is' expression.
assert(!as->isFolded() && "already folded 'as' expr in sequence?!");
if (!Ctx.CompletionCallback) {
// In code completion we might call preCheckExpression twice - once for
// the first pass and once for the second pass. This is fine since
// preCheckExpression idempotent.
assert(!as->isFolded() && "already folded 'as' expr in sequence?!");
}
assert(RHS == as && "'as' with non-type RHS?!");
as->setSubExpr(LHS);
return as;
}

if (auto *arrow = dyn_cast<ArrowExpr>(Op)) {
// Resolve the '->' expression.
assert(!arrow->isFolded() && "already folded '->' expr in sequence?!");
if (!Ctx.CompletionCallback) {
// In code completion we might call preCheckExpression twice - once for
// the first pass and once for the second pass. This is fine since
// preCheckExpression idempotent.
assert(!arrow->isFolded() && "already folded '->' expr in sequence?!");
}
arrow->setArgsExpr(LHS);
arrow->setResultExpr(RHS);
return arrow;
Expand Down
3 changes: 3 additions & 0 deletions validation-test/IDE/crashers_2_fixed/sr14755.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %swift-ide-test --code-completion --source-filename %s --code-completion-token=COMPLETE

Foo.#^COMPLETE^#bar ?? baz(_) = baba