Skip to content

Commit c285bab

Browse files
authored
Merge pull request #63197 from tshortli/avoid-spi-available-diagnostic-on-nested-decls
2 parents 6dcce6e + a81c057 commit c285bab

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,12 +4509,16 @@ void AttributeChecker::checkOriginalDefinedInAttrs(
45094509
void AttributeChecker::checkAvailableAttrs(ArrayRef<AvailableAttr *> Attrs) {
45104510
if (Attrs.empty())
45114511
return;
4512-
// If all available are spi available, we should use @_spi instead.
4513-
if (std::all_of(Attrs.begin(), Attrs.end(), [](AvailableAttr *AV) {
4514-
return AV->IsSPI;
4515-
})) {
4516-
diagnose(D->getLoc(), diag::spi_preferred_over_spi_available);
4517-
};
4512+
4513+
// Only diagnose top level decls since nested ones may have inherited availability.
4514+
if (!D->getDeclContext()->getInnermostDeclarationDeclContext()) {
4515+
// If all available are spi available, we should use @_spi instead.
4516+
if (std::all_of(Attrs.begin(), Attrs.end(), [](AvailableAttr *AV) {
4517+
return AV->IsSPI;
4518+
})) {
4519+
diagnose(D->getLoc(), diag::spi_preferred_over_spi_available);
4520+
}
4521+
}
45184522
}
45194523

45204524
void AttributeChecker::checkBackDeployAttrs(ArrayRef<BackDeployAttr *> Attrs) {

test/attr/spi_available.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ public class SPIClass5 {}
1717

1818
@_spi_available(mscos 10.15, *) // expected-warning {{unrecognized platform name 'mscos'; did you mean 'macOS'?}} {{17-22=macOS}}
1919
public class SPIClass6 {}
20+
21+
public class ClassWithMembers {
22+
@_spi_available(macOS 10.15, *)
23+
public func spiFunc() {} // Ok, this declaration is not top level
24+
}

0 commit comments

Comments
 (0)