Skip to content

Sema: Avoid use @_spi instead diagnostic on nested decls with @_spi_available #63197

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
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
16 changes: 10 additions & 6 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4509,12 +4509,16 @@ void AttributeChecker::checkOriginalDefinedInAttrs(
void AttributeChecker::checkAvailableAttrs(ArrayRef<AvailableAttr *> Attrs) {
if (Attrs.empty())
return;
// If all available are spi available, we should use @_spi instead.
if (std::all_of(Attrs.begin(), Attrs.end(), [](AvailableAttr *AV) {
return AV->IsSPI;
})) {
diagnose(D->getLoc(), diag::spi_preferred_over_spi_available);
};

// Only diagnose top level decls since nested ones may have inherited availability.
if (!D->getDeclContext()->getInnermostDeclarationDeclContext()) {
// If all available are spi available, we should use @_spi instead.
if (std::all_of(Attrs.begin(), Attrs.end(), [](AvailableAttr *AV) {
return AV->IsSPI;
})) {
diagnose(D->getLoc(), diag::spi_preferred_over_spi_available);
}
}
}

void AttributeChecker::checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs) {
Expand Down
5 changes: 5 additions & 0 deletions test/attr/spi_available.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ public class SPIClass5 {}

@_spi_available(mscos 10.15, *) // expected-warning {{unrecognized platform name 'mscos'; did you mean 'macOS'?}} {{17-22=macOS}}
public class SPIClass6 {}

public class ClassWithMembers {
@_spi_available(macOS 10.15, *)
public func spiFunc() {} // Ok, this declaration is not top level
}