Skip to content

Commit 45edfc3

Browse files
authored
Merge pull request #63768 from xedin/issue-63764
[BuilderTransform] Rework missing `buildWithLimitedAvailability` detection
2 parents aec5bc5 + c4ea02c commit 45edfc3

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
@@ -2111,7 +2111,7 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
21112111
NullablePtr<Stmt> transformIf(IfStmt *ifStmt, TypeJoinExpr *join,
21122112
unsigned index) {
21132113
// FIXME: Turn this into a condition once warning is an error.
2114-
(void)diagnoseMissingBuildWithAvailability(ifStmt);
2114+
(void)diagnoseMissingBuildWithAvailability(ifStmt, join);
21152115

21162116
auto *joinVar = join->getVar();
21172117

@@ -2213,7 +2213,8 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
22132213
/// have had the chance to adopt buildLimitedAvailability(), we'll upgrade
22142214
/// this warning to an error.
22152215
LLVM_NODISCARD
2216-
bool diagnoseMissingBuildWithAvailability(IfStmt *ifStmt) {
2216+
bool diagnoseMissingBuildWithAvailability(IfStmt *ifStmt,
2217+
TypeJoinExpr *join) {
22172218
auto findAvailabilityCondition =
22182219
[](StmtCondition stmtCond) -> const StmtConditionElement * {
22192220
for (const auto &cond : stmtCond) {
@@ -2237,27 +2238,10 @@ class ResultBuilderRewriter : public SyntacticElementSolutionApplication {
22372238
return false;
22382239

22392240
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-
22602241
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());
22612245

22622246
return bodyType.findIf([&](Type type) {
22632247
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)