Skip to content

[6.2] [Sema] Avoid folding sequences multiple times for completion #83036

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 2 commits into from
Jul 15, 2025
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
8 changes: 8 additions & 0 deletions lib/Sema/TypeCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,14 @@ swift::DefaultTypeRequest::evaluate(Evaluator &evaluator,
}

Expr *TypeChecker::foldSequence(SequenceExpr *expr, DeclContext *dc) {
// We may end up running pre-checking multiple times for completion, just use
// the folded expression if we've already folded the sequence.
// FIXME: We ought to fix completion to not pre-check multiple times, strictly
// speaking it isn't idempotent (e.g for things like `markDirectCallee`).
if (dc->getASTContext().CompletionCallback) {
if (auto *folded = expr->getFoldedExpr())
return folded;
}
// First resolve any unresolved decl references in operator positions.
for (auto i : indices(expr->getElements())) {
if (i % 2 == 0)
Expand Down
17 changes: 17 additions & 0 deletions validation-test/IDE/issues_fixed/issue-75845.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %batch-code-completion

// https://github.com/apple/swift/issues/75845
// Make sure we don't crash.

struct Foo {
init() {
do {
} catch {
#^A^#self#^B^# = #^C^#error#^D^#
}
}
}
// A: Decl[LocalVar]/Local: error[#any Error#]; name=error
// B: Begin completions
// C: Decl[LocalVar]/Local: error[#any Error#]; name=error
// D: Begin completions