Skip to content

Commit 3c03449

Browse files
committed
[MiscDiagnostics] OpaqueTypes: Handle unrelated #available conditions gracefully
`OpaqueUnderlyingTypeChecker` should skip conditional availability blocks if none of the conditions restrict the current target. Resolves: rdar://103445432
1 parent d6ed370 commit 3c03449

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
@@ -3068,13 +3068,22 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
30683068

30693069
SmallVector<AvailabilityCondition, 4> conditions;
30703070

3071-
llvm::transform(availabilityContext->getCond(),
3072-
std::back_inserter(conditions),
3073-
[&](const StmtConditionElement &elt) {
3074-
auto condition = elt.getAvailability();
3075-
return std::make_pair(condition->getAvailableRange(),
3076-
condition->isUnavailability());
3077-
});
3071+
for (const auto &elt : availabilityContext->getCond()) {
3072+
auto condition = elt.getAvailability();
3073+
3074+
auto availabilityRange = condition->getAvailableRange();
3075+
// If there is no lower endpoint it means that the
3076+
// current platform is unrelated to this condition
3077+
// and we can ignore it.
3078+
if (!availabilityRange.hasLowerEndpoint())
3079+
continue;
3080+
3081+
conditions.push_back(
3082+
{availabilityRange, condition->isUnavailability()});
3083+
}
3084+
3085+
if (conditions.empty())
3086+
continue;
30783087

30793088
conditionalSubstitutions.push_back(
30803089
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)