@@ -2111,7 +2111,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2111
2111
NullablePtr<Stmt> transformIf (IfStmt *ifStmt, TypeJoinExpr *join,
2112
2112
unsigned index) {
2113
2113
// FIXME: Turn this into a condition once warning is an error.
2114
- (void )diagnoseMissingBuildWithAvailability (ifStmt);
2114
+ (void )diagnoseMissingBuildWithAvailability (ifStmt, join );
2115
2115
2116
2116
auto *joinVar = join->getVar ();
2117
2117
@@ -2213,7 +2213,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2213
2213
// / have had the chance to adopt buildLimitedAvailability(), we'll upgrade
2214
2214
// / this warning to an error.
2215
2215
LLVM_NODISCARD
2216
- bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt) {
2216
+ bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt,
2217
+ TypeJoinExpr *join) {
2217
2218
auto findAvailabilityCondition =
2218
2219
[](StmtCondition stmtCond) -> const StmtConditionElement * {
2219
2220
for (const auto &cond : stmtCond) {
@@ -2237,27 +2238,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2237
2238
return false ;
2238
2239
2239
2240
SourceLoc loc = availabilityCond->getStartLoc ();
2240
- Type bodyType;
2241
- if (availabilityCond->getAvailability ()->isUnavailability ()) {
2242
- BraceStmt *elseBody = nullptr ;
2243
- // For #unavailable, we need to check the "else".
2244
- if (auto *innerIf = getAsStmt<IfStmt>(ifStmt->getElseStmt ())) {
2245
- elseBody = castToStmt<BraceStmt>(innerIf->getThenStmt ());
2246
- } else {
2247
- elseBody = castToStmt<BraceStmt>(ifStmt->getElseStmt ());
2248
- }
2249
-
2250
- Type elseBodyType =
2251
- solution.simplifyType (solution.getType (elseBody->getLastElement ()));
2252
- bodyType = elseBodyType;
2253
- } else {
2254
- auto *thenBody = castToStmt<BraceStmt>(ifStmt->getThenStmt ());
2255
- Type thenBodyType =
2256
- solution.simplifyType (solution.getType (thenBody->getLastElement ()));
2257
- bodyType = thenBodyType;
2258
- }
2259
-
2260
2241
auto builderType = solution.simplifyType (Transform.builderType );
2242
+ // Since all of the branches of `if` statement have to join into the same
2243
+ // type we can just use the type of the join variable here.
2244
+ Type bodyType = solution.getResolvedType (join->getVar ());
2261
2245
2262
2246
return bodyType.findIf ([&](Type type) {
2263
2247
auto nominal = type->getAnyNominal ();
0 commit comments