Skip to content

Commit b8aef24

Browse files
committed
Sema: Fix @marker attribute checking
1 parent b5b1570 commit b8aef24

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7042,20 +7042,25 @@ void AttributeChecker::visitMarkerAttr(MarkerAttr *attr) {
70427042
if (!proto)
70437043
return;
70447044

7045-
// A marker protocol cannot inherit a non-marker protocol.
7046-
for (auto inheritedProto : proto->getInheritedProtocols()) {
7047-
if (!inheritedProto->isMarkerProtocol()) {
7048-
proto->diagnose(
7049-
diag::marker_protocol_inherit_nonmarker,
7050-
proto->getName(), inheritedProto->getName());
7051-
inheritedProto->diagnose( diag::decl_declared_here, inheritedProto);
7052-
}
7053-
}
7045+
for (auto req : proto->getRequirementSignature().getRequirements()) {
7046+
if (!req.getFirstType()->isEqual(proto->getSelfInterfaceType()))
7047+
continue;
70547048

7055-
if (Type superclass = proto->getSuperclass()) {
7056-
proto->diagnose(
7049+
if (req.getKind() == RequirementKind::Superclass) {
7050+
// A marker protocol cannot have a superclass requirement.
7051+
proto->diagnose(
70577052
diag::marker_protocol_inherit_class,
7058-
proto->getName(), superclass);
7053+
proto->getName(), req.getSecondType());
7054+
} else if (req.getKind() == RequirementKind::Conformance) {
7055+
// A marker protocol cannot inherit a non-marker protocol.
7056+
auto inheritedProto = req.getProtocolDecl();
7057+
if (!inheritedProto->isMarkerProtocol()) {
7058+
proto->diagnose(
7059+
diag::marker_protocol_inherit_nonmarker,
7060+
proto->getName(), inheritedProto->getName());
7061+
inheritedProto->diagnose( diag::decl_declared_here, inheritedProto);
7062+
}
7063+
}
70597064
}
70607065

70617066
// A marker protocol cannot have any requirements.

test/attr/attr_marker_protocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protocol P4 { } // expected-note{{'P4' declared here}}
2020
class C { }
2121
@_marker protocol P5a: AnyObject { } // okay
2222
@_marker protocol P5b: C { } // expected-error{{marker protocol 'P5b' cannot inherit class 'C'}}
23+
@_marker protocol P5c where Self: C { } // expected-error{{marker protocol 'P5c' cannot inherit class 'C'}}
2324

2425
// Legitimate uses of marker protocols.
2526
extension P3 {

0 commit comments

Comments
 (0)