Skip to content

Commit ec48de5

Browse files
authored
Merge pull request swiftlang#32796 from xymus/fix-invalid-spi-attr-5.3
[5.3][ModuleInterface] Don't print SPI attributes on unsupported decls
2 parents e4664ef + 665b3aa commit ec48de5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/AST/ASTPrinter.cpp

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

993993
// SPI groups
994-
if (Options.PrintSPIs) {
994+
if (Options.PrintSPIs &&
995+
DeclAttribute::canAttributeAppearOnDeclKind(
996+
DAK_SPIAccessControl, D->getKind())) {
995997
interleave(D->getSPIGroups(),
996998
[&](Identifier spiName) {
997999
Printer.printAttrName("_spi", true);

test/SPI/private_swiftinterface.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ 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-PUBLIC-NOT: AssociatedType
98+
99+
func implicitSPIMethod()
100+
// CHECK-PRIVATE: @_spi(LocalSPI) func implicitSPIMethod()
101+
// CHECK-PUBLIC-NOT: implicitSPIMethod
102+
}
103+
91104
// Test the dummy conformance printed to replace private types used in
92105
// conditional conformances. rdar://problem/63352700
93106

0 commit comments

Comments
 (0)