Skip to content

Commit 234a415

Browse files
authored
Merge pull request #83036 from hamishknight/origami-6.2
[6.2] [Sema] Avoid folding sequences multiple times for completion
2 parents e5c2346 + e653a22 commit 234a415

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/Sema/TypeCheckExpr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,14 @@ swift::DefaultTypeRequest::evaluate(Evaluator &evaluator,
633633
}
634634

635635
Expr *TypeChecker::foldSequence(SequenceExpr *expr, DeclContext *dc) {
636+
// We may end up running pre-checking multiple times for completion, just use
637+
// the folded expression if we've already folded the sequence.
638+
// FIXME: We ought to fix completion to not pre-check multiple times, strictly
639+
// speaking it isn't idempotent (e.g for things like `markDirectCallee`).
640+
if (dc->getASTContext().CompletionCallback) {
641+
if (auto *folded = expr->getFoldedExpr())
642+
return folded;
643+
}
636644
// First resolve any unresolved decl references in operator positions.
637645
for (auto i : indices(expr->getElements())) {
638646
if (i % 2 == 0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %batch-code-completion
2+
3+
// https://github.com/apple/swift/issues/75845
4+
// Make sure we don't crash.
5+
6+
struct Foo {
7+
init() {
8+
do {
9+
} catch {
10+
#^A^#self#^B^# = #^C^#error#^D^#
11+
}
12+
}
13+
}
14+
// A: Decl[LocalVar]/Local: error[#any Error#]; name=error
15+
// B: Begin completions
16+
// C: Decl[LocalVar]/Local: error[#any Error#]; name=error
17+
// D: Begin completions

0 commit comments

Comments
 (0)