Skip to content

Commit 1caf2c7

Browse files
committed
Sema: Fix code completion crash when a ParamDecl hasn't had its type set yet
We set the type of ParamDecls when applying solutions in the normal path, but sometimes code completion will type check an expression inside a closure without checking the outer expression. In this case, we may have inferred a type for the ParamDecl, but we don't write it back. Instead, just look at the DeclRefExpr's type. Fixes <rdar://problem/42098113>.
1 parent 88e4123 commit 1caf2c7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
584584
void checkNoEscapeParameterUse(DeclRefExpr *DRE, Expr *parent,
585585
OperandKind useKind) {
586586
// This only cares about declarations of noescape function type.
587-
auto AFT = DRE->getDecl()->getInterfaceType()->getAs<AnyFunctionType>();
587+
auto AFT = DRE->getType()->getAs<FunctionType>();
588588
if (!AFT || !AFT->isNoEscape())
589589
return;
590590

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename %s
2+
3+
func test() {
4+
let cl = { arg in
5+
let name = arg as String
6+
#^A^#
7+
}
8+
}

0 commit comments

Comments
 (0)