Skip to content

Commit 67c277d

Browse files
authored
Merge pull request #18133 from gregomni/8324
2 parents 4694310 + 8cd1a74 commit 67c277d

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,11 +1002,14 @@ static void sanitizeProtocolRequirements(
10021002
if (auto depMemTy = dyn_cast<DependentMemberType>(type)) {
10031003
if (!depMemTy->getAssocType() ||
10041004
depMemTy->getAssocType()->getProtocol() != proto) {
1005+
10051006
for (auto member : proto->lookupDirect(depMemTy->getName())) {
10061007
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
1007-
return Type(DependentMemberType::get(
1008-
sanitizeType(depMemTy->getBase()),
1009-
assocType));
1008+
Type sanitizedBase = sanitizeType(depMemTy->getBase());
1009+
if (!sanitizedBase)
1010+
return Type();
1011+
return Type(DependentMemberType::get(sanitizedBase,
1012+
assocType));
10101013
}
10111014
}
10121015

test/Generics/conditional_conformances.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,20 @@ extension SR6990: Sequence where T == Int {
396396
public typealias Iterator = IndexingIterator<[Float]>
397397
public func makeIterator() -> Iterator { fatalError() }
398398
}
399+
400+
// SR-8324
401+
protocol ElementProtocol {
402+
associatedtype BaseElement: BaseElementProtocol = Self
403+
}
404+
protocol BaseElementProtocol: ElementProtocol where BaseElement == Self {}
405+
protocol ArrayProtocol {
406+
associatedtype Element: ElementProtocol
407+
}
408+
protocol NestedArrayProtocol: ArrayProtocol where Element: ArrayProtocol, Element.Element.BaseElement == Element.BaseElement {
409+
associatedtype BaseElement = Element.BaseElement
410+
}
411+
extension Array: ArrayProtocol where Element: ElementProtocol {}
412+
extension Array: NestedArrayProtocol where Element: ElementProtocol, Element: ArrayProtocol, Element.Element.BaseElement == Element.BaseElement {
413+
// with the typealias uncommented you do not get a crash.
414+
// typealias BaseElement = Element.BaseElement
415+
}

0 commit comments

Comments
 (0)