Skip to content

Commit a31f8c8

Browse files
authored
Merge pull request swiftlang#21655 from DougGregor/implements-attr-crash-rdar46678653
2 parents f98d7bd + 8d5971e commit a31f8c8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,12 @@ witnessHasImplementsAttrForExactRequirement(ValueDecl *witness,
967967
assert(requirement->isProtocolRequirement());
968968
auto *PD = cast<ProtocolDecl>(requirement->getDeclContext());
969969
if (auto A = witness->getAttrs().getAttribute<ImplementsAttr>()) {
970-
Type T = A->getProtocolType().getType();
971-
if (T->castTo<ProtocolType>()->getDecl() == PD) {
972-
return A->getMemberName() == requirement->getFullName();
970+
if (Type T = A->getProtocolType().getType()) {
971+
if (auto ProtoTy = T->getAs<ProtocolType>()) {
972+
if (ProtoTy->getDecl() == PD) {
973+
return A->getMemberName() == requirement->getFullName();
974+
}
975+
}
973976
}
974977
}
975978
return false;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
protocol P: class { }
4+
5+
protocol Q {
6+
func g()
7+
}
8+
9+
protocol P { }
10+
11+
struct S : Q {
12+
@_implements(P, g())
13+
func h() {}
14+
}
15+

0 commit comments

Comments
 (0)