Skip to content

Commit d6d966a

Browse files
author
marcrasi
authored
handle diags that happen during repl code completion (#24918)
1 parent 528fb67 commit d6d966a

File tree

6 files changed

+15
-26
lines changed

6 files changed

+15
-26
lines changed

lib/IDE/REPLCodeCompletion.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "swift/IDE/REPLCodeCompletion.h"
1818
#include "swift/AST/ASTContext.h"
19+
#include "swift/AST/DiagnosticSuppression.h"
1920
#include "swift/AST/Module.h"
2021
#include "swift/Basic/LLVM.h"
2122
#include "swift/Basic/SourceManager.h"
@@ -193,7 +194,7 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID,
193194
CodeCompletionCallbacksFactory *CompletionCallbacksFactory) {
194195
// Temporarily disable printing the diagnostics.
195196
ASTContext &Ctx = SF.getASTContext();
196-
DiagnosticTransaction DelayedDiags(Ctx.Diags);
197+
DiagnosticSuppression SuppressedDiags(Ctx.Diags);
197198

198199
std::string AugmentedCode = EnteredCode.str();
199200
AugmentedCode += '\0';
@@ -222,7 +223,10 @@ doCodeCompletion(SourceFile &SF, StringRef EnteredCode, unsigned *BufferID,
222223
// Now we are done with code completion. Remove the declarations we
223224
// temporarily inserted.
224225
SF.Decls.resize(OriginalDeclCount);
225-
DelayedDiags.abort();
226+
227+
// Reset the error state because it's only relevant to the code that we just
228+
// processed, which now gets thrown away.
229+
Ctx.Diags.resetHadAnyError();
226230
}
227231

228232
void REPLCompletions::populate(SourceFile &SF, StringRef EnteredCode) {

lib/Sema/TypeCheckREPL.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,6 @@ void REPLChecker::generatePrintOfExpression(StringRef NameStr, Expr *E) {
286286
/// When we see an expression in a TopLevelCodeDecl in the REPL, process it,
287287
/// adding the proper decls back to the top level of the file.
288288
void REPLChecker::processREPLTopLevelExpr(Expr *E) {
289-
// Don't try to print expressions without types.
290-
if (!E->getType())
291-
return;
292-
293289
CanType T = E->getType()->getCanonicalType();
294290

295291
// Don't try to print invalid expressions, module exprs, or void expressions.

lib/Sema/TypeCheckStmt.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
550550
Type contextType = yieldType;
551551
if (yieldResults[i].isInOut()) {
552552
contextTypePurpose = CTP_YieldByReference;
553-
if (!contextType->hasError())
554-
contextType = LValueType::get(contextType);
553+
contextType = LValueType::get(contextType);
555554

556555
// Check that the yielded expression is a &.
557556
if ((inout = dyn_cast<InOutExpr>(exprToCheck))) {

test/IDE/complete_tf_194.swift

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

test/IDE/complete_tf_195.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// While running completion on this, the typechecker produces a diagnostic and
2+
// an AST with an error type. If the ASTVerifier ran on the AST with the error
3+
// type, then it would fail. This test verifies that the ASTVerifier does not
4+
// run on ASTs with error types produced by completion requests.
5+
6+
// RUN: %target-swift-ide-test -repl-code-completion -source-filename=%s
7+
8+
let bar: NotARealType = 0; ba

0 commit comments

Comments
 (0)