Skip to content

[5.7][AST] Teach computeNominalType about nested ObjC protocols #59783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4249,7 +4249,11 @@ static Type computeNominalType(NominalTypeDecl *decl, DeclTypeKind kind) {
// If `decl` is a nested type, find the parent type.
Type ParentTy;
DeclContext *dc = decl->getDeclContext();
if (!isa<ProtocolDecl>(decl) && dc->isTypeContext()) {
bool isObjCProtocol = isa<ProtocolDecl>(decl) && decl->hasClangNode();

// Objective-C protocols, unlike Swift protocols, could be nested
// in other types.
if ((isObjCProtocol || !isa<ProtocolDecl>(decl)) && dc->isTypeContext()) {
switch (kind) {
case DeclTypeKind::DeclaredType: {
if (auto *nominal = dc->getSelfNominalTypeDecl())
Expand Down
3 changes: 3 additions & 0 deletions test/ClangImporter/Inputs/nested_protocol_name.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@import Foundation;

@protocol TrunkBranchProtocol;

__attribute__((objc_root_class))
@interface Trunk
- (instancetype)init;
- (void)addLimb:(id<TrunkBranchProtocol>)limb;
- (void)addLimbs:(NSArray<id<TrunkBranchProtocol>> *)limbs;
@end

// NS_SWIFT_NAME(Trunk.Branch)
Expand Down
10 changes: 8 additions & 2 deletions test/ClangImporter/nested_protocol_name.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

// HEADER: class Trunk {
// HEADER: init!()
// HEADER: class func addLimb(_ limb: Branch!)
// HEADER: func addLimb(_ limb: Branch!)
// HEADER: class func addLimb(_ limb: Trunk.Branch!)
// HEADER: func addLimb(_ limb: Trunk.Branch!)
// HEADER: func addLimbs(_ limbs: [Trunk.Branch]!)
// HEADER: }
// HEADER: // NS_SWIFT_NAME(Trunk.Branch)
// HEADER: protocol Branch {
Expand All @@ -24,6 +25,11 @@ func grow(_ branch: Trunk.Branch, from trunk: Trunk) {
trunk.addLimb(branch)
}

// rdar://95084142 - crash while matching existential types
func grow_multiple(_ branches: [Trunk.Branch], from trunk: Trunk) {
trunk.addLimbs(branches) // ok
}

class SturdyBranch: Trunk.Branch {
func flower() {}
}
Expand Down