Skip to content

Commit a49548c

Browse files
authored
Merge pull request #42080 from nkcsgexi/90938725
sema: allow unavailable context to refer SPI-available decls
2 parents 225a5ef + e0d7a3e commit a49548c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,14 @@ swift::getDisallowedOriginKind(const Decl *decl,
15461546
// Implementation-only imported, cannot be reexported.
15471547
return DisallowedOriginKind::ImplementationOnly;
15481548
} else if ((decl->isSPI() || decl->isAvailableAsSPI()) && !where.isSPI()) {
1549+
// Allowing unavailable context to use @_spi_available decls.
1550+
// Decls with @_spi_available aren't hidden entirely from public interfaces,
1551+
// thus public interfaces may still refer them. Be forgiving here so public
1552+
// interfaces can compile.
1553+
if (where.getUnavailablePlatformKind().hasValue() &&
1554+
decl->isAvailableAsSPI() && !decl->isSPI()) {
1555+
return DisallowedOriginKind::None;
1556+
}
15491557
// SPI can only be exported in SPI.
15501558
return where.getDeclContext()->getParentModule() == M ?
15511559
DisallowedOriginKind::SPILocal :

test/ClangImporter/availability_spi_as_unavailable.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ public let d: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2'
1616
public func inlinableUsingSPI() {
1717
SharedInterface.foo() // expected-error{{class method 'foo()' cannot be used in an '@inlinable' function because it is an SPI imported from 'SPIContainer'}}
1818
}
19+
20+
@available(macOS, unavailable)
21+
public let e: SPIInterface2
22+
23+
@available(iOS, unavailable)
24+
public let f: SPIInterface2 // expected-error{{cannot use class 'SPIInterface2' here; it is an SPI imported from 'SPIContainer'}}
25+
26+
@inlinable
27+
@available(macOS, unavailable)
28+
public func inlinableUnavailableUsingSPI() {
29+
SharedInterface.foo()
30+
}

0 commit comments

Comments
 (0)