Skip to content

Commit 2add29c

Browse files
Merge pull request #3694 from aschwaighofer/sr1951_objc_generics
Sema: ObjC type parameters can capture generic types
2 parents c063aa7 + 1ee52e2 commit 2add29c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,6 @@ class FindCapturedVars : public ASTWalker {
125125
return Action::Continue;
126126
}
127127

128-
// ObjC generic type parameters don't have a runtime representation,
129-
// so they don't count as captures.
130-
if (auto bgt = t->getAs<BoundGenericClassType>()) {
131-
if (bgt->getDecl()->hasClangNode()) {
132-
return Action::SkipChildren;
133-
}
134-
}
135-
136128
return Action::Continue;
137129
}
138130
};

test/SILGen/objc_imported_generic.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,16 @@ public func arraysOfGenericParam<T: AnyObject>(y: Array<T>) {
9292
x.propertyArrayOfThings = y
9393
}
9494

95+
// CHECK-LABEL: sil shared @_TFF21objc_imported_generic11genericFuncuRxs9AnyObjectrFMxT_U_FT_T_ : $@convention(thin) <V where V : AnyObject> () -> () {
96+
// CHECK: [[INIT:%.*]] = function_ref @_TFCSo12GenericClassCfT_GS_x_ : $@convention(method) <τ_0_0 where τ_0_0 : AnyObject> (@thick GenericClass<τ_0_0>.Type) -> @owned GenericClass<τ_0_0>
97+
// CHECK: [[META:%.*]] = metatype $@thick GenericClass<V>.Type
98+
// CHECK: apply [[INIT]]<V>([[META]])
99+
// CHECK: return
100+
func genericFunc<V: AnyObject>(_ v: V.Type) {
101+
let _ = {
102+
var _ = GenericClass<V>()
103+
}
104+
}
105+
95106
// CHECK-LABEL: sil shared [thunk] @_TTOFCSo12GenericClasscfT13arrayOfThings
96107
// CHECK: class_method [volatile] {{%.*}} : $GenericClass<T>, #GenericClass.init!initializer.1.foreign {{.*}}, $@convention(objc_method) @pseudogeneric <τ_0_0 where τ_0_0 : AnyObject> (NSArray, @owned GenericClass<τ_0_0>) -> @owned ImplicitlyUnwrappedOptional<GenericClass<τ_0_0>>

0 commit comments

Comments
 (0)