Skip to content

Commit faf0da9

Browse files
authored
Merge pull request #62889 from xedin/rdar-103445432-5.8
[5.8][MiscDiagnostics] OpaqueTypes: Handle unrelated #available conditions gracefully
2 parents 6e84f8a + 29c1a17 commit faf0da9

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,13 +3041,22 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
30413041

30423042
SmallVector<AvailabilityCondition, 4> conditions;
30433043

3044-
llvm::transform(availabilityContext->getCond(),
3045-
std::back_inserter(conditions),
3046-
[&](const StmtConditionElement &elt) {
3047-
auto condition = elt.getAvailability();
3048-
return std::make_pair(condition->getAvailableRange(),
3049-
condition->isUnavailability());
3050-
});
3044+
for (const auto &elt : availabilityContext->getCond()) {
3045+
auto condition = elt.getAvailability();
3046+
3047+
auto availabilityRange = condition->getAvailableRange();
3048+
// If there is no lower endpoint it means that the
3049+
// current platform is unrelated to this condition
3050+
// and we can ignore it.
3051+
if (!availabilityRange.hasLowerEndpoint())
3052+
continue;
3053+
3054+
conditions.push_back(
3055+
{availabilityRange, condition->isUnavailability()});
3056+
}
3057+
3058+
if (conditions.empty())
3059+
continue;
30513060

30523061
conditionalSubstitutions.push_back(
30533062
OpaqueTypeDecl::ConditionallyAvailableSubstitutions::get(

test/Serialization/Inputs/opaque_with_limited_availability.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,14 @@ public func test_return_from_conditional() -> some P {
6767

6868
return Tuple<(String, Int)>(("", 0))
6969
}
70+
71+
// This used to crash during serialization because
72+
// @available negates availability condition.
73+
@available(macOS, unavailable)
74+
public func testUnusable() -> some P {
75+
if #available(iOS 50, *) {
76+
return Named()
77+
}
78+
79+
return Tuple<(String, Int)>(("", 0))
80+
}

0 commit comments

Comments
 (0)