File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -530,7 +530,9 @@ void SILGenFunction::emitClassConstructorAllocator(ConstructorDecl *ctor) {
530
530
// Allocate the 'self' value.
531
531
bool useObjCAllocation = usesObjCAllocator (selfClassDecl);
532
532
533
- if (ctor->hasClangNode () || ctor->isConvenienceInit ()) {
533
+ if (ctor->hasClangNode () ||
534
+ ctor->isObjCDynamic () ||
535
+ ctor->isConvenienceInit ()) {
534
536
assert (ctor->hasClangNode () || ctor->isObjC ());
535
537
// For an allocator thunk synthesized for an @objc convenience initializer
536
538
// or imported Objective-C init method, allocate using the metatype.
Original file line number Diff line number Diff line change
1
+ // RUN: %target-run-simple-swift
2
+ // REQUIRES: executable_test
3
+ // REQUIRES: objc_interop
4
+
5
+ import StdlibUnittest
6
+ import Foundation
7
+
8
+ protocol Horse {
9
+ init ( )
10
+ }
11
+
12
+ class Pony : NSObject , Horse {
13
+ override required init ( ) { }
14
+ }
15
+
16
+ class ChincoteaguePony : Pony { }
17
+
18
+ var ObjCMetatypesTest = TestSuite ( " ObjCMetatypes " )
19
+
20
+ ObjCMetatypesTest . test ( " ClassInit " ) {
21
+ let metatype : Pony . Type = ChincoteaguePony . self
22
+ let instance = metatype. init ( )
23
+ expectEqual ( type ( of: instance) , ChincoteaguePony . self)
24
+ }
25
+
26
+ ObjCMetatypesTest . test ( " ProtocolInit " ) {
27
+ let metatype : Horse . Type = ChincoteaguePony . self
28
+ let instance = metatype. init ( )
29
+ expectEqual ( type ( of: instance) , ChincoteaguePony . self)
30
+ }
31
+
32
+ runAllTests ( )
Original file line number Diff line number Diff line change @@ -17,6 +17,16 @@ class Gadget: NSObject, Hoozit {
17
17
}
18
18
}
19
19
20
+ // CHECK-LABEL: sil hidden [ossa] @$s17objc_dynamic_init6GadgetCACycfC : $@convention(method) (@thick Gadget.Type) -> @owned Gadget
21
+ // CHECK: [[OBJC_METATYPE:%.*]] = thick_to_objc_metatype %0 : $@thick Gadget.Type to $@objc_metatype Gadget.Type
22
+ // CHECK: [[SELF:%.*]] = alloc_ref_dynamic [objc] %1 : $@objc_metatype Gadget.Type, $Gadget
23
+ // CHECK: [[INIT:%.*]] = function_ref @$s17objc_dynamic_init6GadgetCACycfcTD : $@convention(method) (@owned Gadget) -> @owned Gadget
24
+ // CHECK: [[NEW_SELF:%.*]] = apply [[INIT]]([[SELF]]) : $@convention(method) (@owned Gadget) -> @owned Gadget
25
+ // CHECK: return [[NEW_SELF]]
26
+
27
+ // CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s17objc_dynamic_init6GadgetCAA6HoozitA2aDPxycfCTW : $@convention(witness_method: Hoozit) (@thick Gadget.Type) -> @out Gadget {
28
+ // CHECK: function_ref @$s17objc_dynamic_init6GadgetCACycfC
29
+
20
30
class Gizmo : Gadget , Wotsit {
21
31
required init ( ) {
22
32
super. init ( )
@@ -35,8 +45,7 @@ final class Bobamathing: Thingamabob {
35
45
}
36
46
}
37
47
38
- // CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s{{.*}}GadgetC{{.*}}CTW
39
- // CHECK: function_ref @{{.*}}Gadget{{.*}}fC :
48
+
40
49
41
50
// CHECK-LABEL: sil_vtable Gadget {
42
51
// CHECK-NOT: #Gadget.init!allocator.1
You can’t perform that action at this time.
0 commit comments