Skip to content

Commit 2038b1a

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 ff5a55c commit 2038b1a

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
@@ -5767,8 +5767,9 @@ void TypeChecker::inferDefaultWitnesses(ProtocolDecl *proto) {
57675767
ResolveWitnessResult result = checker.resolveWitnessViaLookup(valueDecl);
57685768

57695769
if (result == ResolveWitnessResult::Missing &&
5770-
requirement->isSPI()) {
5771-
// SPI requirements need a default value.
5770+
requirement->isSPI() &&
5771+
!proto->isSPI()) {
5772+
// SPI requirements need a default value, unless the protocol is SPI too.
57725773
valueDecl->diagnose(diag::spi_attribute_on_protocol_requirement,
57735774
valueDecl->getName());
57745775
}

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)