@@ -14,98 +14,136 @@ import ObjectiveC
1414typealias MyTuple = ( Int , AnyObject ? )
1515typealias MyNamedTuple = ( a: Int , b: AnyObject ? )
1616typealias MyInt = Int
17+ typealias MyBlockWithEscapingParam = ( @escaping ( ) -> ( ) ) -> Int
18+ typealias MyBlockWithNoescapeParam = ( ( ) -> ( ) ) -> Int
19+
20+ // Please see related tests in PrintAsObjC/imported-block-typedefs.swift.
1721
1822// CHECK-LABEL: @interface Callbacks
19- // CHECK-NEXT: - (void (^ _Nonnull)(void))voidBlocks:(void (^ _Nonnull)(void))input;
20- // CHECK-NEXT: - (void)manyArguments:(void (^ _Nonnull)(float, float, double, double))input;
21- // CHECK-NEXT: - (void)blockTakesBlock:(void (^ _Nonnull)(void (^ _Nonnull)(void)))input;
22- // CHECK-NEXT: - (void)blockReturnsBlock:(void (^ _Nonnull (^ _Nonnull)(void))(void))input;
23- // CHECK-NEXT: - (void)blockTakesAndReturnsBlock:(uint8_t (^ _Nonnull (^ _Nonnull)(uint16_t (^ _Nonnull)(int16_t)))(int8_t))input;
24- // CHECK-NEXT: - (void)blockTakesTwoBlocksAndReturnsBlock:(uint8_t (^ _Nonnull (^ _Nonnull)(uint16_t (^ _Nonnull)(int16_t), uint32_t (^ _Nonnull)(int32_t)))(int8_t))input;
25- // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithInput;
26- // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithParenthesizedInput;
27- // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull, NSObject * _Nonnull))returnsBlockWithTwoInputs;
28- // CHECK-NEXT: - (void)blockWithTypealias:(NSInteger (^ _Nonnull)(NSInteger, id _Nullable))input;
29- // CHECK-NEXT: - (void)blockWithSimpleTypealias:(NSInteger (^ _Nonnull)(NSInteger))input;
30- // CHECK-NEXT: - (void)namedArguments:(void (^ _Nonnull)(float, float, double, double))input;
31- // CHECK-NEXT: - (void)blockTakesNamedBlock:(void (^ _Nonnull)(void (^ _Nonnull)(void)))input;
32- // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithNamedInput;
33- // CHECK-NEXT: - (void)blockWithTypealiasWithNames:(NSInteger (^ _Nonnull)(NSInteger a, id _Nullable b))input;
34- // CHECK-NEXT: - (void)blockWithKeyword:(NSInteger (^ _Nonnull)(NSInteger))_Nullable_;
35- // CHECK-NEXT: - (NSInteger (* _Nonnull)(NSInteger))functionPointers:(NSInteger (* _Nonnull)(NSInteger))input;
36- // CHECK-NEXT: - (void)functionPointerTakesAndReturnsFunctionPointer:(NSInteger (* _Nonnull (^ _Nonnull (* _Nonnull)(NSInteger))(NSInteger))(NSInteger))input;
37- // CHECK-NEXT: - (NSInteger (* _Nonnull)(NSInteger))functionPointersWithName:(NSInteger (* _Nonnull)(NSInteger))input;
38- // CHECK-NEXT: @property (nonatomic, copy) NSInteger (^ _Nullable savedBlock)(NSInteger);
39- // CHECK-NEXT: @property (nonatomic, copy) NSInteger (^ _Nullable savedBlockWithName)(NSInteger);
40- // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nonnull savedFunctionPointer)(NSInteger);
41- // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nullable savedFunctionPointer2)(NSInteger);
42- // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nonnull savedFunctionPointerWithName)(NSInteger);
43- // CHECK-NEXT: @property (nonatomic, copy, getter=this, setter=setThis:) NSInteger (^ _Nonnull this_)(NSInteger);
44- // CHECK-NEXT: @property (nonatomic, getter=class, setter=setClass:) NSInteger (* _Nonnull class_)(NSInteger);
45- // CHECK-NEXT: init
46- // CHECK-NEXT: @end
4723@objc class Callbacks {
24+
25+ // CHECK-NEXT: - (void (^ _Nonnull)(void))voidBlocks:(void (^ _Nonnull)(void))input;
4826 func voidBlocks( _ input: @escaping ( ) -> ( ) ) -> ( ) -> ( ) {
4927 return input
5028 }
29+
30+ // CHECK-NEXT: - (void)manyArguments:(void (^ _Nonnull)(float, float, double, double))input;
5131 func manyArguments( _ input: @escaping ( Float , Float , Double , Double ) -> ( ) ) { }
5232
33+ // CHECK-NEXT: - (void)blockTakesBlock:(void (^ _Nonnull)(SWIFT_NOESCAPE void (^ _Nonnull)(void)))input;
5334 func blockTakesBlock( _ input: @escaping ( ( ) -> ( ) ) -> ( ) ) { }
35+
36+ // CHECK-NEXT: - (void)blockReturnsBlock:(void (^ _Nonnull (^ _Nonnull)(void))(void))input;
5437 func blockReturnsBlock( _ input: @escaping ( ) -> ( ) -> ( ) ) { }
38+
39+ // CHECK-NEXT: - (void)blockTakesAndReturnsBlock:(SWIFT_NOESCAPE uint8_t (^ _Nonnull (^ _Nonnull)(SWIFT_NOESCAPE uint16_t (^ _Nonnull)(int16_t)))(int8_t))input;
5540 func blockTakesAndReturnsBlock( _ input:
5641 ( ( Int16 ) -> ( UInt16 ) ) ->
5742 ( ( Int8 ) -> ( UInt8 ) ) ) { }
43+
44+ // CHECK-NEXT: - (void)blockTakesTwoBlocksAndReturnsBlock:(SWIFT_NOESCAPE uint8_t (^ _Nonnull (^ _Nonnull)(SWIFT_NOESCAPE uint16_t (^ _Nonnull)(int16_t), SWIFT_NOESCAPE uint32_t (^ _Nonnull)(int32_t)))(int8_t))input;
5845 func blockTakesTwoBlocksAndReturnsBlock( _ input:
5946 ( ( Int16 ) -> ( UInt16 ) ,
6047 ( Int32 ) -> ( UInt32 ) ) ->
6148 ( ( Int8 ) -> ( UInt8 ) ) ) { }
6249
50+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithInput;
6351 func returnsBlockWithInput( ) -> ( ( NSObject ) -> ( ) ) ? {
6452 return nil
6553 }
54+
55+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithParenthesizedInput;
6656 func returnsBlockWithParenthesizedInput( ) -> ( ( NSObject ) -> ( ) ) ? {
6757 return nil
6858 }
59+
60+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull, NSObject * _Nonnull))returnsBlockWithTwoInputs;
6961 func returnsBlockWithTwoInputs( ) -> ( ( NSObject , NSObject ) -> ( ) ) ? {
7062 return nil
7163 }
7264
65+ // CHECK-NEXT: - (void)blockWithTypealias:(NSInteger (^ _Nonnull)(NSInteger, id _Nullable))input;
7366 func blockWithTypealias( _ input: @escaping ( MyTuple ) -> MyInt ) { }
67+
68+ // CHECK-NEXT: - (void)blockWithSimpleTypealias:(NSInteger (^ _Nonnull)(NSInteger))input;
7469 func blockWithSimpleTypealias( _ input: @escaping ( MyInt ) -> MyInt ) { }
7570
71+ // CHECK-NEXT: - (void)namedArguments:(void (^ _Nonnull)(float, float, double, double))input;
7672 func namedArguments( _ input: @escaping ( _ f1: Float , _ f2: Float , _ d1: Double , _ d2: Double ) -> ( ) ) { }
73+
74+ // CHECK-NEXT: - (void)blockTakesNamedBlock:(void (^ _Nonnull)(SWIFT_NOESCAPE void (^ _Nonnull)(void)))input;
7775 func blockTakesNamedBlock( _ input: @escaping ( _ block: ( ) -> ( ) ) -> ( ) ) { }
76+
77+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithNamedInput;
7878 func returnsBlockWithNamedInput( ) -> ( ( _ object: NSObject ) -> ( ) ) ? {
7979 return nil
8080 }
8181
82+ // CHECK-NEXT: - (void)blockWithTypealiasWithNames:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(NSInteger a, id _Nullable b))input;
8283 func blockWithTypealiasWithNames( _ input: ( MyNamedTuple ) -> MyInt ) { }
8384
85+ // CHECK-NEXT: - (void)blockWithKeyword:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(NSInteger))_Nullable_;
8486 func blockWithKeyword( _ _Nullable: ( _ `class`: Int ) -> Int ) { }
8587
88+ // CHECK-NEXT: - (NSInteger (* _Nonnull)(NSInteger))functionPointers:(NSInteger (* _Nonnull)(NSInteger))input;
8689 func functionPointers( _ input: @escaping @convention ( c) ( Int ) -> Int )
8790 -> @convention ( c) ( Int ) -> Int {
8891 return input
8992 }
9093
94+ // CHECK-NEXT: - (void)blockWithBlockTypealias:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(void (^ _Nonnull)(void)))block;
95+ func blockWithBlockTypealias( _ block: MyBlockWithEscapingParam ) { }
96+
97+ // CHECK-NEXT: - (void)blockWithBlockTypealias2:(NSInteger (^ _Nonnull)(void (^ _Nonnull)(void)))block;
98+ func blockWithBlockTypealias2( _ block: @escaping MyBlockWithEscapingParam ) { }
99+
100+ // CHECK-NEXT: - (void)blockWithBlockTypealias3:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(SWIFT_NOESCAPE void (^ _Nonnull)(void)))block;
101+ func blockWithBlockTypealias3( _ block: MyBlockWithNoescapeParam ) { }
102+
103+ // CHECK-NEXT: - (void)blockWithBlockTypealias4:(NSInteger (^ _Nonnull)(SWIFT_NOESCAPE void (^ _Nonnull)(void)))block;
104+ func blockWithBlockTypealias4( _ block: @escaping MyBlockWithNoescapeParam ) { }
105+
106+ // CHECK-NEXT: - (void)functionPointerTakesAndReturnsFunctionPointer:(NSInteger (* _Nonnull (^ _Nonnull (* _Nonnull)(NSInteger))(NSInteger))(NSInteger))input;
91107 func functionPointerTakesAndReturnsFunctionPointer(
92108 _ input: @escaping @convention ( c) ( Int ) -> ( Int )
93109 -> @convention ( c) ( Int ) -> Int
94110 ) {
95111 }
112+
113+ // CHECK-NEXT: - (void (* _Nonnull)(SWIFT_NOESCAPE NSInteger (* _Nonnull)(NSInteger, NSInteger)))returnsFunctionPointerThatTakesFunctionPointer;
114+ func returnsFunctionPointerThatTakesFunctionPointer( ) ->
115+ @convention ( c) ( _ comparator: @convention ( c) ( _ x: Int , _ y: Int ) -> Int ) -> Void {
116+ fatalError ( )
117+ }
96118
119+ // CHECK-NEXT: - (NSInteger (* _Nonnull)(NSInteger))functionPointersWithName:(NSInteger (* _Nonnull)(NSInteger))input;
97120 func functionPointersWithName( _ input: @escaping @convention ( c) ( _ value: Int ) -> Int )
98121 -> @convention ( c) ( _ result: Int ) -> Int {
99122 return input
100123 }
101124
125+ // CHECK-NEXT: @property (nonatomic, copy) NSInteger (^ _Nullable savedBlock)(NSInteger);
102126 var savedBlock : ( ( Int ) -> Int ) ?
127+
128+ // CHECK-NEXT: @property (nonatomic, copy) NSInteger (^ _Nullable savedBlockWithName)(NSInteger);
103129 var savedBlockWithName : ( ( _ x: Int ) -> Int ) ?
130+
131+ // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nonnull savedFunctionPointer)(NSInteger);
104132 var savedFunctionPointer : @convention ( c) ( Int ) -> Int = { $0 }
133+
134+ // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nullable savedFunctionPointer2)(NSInteger);
105135 var savedFunctionPointer2 : ( @convention ( c) ( Int ) -> Int ) ? = { $0 }
136+
137+ // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nonnull savedFunctionPointerWithName)(NSInteger);
106138 var savedFunctionPointerWithName : @convention ( c) ( _ x: Int ) -> Int = { $0 }
107139
108140 // The following uses a clang keyword as the name.
141+
142+ // CHECK-NEXT: @property (nonatomic, copy, getter=this, setter=setThis:) NSInteger (^ _Nonnull this_)(NSInteger);
109143 var this : ( _ block: Int ) -> Int = { $0 }
144+
145+ // CHECK-NEXT: @property (nonatomic, getter=class, setter=setClass:) NSInteger (* _Nonnull class_)(NSInteger);
110146 var `class` : @convention ( c) ( _ function: Int ) -> Int = { $0 }
111147}
148+ // CHECK-NEXT: init
149+ // CHECK-NEXT: @end
0 commit comments