Skip to content

Commit 7141fa7

Browse files
Merge pull request #32759 from nate-chandler/rdar64672291
[5.3] [Runtime] Let existential types satisfy superclass requirements.
2 parents 7866f31 + ca525fc commit 7141fa7

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,15 @@ bool swift::_checkGenericRequirements(
869869
substGenericParam, substWitnessTable).getMetadata();
870870
if (!baseType) return true;
871871

872+
// If the type which is constrained to a base class is an existential
873+
// type, and if that existential type includes a superclass constraint,
874+
// just require that the superclass by which the existential is
875+
// constrained is a subclass of the base class.
876+
if (auto *existential = dyn_cast<ExistentialTypeMetadata>(subjectType)) {
877+
if (auto *superclassConstraint = existential->getSuperclassConstraint())
878+
subjectType = superclassConstraint;
879+
}
880+
872881
if (!isSubclass(subjectType, baseType))
873882
return true;
874883

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-run-simple-swift
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
final class Storage<T: NSObject> {
7+
weak var object: T?
8+
init(object: T) {
9+
self.object = object
10+
}
11+
}
12+
13+
14+
@objc protocol MyProtocol {}
15+
typealias MyStorage = Storage<NSObject & MyProtocol>
16+
17+
class Gadget: NSObject, MyProtocol {
18+
func testit() {
19+
_ = MyStorage(object: self)
20+
}
21+
}
22+
23+
let gadget = Gadget()
24+
gadget.testit()

0 commit comments

Comments
 (0)