Skip to content

Commit 66cd7d8

Browse files
committed
Marker protocols are self-conforming.
1 parent 85611db commit 66cd7d8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lib/AST/Module.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,8 +918,8 @@ ModuleDecl::lookupExistentialConformance(Type type, ProtocolDecl *protocol) {
918918

919919
// Due to an IRGen limitation, witness tables cannot be passed from an
920920
// existential to an archetype parameter, so for now we restrict this to
921-
// @objc protocols.
922-
if (!layout.isObjC()) {
921+
// @objc protocols and marker protocols.
922+
if (!layout.isObjC() && !protocol->isMarkerProtocol()) {
923923
// There's a specific exception for protocols with self-conforming
924924
// witness tables, but the existential has to be *exactly* that type.
925925
// TODO: synthesize witness tables on-demand for protocol compositions

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,12 @@ ProtocolRequiresClassRequest::evaluate(Evaluator &evaluator,
643643
bool
644644
ExistentialConformsToSelfRequest::evaluate(Evaluator &evaluator,
645645
ProtocolDecl *decl) const {
646-
// If it's not @objc, it conforms to itself only if it has a self-conformance
647-
// witness table.
646+
// Marker protocols always self-conform.
647+
if (decl->isMarkerProtocol())
648+
return true;
649+
650+
// Otherwise, if it's not @objc, it conforms to itself only if it has a
651+
// self-conformance witness table.
648652
if (!decl->isObjC())
649653
return decl->requiresSelfConformanceWitnessTable();
650654

test/attr/attr_marker_protocol.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ protocol P6: P3 { } // okay
3030

3131
func genericOk<T: P3>(_: T) { }
3232

33-
func testGenericOk(i: Int, arr: [Int], nope: [Double]) {
33+
func testGenericOk(i: Int, arr: [Int], nope: [Double], p3: P3, p3array: [P3]) {
3434
genericOk(i)
3535
genericOk(arr)
3636
genericOk(nope) // expected-error{{global function 'genericOk' requires that 'Double' conform to 'P3'}}
37+
genericOk(p3)
38+
genericOk(p3array)
3739
}
3840

3941
// Incorrect uses of marker protocols in types.

0 commit comments

Comments
 (0)