@@ -1891,7 +1891,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
1891
1891
NullablePtr<Stmt> transformIf (IfStmt *ifStmt, TypeJoinExpr *join,
1892
1892
unsigned index) {
1893
1893
// FIXME: Turn this into a condition once warning is an error.
1894
- (void )diagnoseMissingBuildWithAvailability (ifStmt);
1894
+ (void )diagnoseMissingBuildWithAvailability (ifStmt, join );
1895
1895
1896
1896
auto *joinVar = join->getVar ();
1897
1897
@@ -1993,7 +1993,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
1993
1993
// / have had the chance to adopt buildLimitedAvailability(), we'll upgrade
1994
1994
// / this warning to an error.
1995
1995
LLVM_NODISCARD
1996
- bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt) {
1996
+ bool diagnoseMissingBuildWithAvailability (IfStmt *ifStmt,
1997
+ TypeJoinExpr *join) {
1997
1998
auto findAvailabilityCondition =
1998
1999
[](StmtCondition stmtCond) -> const StmtConditionElement * {
1999
2000
for (const auto &cond : stmtCond) {
@@ -2017,27 +2018,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
2017
2018
return false ;
2018
2019
2019
2020
SourceLoc loc = availabilityCond->getStartLoc ();
2020
- Type bodyType;
2021
- if (availabilityCond->getAvailability ()->isUnavailability ()) {
2022
- BraceStmt *elseBody = nullptr ;
2023
- // For #unavailable, we need to check the "else".
2024
- if (auto *innerIf = getAsStmt<IfStmt>(ifStmt->getElseStmt ())) {
2025
- elseBody = castToStmt<BraceStmt>(innerIf->getThenStmt ());
2026
- } else {
2027
- elseBody = castToStmt<BraceStmt>(ifStmt->getElseStmt ());
2028
- }
2029
-
2030
- Type elseBodyType =
2031
- solution.simplifyType (solution.getType (elseBody->getLastElement ()));
2032
- bodyType = elseBodyType;
2033
- } else {
2034
- auto *thenBody = castToStmt<BraceStmt>(ifStmt->getThenStmt ());
2035
- Type thenBodyType =
2036
- solution.simplifyType (solution.getType (thenBody->getLastElement ()));
2037
- bodyType = thenBodyType;
2038
- }
2039
-
2040
2021
auto builderType = solution.simplifyType (Transform.builderType );
2022
+ // Since all of the branches of `if` statement have to join into the same
2023
+ // type we can just use the type of the join variable here.
2024
+ Type bodyType = solution.getResolvedType (join->getVar ());
2041
2025
2042
2026
return bodyType.findIf ([&](Type type) {
2043
2027
auto nominal = type->getAnyNominal ();
0 commit comments