@@ -14,98 +14,136 @@ import ObjectiveC
14
14
typealias MyTuple = ( Int , AnyObject ? )
15
15
typealias MyNamedTuple = ( a: Int , b: AnyObject ? )
16
16
typealias MyInt = Int
17
+ typealias MyBlockWithEscapingParam = ( @escaping ( ) -> ( ) ) -> Int
18
+ typealias MyBlockWithNoescapeParam = ( ( ) -> ( ) ) -> Int
19
+
20
+ // Please see related tests in PrintAsObjC/imported-block-typedefs.swift.
17
21
18
22
// 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
47
23
@objc class Callbacks {
24
+
25
+ // CHECK-NEXT: - (void (^ _Nonnull)(void))voidBlocks:(void (^ _Nonnull)(void))input;
48
26
func voidBlocks( _ input: @escaping ( ) -> ( ) ) -> ( ) -> ( ) {
49
27
return input
50
28
}
29
+
30
+ // CHECK-NEXT: - (void)manyArguments:(void (^ _Nonnull)(float, float, double, double))input;
51
31
func manyArguments( _ input: @escaping ( Float , Float , Double , Double ) -> ( ) ) { }
52
32
33
+ // CHECK-NEXT: - (void)blockTakesBlock:(void (^ _Nonnull)(SWIFT_NOESCAPE void (^ _Nonnull)(void)))input;
53
34
func blockTakesBlock( _ input: @escaping ( ( ) -> ( ) ) -> ( ) ) { }
35
+
36
+ // CHECK-NEXT: - (void)blockReturnsBlock:(void (^ _Nonnull (^ _Nonnull)(void))(void))input;
54
37
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;
55
40
func blockTakesAndReturnsBlock( _ input:
56
41
( ( Int16 ) -> ( UInt16 ) ) ->
57
42
( ( 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;
58
45
func blockTakesTwoBlocksAndReturnsBlock( _ input:
59
46
( ( Int16 ) -> ( UInt16 ) ,
60
47
( Int32 ) -> ( UInt32 ) ) ->
61
48
( ( Int8 ) -> ( UInt8 ) ) ) { }
62
49
50
+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithInput;
63
51
func returnsBlockWithInput( ) -> ( ( NSObject ) -> ( ) ) ? {
64
52
return nil
65
53
}
54
+
55
+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithParenthesizedInput;
66
56
func returnsBlockWithParenthesizedInput( ) -> ( ( NSObject ) -> ( ) ) ? {
67
57
return nil
68
58
}
59
+
60
+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull, NSObject * _Nonnull))returnsBlockWithTwoInputs;
69
61
func returnsBlockWithTwoInputs( ) -> ( ( NSObject , NSObject ) -> ( ) ) ? {
70
62
return nil
71
63
}
72
64
65
+ // CHECK-NEXT: - (void)blockWithTypealias:(NSInteger (^ _Nonnull)(NSInteger, id _Nullable))input;
73
66
func blockWithTypealias( _ input: @escaping ( MyTuple ) -> MyInt ) { }
67
+
68
+ // CHECK-NEXT: - (void)blockWithSimpleTypealias:(NSInteger (^ _Nonnull)(NSInteger))input;
74
69
func blockWithSimpleTypealias( _ input: @escaping ( MyInt ) -> MyInt ) { }
75
70
71
+ // CHECK-NEXT: - (void)namedArguments:(void (^ _Nonnull)(float, float, double, double))input;
76
72
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;
77
75
func blockTakesNamedBlock( _ input: @escaping ( _ block: ( ) -> ( ) ) -> ( ) ) { }
76
+
77
+ // CHECK-NEXT: - (void (^ _Nullable)(NSObject * _Nonnull))returnsBlockWithNamedInput;
78
78
func returnsBlockWithNamedInput( ) -> ( ( _ object: NSObject ) -> ( ) ) ? {
79
79
return nil
80
80
}
81
81
82
+ // CHECK-NEXT: - (void)blockWithTypealiasWithNames:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(NSInteger a, id _Nullable b))input;
82
83
func blockWithTypealiasWithNames( _ input: ( MyNamedTuple ) -> MyInt ) { }
83
84
85
+ // CHECK-NEXT: - (void)blockWithKeyword:(SWIFT_NOESCAPE NSInteger (^ _Nonnull)(NSInteger))_Nullable_;
84
86
func blockWithKeyword( _ _Nullable: ( _ `class`: Int ) -> Int ) { }
85
87
88
+ // CHECK-NEXT: - (NSInteger (* _Nonnull)(NSInteger))functionPointers:(NSInteger (* _Nonnull)(NSInteger))input;
86
89
func functionPointers( _ input: @escaping @convention ( c) ( Int ) -> Int )
87
90
-> @convention ( c) ( Int ) -> Int {
88
91
return input
89
92
}
90
93
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;
91
107
func functionPointerTakesAndReturnsFunctionPointer(
92
108
_ input: @escaping @convention ( c) ( Int ) -> ( Int )
93
109
-> @convention ( c) ( Int ) -> Int
94
110
) {
95
111
}
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
+ }
96
118
119
+ // CHECK-NEXT: - (NSInteger (* _Nonnull)(NSInteger))functionPointersWithName:(NSInteger (* _Nonnull)(NSInteger))input;
97
120
func functionPointersWithName( _ input: @escaping @convention ( c) ( _ value: Int ) -> Int )
98
121
-> @convention ( c) ( _ result: Int ) -> Int {
99
122
return input
100
123
}
101
124
125
+ // CHECK-NEXT: @property (nonatomic, copy) NSInteger (^ _Nullable savedBlock)(NSInteger);
102
126
var savedBlock : ( ( Int ) -> Int ) ?
127
+
128
+ // CHECK-NEXT: @property (nonatomic, copy) NSInteger (^ _Nullable savedBlockWithName)(NSInteger);
103
129
var savedBlockWithName : ( ( _ x: Int ) -> Int ) ?
130
+
131
+ // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nonnull savedFunctionPointer)(NSInteger);
104
132
var savedFunctionPointer : @convention ( c) ( Int ) -> Int = { $0 }
133
+
134
+ // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nullable savedFunctionPointer2)(NSInteger);
105
135
var savedFunctionPointer2 : ( @convention ( c) ( Int ) -> Int ) ? = { $0 }
136
+
137
+ // CHECK-NEXT: @property (nonatomic) NSInteger (* _Nonnull savedFunctionPointerWithName)(NSInteger);
106
138
var savedFunctionPointerWithName : @convention ( c) ( _ x: Int ) -> Int = { $0 }
107
139
108
140
// The following uses a clang keyword as the name.
141
+
142
+ // CHECK-NEXT: @property (nonatomic, copy, getter=this, setter=setThis:) NSInteger (^ _Nonnull this_)(NSInteger);
109
143
var this : ( _ block: Int ) -> Int = { $0 }
144
+
145
+ // CHECK-NEXT: @property (nonatomic, getter=class, setter=setClass:) NSInteger (* _Nonnull class_)(NSInteger);
110
146
var `class` : @convention ( c) ( _ function: Int ) -> Int = { $0 }
111
147
}
148
+ // CHECK-NEXT: init
149
+ // CHECK-NEXT: @end
0 commit comments