Skip to content

Commit 634eb63

Browse files
jckartertkremenek
authored andcommitted
Clang importer: Fix the 'self' type of imported ObjC generic members. (#2732)
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 3f36309 commit 634eb63

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
@@ -3630,16 +3630,16 @@ namespace {
36303630
// Add the implicit 'self' parameter patterns.
36313631
SmallVector<ParameterList *, 4> bodyParams;
36323632
auto selfVar =
3633-
ParamDecl::createUnboundSelf(SourceLoc(), dc, /*isStatic*/!isInstance);
3633+
ParamDecl::createSelf(SourceLoc(), dc, /*isStatic*/!isInstance);
36343634
bodyParams.push_back(ParameterList::createWithoutLoc(selfVar));
3635-
Type selfInterfaceType;
3635+
Type selfContextType;
36363636
if (dc->getAsProtocolOrProtocolExtensionContext()) {
3637-
selfInterfaceType = dc->getProtocolSelf()->getArchetype();
3637+
selfContextType = dc->getProtocolSelf()->getArchetype();
36383638
} else {
3639-
selfInterfaceType = dc->getDeclaredInterfaceType();
3639+
selfContextType = dc->getDeclaredTypeInContext();
36403640
}
36413641
if (!isInstance) {
3642-
selfInterfaceType = MetatypeType::get(selfInterfaceType);
3642+
selfContextType = MetatypeType::get(selfContextType);
36433643
}
36443644

36453645
SpecialMethodKind kind = SpecialMethodKind::Regular;
@@ -3722,7 +3722,7 @@ namespace {
37223722
}
37233723

37243724
// Add the 'self' parameter to the function type.
3725-
type = FunctionType::get(selfInterfaceType, type);
3725+
type = FunctionType::get(selfContextType, type);
37263726

37273727
if (auto proto = dyn_cast<ProtocolDecl>(dc)) {
37283728
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)