@@ -2104,7 +2104,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2104
2104
NullablePtr<Stmt> transformIf (IfStmt *ifStmt, TypeJoinExpr *join,
2105
2105
unsigned index) {
2106
2106
// FIXME: Turn this into a condition once warning is an error.
2107
- (void )diagnoseMissingBuildWithAvailability (ifStmt);
2107
+ (void )diagnoseMissingBuildWithAvailability (ifStmt, join );
2108
2108
2109
2109
auto *joinVar = join->getVar ();
2110
2110
@@ -2206,7 +2206,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2206
2206
// / have had the chance to adopt buildLimitedAvailability(), we'll upgrade
2207
2207
// / this warning to an error.
2208
2208
LLVM_NODISCARD
2209
- bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt) {
2209
+ bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt,
2210
+ TypeJoinExpr *join) {
2210
2211
auto findAvailabilityCondition =
2211
2212
[](StmtCondition stmtCond) -> const StmtConditionElement * {
2212
2213
for (const auto &cond : stmtCond) {
@@ -2230,27 +2231,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2230
2231
return false ;
2231
2232
2232
2233
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
-
2253
2234
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 ());
2254
2238
2255
2239
return bodyType.findIf ([&](Type type) {
2256
2240
auto nominal = type->getAnyNominal ();
0 commit comments