Skip to content
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
34 changes: 22 additions & 12 deletions lib/Sema/TypeCheckStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2671,18 +2671,28 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
// function, we unfortunately need to type-check everything since we need to
// apply the solution.
// FIXME: We ought to see if we can do better in that case.
if (auto *CE = DC->getInnermostClosureForCaptures()) {
if (CE->getBodyState() == ClosureExpr::BodyState::Parsed) {
swift::typeCheckASTNodeAtLoc(
TypeCheckASTNodeAtLocContext::declContext(CE->getParent()),
CE->getLoc());

// If the context itself is a ClosureExpr, we should have type-checked
// the completion expression now. If it's a nested local declaration,
// fall through to type-check the AST node now that we've type-checked
// the surrounding closure.
if (isa<ClosureExpr>(DC))
return false;
//
// We don't need to do this for unattached nodes since we already would have
// type-checked the surrounding context, and unattached nodes cannot be
// typechecked via DeclContext since they aren't actually part of the AST.
if (!typeCheckCtx.isForUnattachedNode()) {
if (auto *CE = DC->getInnermostClosureForCaptures()) {
// Walk up to the parent-most closure.
while (auto *parent = dyn_cast_or_null<ClosureExpr>(CE->getParent()))
CE = parent;

if (CE->getBodyState() == ClosureExpr::BodyState::Parsed) {
swift::typeCheckASTNodeAtLoc(
TypeCheckASTNodeAtLocContext::declContext(CE->getParent()),
CE->getLoc());

// If the context itself is a ClosureExpr, we should have type-checked
// the completion expression now. If it's a nested local declaration,
// fall through to type-check the AST node now that we've type-checked
// the surrounding closure.
if (isa<ClosureExpr>(DC))
return false;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// {"kind":"complete","signature":"swift::SourceManager::findBufferContainingLocInternal(swift::SourceLoc) const","signatureAssert":"Assertion failed: (Loc.isValid()), function findBufferContainingLocInternal"}
// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
class a { lazy b: () = { answer {}#^^#
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// {"kind":"complete","original":"7bbb1dc5","signature":"swift::TypeRepr::print(swift::ASTPrinter&, swift::PrintOptions const&, swift::optionset::OptionSet<swift::NonRecursivePrintOption, unsigned int>) const","signatureAssert":"Assertion failed: (false && \"Expression wasn't type checked?\"), function getTypeForCompletion"}
// RUN: not --crash %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
// RUN: %target-swift-ide-test -code-completion -batch-code-completion -skip-filecheck -code-completion-diagnostics -source-filename %s
a ? {
init { b { extension
}#^^#