Skip to content

Commit b47b168

Browse files
committed
Merge pull request #2731 from jckarter/objc-generic-protocol-conformance
Clang importer: Fix the 'self' type of imported ObjC generic members.
2 parents 740ddd8 + 615cfd4 commit b47b168

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
@@ -3631,16 +3631,16 @@ namespace {
36313631
// Add the implicit 'self' parameter patterns.
36323632
SmallVector<ParameterList *, 4> bodyParams;
36333633
auto selfVar =
3634-
ParamDecl::createUnboundSelf(SourceLoc(), dc, /*isStatic*/!isInstance);
3634+
ParamDecl::createSelf(SourceLoc(), dc, /*isStatic*/!isInstance);
36353635
bodyParams.push_back(ParameterList::createWithoutLoc(selfVar));
3636-
Type selfInterfaceType;
3636+
Type selfContextType;
36373637
if (dc->getAsProtocolOrProtocolExtensionContext()) {
3638-
selfInterfaceType = dc->getProtocolSelf()->getArchetype();
3638+
selfContextType = dc->getProtocolSelf()->getArchetype();
36393639
} else {
3640-
selfInterfaceType = dc->getDeclaredInterfaceType();
3640+
selfContextType = dc->getDeclaredTypeInContext();
36413641
}
36423642
if (!isInstance) {
3643-
selfInterfaceType = MetatypeType::get(selfInterfaceType);
3643+
selfContextType = MetatypeType::get(selfContextType);
36443644
}
36453645

36463646
SpecialMethodKind kind = SpecialMethodKind::Regular;
@@ -3725,7 +3725,7 @@ namespace {
37253725
}
37263726

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

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