Skip to content

Commit b660dfe

Browse files
authored
Merge pull request swiftlang#40946 from slavapestov/forwarding-substitutions-with-concrete-conformance
AST: Handle concrete superclass conformance when forming forwarding substitutions
2 parents 0e37ada + 8f992f0 commit b660dfe

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/AST/Type.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,10 +3976,13 @@ operator()(CanType dependentType, Type conformingReplacementType,
39763976
|| conformingReplacementType->is<DependentMemberType>()
39773977
|| conformingReplacementType->is<TypeVariableType>())
39783978
&& "replacement requires looking up a concrete conformance");
3979-
// Lookup conformances for opened existential.
3980-
if (conformingReplacementType->isOpenedExistential()) {
3981-
return conformedProtocol->getModuleContext()->lookupConformance(
3982-
conformingReplacementType, conformedProtocol);
3979+
// A class-constrained archetype might conform to the protocol
3980+
// concretely.
3981+
if (auto *archetypeType = conformingReplacementType->getAs<ArchetypeType>()) {
3982+
if (auto superclassType = archetypeType->getSuperclass()) {
3983+
return conformedProtocol->getModuleContext()->lookupConformance(
3984+
archetypeType, conformedProtocol);
3985+
}
39833986
}
39843987
return ProtocolConformanceRef(conformedProtocol);
39853988
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-swift-frontend -emit-silgen %s
2+
3+
// When a protocol has a superclass requirement on 'Self' and the class
4+
// itself conforms concretely, the forwarding substitution map will have
5+
// a concrete conformance in it. Make sure this is handled correctly
6+
// without tripping the SIL verifier.
7+
8+
class C: P {}
9+
10+
protocol P: C {}
11+
12+
func f<T : P>(_ t: T) {
13+
// The weak reference causes us to form a SILBoxType, which is where
14+
// the problematic conformance popped up.
15+
_ = { [weak t] in _ = t }
16+
}

0 commit comments

Comments
 (0)