@@ -2104,7 +2104,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
21042104 NullablePtr<Stmt> transformIf (IfStmt *ifStmt, TypeJoinExpr *join,
21052105 unsigned index) {
21062106 // FIXME: Turn this into a condition once warning is an error.
2107- (void )diagnoseMissingBuildWithAvailability (ifStmt);
2107+ (void )diagnoseMissingBuildWithAvailability (ifStmt, join );
21082108
21092109 auto *joinVar = join->getVar ();
21102110
@@ -2206,7 +2206,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
22062206 // / have had the chance to adopt buildLimitedAvailability(), we'll upgrade
22072207 // / this warning to an error.
22082208 LLVM_NODISCARD
2209- bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt) {
2209+ bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt,
2210+ TypeJoinExpr *join) {
22102211 auto findAvailabilityCondition =
22112212 [](StmtCondition stmtCond) -> const StmtConditionElement * {
22122213 for (const auto &cond : stmtCond) {
@@ -2230,27 +2231,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
22302231 return false ;
22312232
22322233 SourceLoc loc = availabilityCond->getStartLoc ();
2233- Type bodyType;
2234- if (availabilityCond->getAvailability ()->isUnavailability ()) {
2235- BraceStmt *elseBody = nullptr ;
2236- // For #unavailable, we need to check the "else".
2237- if (auto *innerIf = getAsStmt<IfStmt>(ifStmt->getElseStmt ())) {
2238- elseBody = castToStmt<BraceStmt>(innerIf->getThenStmt ());
2239- } else {
2240- elseBody = castToStmt<BraceStmt>(ifStmt->getElseStmt ());
2241- }
2242-
2243- Type elseBodyType =
2244- solution.simplifyType (solution.getType (elseBody->getLastElement ()));
2245- bodyType = elseBodyType;
2246- } else {
2247- auto *thenBody = castToStmt<BraceStmt>(ifStmt->getThenStmt ());
2248- Type thenBodyType =
2249- solution.simplifyType (solution.getType (thenBody->getLastElement ()));
2250- bodyType = thenBodyType;
2251- }
2252-
22532234 auto builderType = solution.simplifyType (Transform.builderType );
2235+ // Since all of the branches of `if` statement have to join into the same
2236+ // type we can just use the type of the join variable here.
2237+ Type bodyType = solution.getResolvedType (join->getVar ());
22542238
22552239 return bodyType.findIf ([&](Type type) {
22562240 auto nominal = type->getAnyNominal ();
0 commit comments