Skip to content

Commit b5f3b9f

Browse files
committed
GSB: Fix null pointer dereference in involvesNonSelfSubjectTypes()
If we have a RequirementSource here that's not rooted in a RequirementSignatureSelf, we would dereference a null pointer instead of ending the loop early. The only way such a RequirementSource can appear is from inferConditionalRequirements(). This crash does not occur on the main branch, because inferConditionalRequirements() is no longer performed inside protocols there because the RequirementMachine can't support it. A better fix would be to change inferConditionalRequirements() to build the proper RequirementSource in this case, but I'm going with a narrow fix since the GenericSignatureBuilder is going away on the main branch at some point. Fixes <rdar://problem/88474300> and <https://bugs.swift.org/browse/SR-15792>.
1 parent 06e7a5e commit b5f3b9f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5834,7 +5834,7 @@ void GenericSignatureBuilder::checkIfRequirementCanBeDerived(
58345834
}
58355835

58365836
static bool involvesNonSelfSubjectTypes(const RequirementSource *source) {
5837-
while (source->kind != RequirementSource::RequirementSignatureSelf) {
5837+
while (source && source->kind != RequirementSource::RequirementSignatureSelf) {
58385838
if (source->isProtocolRequirement() &&
58395839
!source->getStoredType()->is<GenericTypeParamType>())
58405840
return true;

test/Generics/sr15792.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-typecheck-verify-swift %s
2+
3+
protocol Collection {
4+
associatedtype SubSequence: Collection
5+
}
6+
7+
protocol BidirectionalCollection: Collection where SubSequence: BidirectionalCollection {}
8+
9+
struct Slice<Base : Collection> : Collection {
10+
typealias SubSequence = Slice<Base>
11+
}
12+
13+
extension Slice: BidirectionalCollection where Base : BidirectionalCollection {}
14+
15+
protocol SlicedCollection: BidirectionalCollection where SubSequence == Slice<Self> {}

0 commit comments

Comments
 (0)