Skip to content

[MiscDiagnostics] OpaqueTypes: Handle unrelated #available conditions… #62856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3068,13 +3068,22 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {

SmallVector<AvailabilityCondition, 4> conditions;

llvm::transform(availabilityContext->getCond(),
std::back_inserter(conditions),
[&](const StmtConditionElement &elt) {
auto condition = elt.getAvailability();
return std::make_pair(condition->getAvailableRange(),
condition->isUnavailability());
});
for (const auto &elt : availabilityContext->getCond()) {
auto condition = elt.getAvailability();

auto availabilityRange = condition->getAvailableRange();
// If there is no lower endpoint it means that the
// current platform is unrelated to this condition
// and we can ignore it.
if (!availabilityRange.hasLowerEndpoint())
continue;

conditions.push_back(
{availabilityRange, condition->isUnavailability()});
}

if (conditions.empty())
continue;

conditionalSubstitutions.push_back(
OpaqueTypeDecl::ConditionallyAvailableSubstitutions::get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ public func test_return_from_conditional() -> some P {

return Tuple<(String, Int)>(("", 0))
}

// This used to crash during serialization because
// @available negates availability condition.
@available(macOS, unavailable)
public func testUnusable() -> some P {
if #available(iOS 50, *) {
return Named()
}

return Tuple<(String, Int)>(("", 0))
}