Skip to content

Commit d70b0c9

Browse files
committed
[Sema] SPI requirements in SPI protocols don't need a default implementation
The check for SPI protocol requirements needing a default implementation should ignore requirements in a protocol that is SPI too. The protocol can’t be conformed to without knowing of the requirement. rdar://65286171
1 parent ba2455a commit d70b0c9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5758,8 +5758,9 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
57585758
ResolveWitnessResult result = checker.resolveWitnessViaLookup(valueDecl);
57595759

57605760
if (result == ResolveWitnessResult::Missing &&
5761-
requirement->isSPI()) {
5762-
// SPI requirements need a default value.
5761+
requirement->isSPI() &&
5762+
!proto->isSPI()) {
5763+
// SPI requirements need a default value, unless the protocol is SPI too.
57635764
valueDecl->diagnose(diag::spi_attribute_on_protocol_requirement,
57645765
valueDecl->getName());
57655766
}

test/SPI/protocol_requirement.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,24 @@ extension PublicProto {
7575
@_spi(Private)
7676
public init() { }
7777
}
78+
79+
@_spi(Private)
80+
public protocol SPIProtocol {
81+
@_spi(Private)
82+
func reqWithoutDefault()
83+
84+
@_spi(Private)
85+
var property: Int { get set }
86+
87+
@_spi(Private)
88+
var propertyWithoutSetter: Int { get set }
89+
90+
@_spi(Private)
91+
subscript(index: Int) -> Int { get set }
92+
93+
@_spi(Private)
94+
init()
95+
96+
@_spi(Private)
97+
static var staticProperty: Int { get }
98+
}

0 commit comments

Comments
 (0)