Skip to content

Commit bf2a77e

Browse files
authored
Merge pull request #71865 from slavapestov/fix-rdar123543200
Sema: Fix checkTypeWitness() for Objective-C protocol compositions
2 parents ba5d473 + 2befb08 commit bf2a77e

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,19 @@ checkTypeWitness(Type type, AssociatedTypeDecl *assocType,
191191
assert(superclassDecl);
192192

193193
// Fish a class declaration out of the type witness.
194-
auto classDecl = type->getClassOrBoundGenericClass();
195-
if (!classDecl) {
196-
if (auto archetype = type->getAs<ArchetypeType>()) {
197-
if (auto superclassType = archetype->getSuperclass())
194+
ClassDecl *classDecl = nullptr;
195+
196+
if (auto archetype = type->getAs<ArchetypeType>()) {
197+
if (auto superclassType = archetype->getSuperclass())
198198
classDecl = superclassType->getClassOrBoundGenericClass();
199-
}
199+
} else if (type->isObjCExistentialType()) {
200+
// For self-conforming Objective-C existentials, the exact check is
201+
// implemented in TypeBase::isExactSuperclassOf(). Here, we just always
202+
// look through into a superclass of a composition.
203+
if (auto superclassType = type->getSuperclass())
204+
classDecl = superclassType->getClassOrBoundGenericClass();
205+
} else {
206+
classDecl = type->getClassOrBoundGenericClass();
200207
}
201208

202209
if (!classDecl || !superclassDecl->isSuperclassOf(classDecl))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
protocol P1 {
8+
associatedtype A: NSObject
9+
}
10+
11+
@objc protocol P2 {}
12+
13+
struct S: P1 {
14+
typealias A = NSObject & P2
15+
}
16+
17+
let x: (any NSObject & P2).Type = S.A.self

0 commit comments

Comments
 (0)