Skip to content

Commit fb268e5

Browse files
author
Marc Rasi
committed
handle diags that happen during repl code completion
1 parent d744ab0 commit fb268e5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
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) {
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)