@@ -242,7 +242,9 @@ class TypeVariableRefFinder : public ASTWalker {
242242// MARK: Constraint generation
243243
244244// / Check whether it makes sense to convert this element into a constraint.
245- static bool isViableElement (ASTNode element) {
245+ static bool isViableElement (ASTNode element,
246+ bool isForSingleValueStmtCompletion,
247+ ConstraintSystem &cs) {
246248 if (auto *decl = element.dyn_cast <Decl *>()) {
247249 // - Ignore variable declarations, they are handled by pattern bindings;
248250 // - Ignore #if, the chosen children should appear in the
@@ -255,10 +257,21 @@ static bool isViableElement(ASTNode element) {
255257 }
256258
257259 if (auto *stmt = element.dyn_cast <Stmt *>()) {
258- // Empty brace statements are now viable because they do not require
259- // inference.
260260 if (auto *braceStmt = dyn_cast<BraceStmt>(stmt)) {
261- return braceStmt->getNumElements () > 0 ;
261+ // Empty brace statements are not viable because they do not require
262+ // inference.
263+ if (braceStmt->empty ())
264+ return false ;
265+
266+ // Skip if we're doing completion for a SingleValueStmtExpr, and have a
267+ // brace that doesn't involve a single expression, and doesn't have a
268+ // code completion token, as it won't contribute to the type of the
269+ // SingleValueStmtExpr.
270+ if (isForSingleValueStmtCompletion &&
271+ !braceStmt->getSingleActiveExpression () &&
272+ !cs.containsIDEInspectionTarget (braceStmt)) {
273+ return false ;
274+ }
262275 }
263276 }
264277
@@ -324,13 +337,19 @@ static void createConjunction(ConstraintSystem &cs,
324337
325338 VarRefCollector paramCollector (cs);
326339
340+ // Whether we're doing completion, and the conjunction is for a
341+ // SingleValueStmtExpr, or one of its braces.
342+ const auto isForSingleValueStmtCompletion =
343+ cs.isForCodeCompletion () &&
344+ locator->isForSingleValueStmtConjunctionOrBrace ();
345+
327346 for (const auto &entry : elements) {
328347 ASTNode element = std::get<0 >(entry);
329348 ContextualTypeInfo context = std::get<1 >(entry);
330349 bool isDiscarded = std::get<2 >(entry);
331350 ConstraintLocator *elementLoc = std::get<3 >(entry);
332351
333- if (!isViableElement (element))
352+ if (!isViableElement (element, isForSingleValueStmtCompletion, cs ))
334353 continue ;
335354
336355 // If this conjunction going to represent a body of a closure,
0 commit comments