Skip to content

Commit 9e496d3

Browse files
committed
Add a Null Check for Missing Generic Signatures
When an extension is nested inside of an invalid decl context, it is going to pull the signature of its nearest enclosing context instead of its extended type. This leads to a null signature since the nearest enclosing context for an extension should always be its parent source file. rdar://76049852
1 parent 876a0ee commit 9e496d3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/AST/DeclContext.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,9 @@ bool DeclContext::hasValueSemantics() const {
11881188
bool DeclContext::isClassConstrainedProtocolExtension() const {
11891189
if (getExtendedProtocolDecl()) {
11901190
auto ED = cast<ExtensionDecl>(this);
1191-
return ED->getGenericSignature()->requiresClass(ED->getSelfInterfaceType());
1191+
if (auto sig = ED->getGenericSignature()) {
1192+
return sig->requiresClass(ED->getSelfInterfaceType());
1193+
}
11921194
}
11931195
return false;
11941196
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: not %target-swift-frontend -typecheck %s
2+
3+
struct MyStruct {}
4+
protocol MyProtocol {}
5+
6+
func foo(bytes: [MyStruct]) {
7+
bytes.withUnsafeBufferPointer { a in
8+
extension MyProtocol {
9+
  var bytes: MyStruct {
10+
    fatalError()
11+
  }
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)