Skip to content

Commit b9562e1

Browse files
authored
Merge pull request #63807 from xedin/issue-63764-5.8
[5.8][BuilderTransform] Rework missing `buildWithLimitedAvailability` detection
2 parents f3e0dd7 + 4b2f803 commit b9562e1

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

lib/Sema/CSSyntacticElement.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
18911891
NullablePtr<Stmt> transformIf(IfStmt *ifStmt, TypeJoinExpr *join,
18921892
unsigned index) {
18931893
// FIXME: Turn this into a condition once warning is an error.
1894-
(void)diagnoseMissingBuildWithAvailability(ifStmt);
1894+
(void)diagnoseMissingBuildWithAvailability(ifStmt, join);
18951895

18961896
auto *joinVar = join->getVar();
18971897

@@ -1993,7 +1993,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
19931993
/// have had the chance to adopt buildLimitedAvailability(), we'll upgrade
19941994
/// this warning to an error.
19951995
LLVM_NODISCARD
1996-
bool diagnoseMissingBuildWithAvailability(IfStmt *ifStmt) {
1996+
bool diagnoseMissingBuildWithAvailability(IfStmt *ifStmt,
1997+
TypeJoinExpr *join) {
19971998
auto findAvailabilityCondition =
19981999
[](StmtCondition stmtCond) -> const StmtConditionElement * {
19992000
for (const auto &cond : stmtCond) {
@@ -2017,27 +2018,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
20172018
return false;
20182019

20192020
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-
20402021
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());
20412025

20422026
return bodyType.findIf([&](Type type) {
20432027
auto nominal = type->getAnyNominal();

test/Constraints/result_builder_availability.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ tuplify(true) { cond in
103103
globalFuncAvailableOn10_52()
104104
} else if false {
105105
globalFuncAvailableOn10_52()
106-
} else {
107-
globalFuncAvailableOn10_52()
108106
}
109107
}
110108
}
@@ -166,6 +164,11 @@ tuplifyWithAvailabilityErasure(true) { cond in
166164
} else {
167165
globalFuncAvailableOn10_52()
168166
}
167+
168+
// https://github.com/apple/swift/issues/63764
169+
if #unavailable(OSX 10.52) {
170+
cond // Ok
171+
}
169172
}
170173

171174
// rdar://97533700 – Make sure we can prefer an unavailable buildPartialBlock if

0 commit comments

Comments
 (0)