@@ -269,12 +269,7 @@ class ResultBuilderTransform
269269 for (auto element : braceStmt->getElements ()) {
270270 if (auto unsupported =
271271 transformBraceElement (element, newBody, buildBlockArguments)) {
272- // When in code completion mode, simply ignore unsported constructs to
273- // get results for anything that's unrelated to the unsupported
274- // constructs.
275- if (!ctx.CompletionCallback ) {
276- return failTransform (*unsupported);
277- }
272+ return failTransform (*unsupported);
278273 }
279274 }
280275
@@ -780,16 +775,17 @@ class ResultBuilderTransform
780775#undef UNSUPPORTED_STMT
781776
782777private:
783- static bool isBuildableIfChainRecursive (IfStmt *ifStmt, unsigned &numPayloads,
784- bool &isOptional) {
778+ static void checkBuildableIfChainRecursive (IfStmt *ifStmt,
779+ unsigned &numPayloads,
780+ bool &isOptional) {
785781 // The 'then' clause contributes a payload.
786782 ++numPayloads;
787783
788784 // If there's an 'else' clause, it contributes payloads:
789785 if (auto elseStmt = ifStmt->getElseStmt ()) {
790786 // If it's 'else if', it contributes payloads recursively.
791787 if (auto elseIfStmt = dyn_cast<IfStmt>(elseStmt)) {
792- return isBuildableIfChainRecursive (elseIfStmt, numPayloads, isOptional);
788+ checkBuildableIfChainRecursive (elseIfStmt, numPayloads, isOptional);
793789 // Otherwise it's just the one.
794790 } else {
795791 ++numPayloads;
@@ -799,8 +795,6 @@ class ResultBuilderTransform
799795 } else {
800796 isOptional = true ;
801797 }
802-
803- return true ;
804798 }
805799
806800 static bool hasUnconditionalElse (IfStmt *ifStmt) {
@@ -815,8 +809,7 @@ class ResultBuilderTransform
815809
816810 bool isBuildableIfChain (IfStmt *ifStmt, unsigned &numPayloads,
817811 bool &isOptional) {
818- if (!isBuildableIfChainRecursive (ifStmt, numPayloads, isOptional))
819- return false ;
812+ checkBuildableIfChainRecursive (ifStmt, numPayloads, isOptional);
820813
821814 // If there's a missing 'else', we need 'buildOptional' to exist.
822815 if (isOptional && !builder.supportsOptional ())
@@ -991,11 +984,11 @@ TypeChecker::applyResultBuilderBodyTransform(FuncDecl *func, Type builderType) {
991984 // of this decl; it's not part of the interface type.
992985 builderType = func->mapTypeIntoContext (builderType);
993986
994- if ( auto result = cs. matchResultBuilder (
995- func, builderType, resultContextType, resultConstraintKind,
996- /* contextualType= */ Type () ,
997- cs.getConstraintLocator (func->getBody ()))) {
998- if (result->isFailure ())
987+ {
988+ auto result = cs. matchResultBuilder (
989+ func, builderType, resultContextType, resultConstraintKind ,
990+ /* contextualType= */ Type (), cs.getConstraintLocator (func->getBody ()));
991+ if (!result || result->isFailure ())
999992 return nullptr ;
1000993 }
1001994
@@ -1132,8 +1125,9 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
11321125 if (fn.bodyHasExplicitReturnStmt ()) {
11331126 // Diagnostic mode means that solver couldn't reach any viable
11341127 // solution, so let's diagnose presence of a `return` statement
1135- // in the closure body.
1136- if (shouldAttemptFixes ()) {
1128+ // in the closure body. Avoid doing this for completion since we need to
1129+ // continue solving the body.
1130+ if (shouldAttemptFixes () && !isForCodeCompletion ()) {
11371131 if (recordFix (IgnoreResultBuilderWithReturnStmts::create (
11381132 *this , builderType,
11391133 getConstraintLocator (fn.getAbstractClosureExpr ()))))
@@ -1157,18 +1151,17 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
11571151 auto *body = transform.apply (fn.getBody ());
11581152
11591153 if (auto unsupported = transform.getUnsupportedElement ()) {
1160- assert (!body || getASTContext ().CompletionCallback );
1161-
1162- // If we aren't supposed to attempt fixes, fail.
1163- if (!shouldAttemptFixes ()) {
1164- return getTypeMatchFailure (locator);
1165- }
1154+ assert (!body);
11661155
11671156 // If we're solving for code completion and the body contains the code
1168- // completion location, skipping it won't get us to a useful solution so
1169- // just bail.
1157+ // completion location, fall back to solving as a regular function body.
11701158 if (isForCodeCompletion () &&
11711159 containsIDEInspectionTarget (fn.getBody ())) {
1160+ return std::nullopt ;
1161+ }
1162+
1163+ // If we aren't supposed to attempt fixes, fail.
1164+ if (!shouldAttemptFixes ()) {
11721165 return getTypeMatchFailure (locator);
11731166 }
11741167
0 commit comments