Skip to content

Commit 615cfd4

Browse files
committed
Clang importer: Fix the 'self' type of imported ObjC generic members.
A variable was called `selfInterfaceType` even though it was inconsistently set to a contextual Self archetype for protocols, and an interface type for nominal types, and the one place we used the type expected to work with contextual types. Fixes rdar://problem/26396895.
1 parent ad6de9b commit 615cfd4

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,16 +3629,16 @@ namespace {
36293629
// Add the implicit 'self' parameter patterns.
36303630
SmallVector<ParameterList *, 4> bodyParams;
36313631
auto selfVar =
3632-
ParamDecl::createUnboundSelf(SourceLoc(), dc, /*isStatic*/!isInstance);
3632+
ParamDecl::createSelf(SourceLoc(), dc, /*isStatic*/!isInstance);
36333633
bodyParams.push_back(ParameterList::createWithoutLoc(selfVar));
3634-
Type selfInterfaceType;
3634+
Type selfContextType;
36353635
if (dc->getAsProtocolOrProtocolExtensionContext()) {
3636-
selfInterfaceType = dc->getProtocolSelf()->getArchetype();
3636+
selfContextType = dc->getProtocolSelf()->getArchetype();
36373637
} else {
3638-
selfInterfaceType = dc->getDeclaredInterfaceType();
3638+
selfContextType = dc->getDeclaredTypeInContext();
36393639
}
36403640
if (!isInstance) {
3641-
selfInterfaceType = MetatypeType::get(selfInterfaceType);
3641+
selfContextType = MetatypeType::get(selfContextType);
36423642
}
36433643

36443644
SpecialMethodKind kind = SpecialMethodKind::Regular;
@@ -3723,7 +3723,7 @@ namespace {
37233723
}
37243724

37253725
// Add the 'self' parameter to the function type.
3726-
type = FunctionType::get(selfInterfaceType, type);
3726+
type = FunctionType::get(selfContextType, type);
37273727

37283728
if (auto proto = dyn_cast<ProtocolDecl>(dc)) {
37293729
std::tie(type, interfaceType)

test/SILGen/objc_imported_generic.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ public func genericPropertyOnAnyObject(o: AnyObject, b: Bool) -> AnyObject?? {
3737
return o.propertyThing
3838
}
3939

40+
protocol ThingHolder {
41+
associatedtype Thing
42+
43+
init!(thing: Thing!)
44+
func thing() -> Thing?
45+
func arrayOfThings() -> [Thing]
46+
func setArrayOfThings(_: [Thing])
47+
static func classThing() -> Thing?
48+
49+
var propertyThing: Thing? { get set }
50+
var propertyArrayOfThings: [Thing]? { get set }
51+
}
52+
53+
extension GenericClass: ThingHolder {}
54+
4055
// CHECK-LABEL: sil @_TF21objc_imported_generic26genericPropertyOnAnyObject
4156
// CHECK: dynamic_method_br %4 : $@opened([[TAG:.*]]) AnyObject, #GenericClass.propertyThing!getter.1.foreign, bb1
4257
// CHECK: bb1({{%.*}} : $@convention(objc_method) (@opened([[TAG]]) AnyObject) -> @autoreleased Optional<AnyObject>):

0 commit comments

Comments
 (0)