Skip to content

Commit de27747

Browse files
authored
Merge pull request swiftlang#32211 from xymus/fix-invalid-spi-attr
[ModuleInterface] Don't print SPI attributes on unsupported decls
2 parents 0de3535 + ead9bc3 commit de27747

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,9 @@ void PrintAST::printAttributes(const Decl *D) {
997997
}
998998

999999
// SPI groups
1000-
if (Options.PrintSPIs) {
1000+
if (Options.PrintSPIs &&
1001+
DeclAttribute::canAttributeAppearOnDeclKind(
1002+
DAK_SPIAccessControl, D->getKind())) {
10011003
interleave(D->getSPIGroups(),
10021004
[&](Identifier spiName) {
10031005
Printer.printAttrName("_spi", true);

test/SPI/private_swiftinterface.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ private class PrivateClassLocal {}
8888
// CHECK-PUBLIC-NOT: extensionSPIMethod
8989
}
9090

91+
@_spi(LocalSPI) public protocol SPIProto3 {
92+
// CHECK-PRIVATE: @_spi(LocalSPI) public protocol SPIProto3
93+
// CHECK-PUBLIC-NOT: SPIProto3
94+
95+
associatedtype AssociatedType
96+
// CHECK-PRIVATE: associatedtype AssociatedType
97+
// CHECK-PRIVATE-NOT: @_spi(LocalSPI) associatedtype AssociatedType
98+
// CHECK-PUBLIC-NOT: AssociatedType
99+
100+
func implicitSPIMethod()
101+
// CHECK-PRIVATE: @_spi(LocalSPI) func implicitSPIMethod()
102+
// CHECK-PUBLIC-NOT: implicitSPIMethod
103+
}
104+
91105
// Test the dummy conformance printed to replace private types used in
92106
// conditional conformances. rdar://problem/63352700
93107

0 commit comments

Comments
 (0)