File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -1339,6 +1339,7 @@ class DeclAndTypePrinter::Implementation
1339
1339
return true ;
1340
1340
}
1341
1341
1342
+ public:
1342
1343
// / If \p nominal is bridged to an Objective-C class (via a conformance to
1343
1344
// / _ObjectiveCBridgeable), return that class.
1344
1345
// /
@@ -1369,6 +1370,7 @@ class DeclAndTypePrinter::Implementation
1369
1370
return objcType->getClassOrBoundGenericClass ();
1370
1371
}
1371
1372
1373
+ private:
1372
1374
// / If the nominal type is bridged to Objective-C (via a conformance
1373
1375
// / to _ObjectiveCBridgeable), print the bridged type.
1374
1376
void printObjCBridgeableType (const NominalTypeDecl *swiftNominal,
@@ -2067,6 +2069,14 @@ bool DeclAndTypePrinter::isEmptyExtensionDecl(const ExtensionDecl *ED) {
2067
2069
return getImpl ().isEmptyExtensionDecl (ED);
2068
2070
}
2069
2071
2072
+ const TypeDecl *DeclAndTypePrinter::getObjCTypeDecl (const TypeDecl* TD) {
2073
+ if (auto *nominal = dyn_cast<NominalTypeDecl>(TD))
2074
+ if (auto *bridged = getImpl ().getObjCBridgedClass (nominal))
2075
+ return bridged;
2076
+
2077
+ return TD;
2078
+ }
2079
+
2070
2080
StringRef
2071
2081
DeclAndTypePrinter::maybeGetOSObjectBaseName (const clang::NamedDecl *decl) {
2072
2082
StringRef name = decl->getName ();
Original file line number Diff line number Diff line change @@ -73,6 +73,14 @@ class DeclAndTypePrinter {
73
73
// / Is \p ED empty of members and protocol conformances to include?
74
74
bool isEmptyExtensionDecl (const ExtensionDecl *ED);
75
75
76
+ // / Returns the type that will be printed by PrintAsObjC for a parameter or
77
+ // / result type resolved to this declaration.
78
+ // /
79
+ // / \warning This handles \c _ObjectiveCBridgeable types, but it doesn't
80
+ // / currently know about other aspects of PrintAsObjC behavior, like known
81
+ // / types.
82
+ const TypeDecl *getObjCTypeDecl (const TypeDecl* TD);
83
+
76
84
// / Prints a category declaring the given members.
77
85
// /
78
86
// / All members must have the same parent type. The list must not be empty.
Original file line number Diff line number Diff line change @@ -278,6 +278,9 @@ class ModuleWriter {
278
278
if (TD == container)
279
279
return ;
280
280
281
+ // Bridge, if necessary.
282
+ TD = printer.getObjCTypeDecl (TD);
283
+
281
284
if (finder.needsDefinition () && isa<NominalTypeDecl>(TD)) {
282
285
// We can delay individual members of classes; do so if necessary.
283
286
if (isa<ClassDecl>(container)) {
Original file line number Diff line number Diff line change @@ -49,8 +49,26 @@ import SingleGenericClass
49
49
// CHECK-NEXT: @end
50
50
@objc class B1 : A1 { }
51
51
52
+ // Used in BridgedTypes test case
53
+ struct Notification : _ObjectiveCBridgeable {
54
+ func _bridgeToObjectiveC( ) -> NSNotification { fatalError ( ) }
55
+ static func _forceBridgeFromObjectiveC(
56
+ _ source: NSNotification ,
57
+ result: inout Self ?
58
+ ) { fatalError ( ) }
59
+ @discardableResult
60
+ static func _conditionallyBridgeFromObjectiveC(
61
+ _ source: NSNotification ,
62
+ result: inout Self ?
63
+ ) -> Bool { fatalError ( ) }
64
+ @_effects ( readonly)
65
+ static func _unconditionallyBridgeFromObjectiveC( _ source: _ObjectiveCType ? )
66
+ -> Self { fatalError ( ) }
67
+ }
68
+
52
69
// CHECK-LABEL: @interface BridgedTypes
53
70
// CHECK-NEXT: - (NSDictionary * _Nonnull)dictBridge:(NSDictionary * _Nonnull)x SWIFT_WARN_UNUSED_RESULT;
71
+ // CHECK-NEXT: - (NSNotification * _Nonnull)noteBridge:(NSNotification * _Nonnull)x SWIFT_WARN_UNUSED_RESULT;
54
72
// CHECK-NEXT: - (NSSet * _Nonnull)setBridge:(NSSet * _Nonnull)x SWIFT_WARN_UNUSED_RESULT;
55
73
// CHECK-NEXT: init
56
74
// CHECK-NEXT: @end
@@ -59,6 +77,10 @@ import SingleGenericClass
59
77
return x
60
78
}
61
79
80
+ @objc func noteBridge( _ x: Notification ) -> Notification {
81
+ return x
82
+ }
83
+
62
84
@objc func setBridge( _ x: Set < NSObject > ) -> Set < NSObject > {
63
85
return x
64
86
}
You can’t perform that action at this time.
0 commit comments