Skip to content

Commit 7b8d635

Browse files
authored
Merge pull request #59756 from xedin/rdar-95084142
[AST] Teach `computeNominalType` about nested ObjC protocols
2 parents 036e168 + add41af commit 7b8d635

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4288,7 +4288,11 @@ static Type computeNominalType(NominalTypeDecl *decl, DeclTypeKind kind) {
42884288
// If `decl` is a nested type, find the parent type.
42894289
Type ParentTy;
42904290
DeclContext *dc = decl->getDeclContext();
4291-
if (!isa<ProtocolDecl>(decl) && dc->isTypeContext()) {
4291+
bool isObjCProtocol = isa<ProtocolDecl>(decl) && decl->hasClangNode();
4292+
4293+
// Objective-C protocols, unlike Swift protocols, could be nested
4294+
// in other types.
4295+
if ((isObjCProtocol || !isa<ProtocolDecl>(decl)) && dc->isTypeContext()) {
42924296
switch (kind) {
42934297
case DeclTypeKind::DeclaredType: {
42944298
if (auto *nominal = dc->getSelfNominalTypeDecl())

test/ClangImporter/Inputs/nested_protocol_name.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
@import Foundation;
2+
13
@protocol TrunkBranchProtocol;
24

35
__attribute__((objc_root_class))
46
@interface Trunk
57
- (instancetype)init;
68
- (void)addLimb:(id<TrunkBranchProtocol>)limb;
9+
- (void)addLimbs:(NSArray<id<TrunkBranchProtocol>> *)limbs;
710
@end
811

912
// NS_SWIFT_NAME(Trunk.Branch)

test/ClangImporter/nested_protocol_name.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
// HEADER: class Trunk {
1313
// HEADER: init!()
14-
// HEADER: class func addLimb(_ limb: Branch!)
15-
// HEADER: func addLimb(_ limb: Branch!)
14+
// HEADER: class func addLimb(_ limb: Trunk.Branch!)
15+
// HEADER: func addLimb(_ limb: Trunk.Branch!)
16+
// HEADER: func addLimbs(_ limbs: [Trunk.Branch]!)
1617
// HEADER: }
1718
// HEADER: // NS_SWIFT_NAME(Trunk.Branch)
1819
// HEADER: protocol Branch {
@@ -24,6 +25,11 @@ func grow(_ branch: Trunk.Branch, from trunk: Trunk) {
2425
trunk.addLimb(branch)
2526
}
2627

28+
// rdar://95084142 - crash while matching existential types
29+
func grow_multiple(_ branches: [Trunk.Branch], from trunk: Trunk) {
30+
trunk.addLimbs(branches) // ok
31+
}
32+
2733
class SturdyBranch: Trunk.Branch {
2834
func flower() {}
2935
}

0 commit comments

Comments
 (0)