Skip to content

Commit 78db42e

Browse files
committed
When obtaining the decl context for an inherited protocol conformance,
use the inherited conformance's decl context if the conformance type does not yet have a registered class decl. (Addresses SR-1267 and SR-1270)
1 parent f6835ec commit 78db42e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

include/swift/AST/ProtocolConformance.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,11 @@ class InheritedProtocolConformance : public ProtocolConformance,
662662
/// Get the declaration context that contains the conforming extension or
663663
/// nominal type declaration.
664664
DeclContext *getDeclContext() const {
665-
return getType()->getClassOrBoundGenericClass();
665+
auto bgc = getType()->getClassOrBoundGenericClass();
666+
667+
// In some cases, we may not have a BGC handy, in which case we should
668+
// delegate to the inherited conformance for the decl context.
669+
return bgc ? bgc : InheritedConformance->getDeclContext();
666670
}
667671

668672
/// Retrieve the state of this conformance.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: rm -rf %t && mkdir %t
2+
// RUN: cp %s %t/main.swift
3+
// RUN: %target-swift-frontend -parse -primary-file %t/main.swift -emit-reference-dependencies-path - > %t.swiftdeps
4+
5+
// SR-1267, SR-1270
6+
import Foundation
7+
8+
class TypeType<T where T: NSString> {
9+
func call(notification: NSNotification?) {
10+
let set = NSOrderedSet()
11+
if let objects = set.array as? [T] {
12+
let _ = (notification?.userInfo?["great_key"] as? NSSet).flatMap { updatedObjects in
13+
return updatedObjects.filter({ element in
14+
guard let element = element as? T
15+
where objects.index(of: element) != nil
16+
else {
17+
return false
18+
}
19+
return true
20+
})
21+
} ?? []
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)