Skip to content

Commit f423301

Browse files
committed
Sema: Fix @marker attribute checking
1 parent bee9fee commit f423301

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
@@ -7076,20 +7076,25 @@ void AttributeChecker::visitMarkerAttr(MarkerAttr *attr) {
70767076
if (!proto)
70777077
return;
70787078

7079-
// A marker protocol cannot inherit a non-marker protocol.
7080-
for (auto inheritedProto : proto->getInheritedProtocols()) {
7081-
if (!inheritedProto->isMarkerProtocol()) {
7082-
proto->diagnose(
7083-
diag::marker_protocol_inherit_nonmarker,
7084-
proto->getName(), inheritedProto->getName());
7085-
inheritedProto->diagnose( diag::decl_declared_here, inheritedProto);
7086-
}
7087-
}
7079+
for (auto req : proto->getRequirementSignature().getRequirements()) {
7080+
if (!req.getFirstType()->isEqual(proto->getSelfInterfaceType()))
7081+
continue;
70887082

7089-
if (Type superclass = proto->getSuperclass()) {
7090-
proto->diagnose(
7083+
if (req.getKind() == RequirementKind::Superclass) {
7084+
// A marker protocol cannot have a superclass requirement.
7085+
proto->diagnose(
70917086
diag::marker_protocol_inherit_class,
7092-
proto->getName(), superclass);
7087+
proto->getName(), req.getSecondType());
7088+
} else if (req.getKind() == RequirementKind::Conformance) {
7089+
// A marker protocol cannot inherit a non-marker protocol.
7090+
auto inheritedProto = req.getProtocolDecl();
7091+
if (!inheritedProto->isMarkerProtocol()) {
7092+
proto->diagnose(
7093+
diag::marker_protocol_inherit_nonmarker,
7094+
proto->getName(), inheritedProto->getName());
7095+
inheritedProto->diagnose( diag::decl_declared_here, inheritedProto);
7096+
}
7097+
}
70937098
}
70947099

70957100
// 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)