Skip to content

Commit 63a5f44

Browse files
committed
AST: Tweak a concrete-nested-type-of-archetype hack slightly
When an archetype conforms to a protocol abstractly (ie, it is not class-constrained and we don't have any further information other than that it conforms), we can recover nested types, but we cannot recover the conformance of those nested types to protocols if those conformances are concrete (the nested type might be concrete, or it might be a class-constrained archetype). To work around this, we added a hack where if the conformance lookup in the SubstitutionMap fails, we fall back to the module. This is horrible and unprincipled, but has to remain in place until more infrastructure is plumbed through. Commit 620db5f made this workaround apply in fewer cases, so that we could still catch cases where the SubstitutionMap was constructed with missing conformances. Unfortunately this workaround didn't handle the case where the nested type was an archetype with a superclass constraint. This will all go away soon, but for now tweak the logic a bit, since I really want to keep the "narrow" workaround in place and not the general fallback, otherwise we run the risk of SubstitutionMap conformance lookup bitrotting completely. Fixes <https://bugs.swift.org/browse/SR-4088> and <rdar://problem/32773028>.
1 parent 37d20f7 commit 63a5f44

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
223223
auto *M = proto->getParentModule();
224224
auto substType = type.subst(*this);
225225
if (substType &&
226-
!substType->is<ArchetypeType>() &&
226+
(!substType->is<ArchetypeType>() ||
227+
substType->castTo<ArchetypeType>()->getSuperclass()) &&
227228
!substType->isTypeParameter() &&
228229
!substType->isExistentialType()) {
229230
auto lazyResolver = M->getASTContext().getLazyResolver();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend -emit-ir -primary-file %s
2+
3+
class UITableViewCell {}
4+
class UITableView {}
5+
6+
extension UITableViewCell: ReusableViewProtocol {
7+
public typealias ParentView = UITableView
8+
}
9+
10+
protocol ReusableViewProtocol {
11+
associatedtype ParentView
12+
}
13+
14+
protocol ReusableViewFactoryProtocol {
15+
associatedtype View: ReusableViewProtocol
16+
func configure(parentView: View.ParentView)
17+
}
18+
19+
extension ReusableViewFactoryProtocol where View: UITableViewCell {
20+
func tableCellFor(tableView: UITableView) {
21+
configure(parentView: tableView)
22+
}
23+
}

0 commit comments

Comments
 (0)