Skip to content

Commit

Permalink
Merge pull request #18133 from gregomni/8324
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-ci committed Jul 22, 2018
2 parents 4694310 + 8cd1a74 commit 67c277d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Sema/TypeCheckProtocolInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,11 +1002,14 @@ static void sanitizeProtocolRequirements(
if (auto depMemTy = dyn_cast<DependentMemberType>(type)) {
if (!depMemTy->getAssocType() ||
depMemTy->getAssocType()->getProtocol() != proto) {

for (auto member : proto->lookupDirect(depMemTy->getName())) {
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
return Type(DependentMemberType::get(
sanitizeType(depMemTy->getBase()),
assocType));
Type sanitizedBase = sanitizeType(depMemTy->getBase());
if (!sanitizedBase)
return Type();
return Type(DependentMemberType::get(sanitizedBase,
assocType));
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/Generics/conditional_conformances.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,3 +396,20 @@ extension SR6990: Sequence where T == Int {
public typealias Iterator = IndexingIterator<[Float]>
public func makeIterator() -> Iterator { fatalError() }
}

// SR-8324
protocol ElementProtocol {
associatedtype BaseElement: BaseElementProtocol = Self
}
protocol BaseElementProtocol: ElementProtocol where BaseElement == Self {}
protocol ArrayProtocol {
associatedtype Element: ElementProtocol
}
protocol NestedArrayProtocol: ArrayProtocol where Element: ArrayProtocol, Element.Element.BaseElement == Element.BaseElement {
associatedtype BaseElement = Element.BaseElement
}
extension Array: ArrayProtocol where Element: ElementProtocol {}
extension Array: NestedArrayProtocol where Element: ElementProtocol, Element: ArrayProtocol, Element.Element.BaseElement == Element.BaseElement {
// with the typealias uncommented you do not get a crash.
// typealias BaseElement = Element.BaseElement
}

0 comments on commit 67c277d

Please sign in to comment.