annotate clang/test/SemaObjC/attr-swift-async-error.m @ 207:2e18cbf3894f

LLVM12
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 08 Jun 2021 06:07:14 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 // RUN: %clang_cc1 %s -fblocks -fsyntax-only -verify
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #define ASYNC(...) __attribute__((swift_async(__VA_ARGS__)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #define ASYNC_ERROR(...) __attribute__((swift_async_error(__VA_ARGS__)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 ASYNC_ERROR(zero_argument, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 void test_good(void (^handler)(int));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 ASYNC(swift_private, 2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 ASYNC_ERROR(nonzero_argument, 2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 void test_good2(double, void (^handler)(double, int, double));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 enum SomeEnum { SE_a, SE_b };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 ASYNC_ERROR(nonzero_argument, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 void test_good3(void (^handler)(enum SomeEnum, double));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 ASYNC_ERROR(zero_argument, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 void test_rev_order(void (^handler)(int));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 @class NSError;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 ASYNC_ERROR(nonnull_error)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 void test_nserror(void (^handler)(NSError *));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 typedef struct __attribute__((objc_bridge(NSError))) __CFError * CFErrorRef;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 ASYNC_ERROR(nonnull_error)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 void test_cferror(void (^handler)(CFErrorRef));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 ASYNC_ERROR(nonnull_error) // expected-error {{'swift_async_error' attribute with 'nonnull_error' convention can only be applied to a function with a completion handler with an error parameter}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 void test_interror(void (^handler)(int));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 ASYNC_ERROR(zero_argument, 1) // expected-error {{'swift_async_error' attribute with 'zero_argument' convention must have an integral-typed parameter in completion handler at index 1, type here is 'double'}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 void test_not_integral(void (^handler)(double));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 ASYNC_ERROR(none)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 void test_none(void (^)());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ASYNC(none)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 ASYNC_ERROR(none)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 void test_double_none(void (^)());
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 ASYNC(none)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 ASYNC_ERROR(none, 1) // expected-error {{'swift_async_error' attribute takes one argument}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 void test_double_none_args();
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 ASYNC_ERROR(nonnull_error, 1) // expected-error{{'swift_async_error' attribute takes one argument}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 void test_args(void (^)(void));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 ASYNC_ERROR(zero_argument, 1, 1) // expected-error{{'swift_async_error' attribute takes no more than 2 arguments}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 void test_args2(void (^)(int));
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 ASYNC_ERROR(none) int x; // expected-warning{{'swift_async_error' attribute only applies to functions and Objective-C methods}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 @interface ObjC
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 -(void)m1:(void (^)(int))handler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 ASYNC_ERROR(zero_argument, 1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 -(void)m2:(int)first withSecond:(void (^)(int))handler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 ASYNC(swift_private, 2)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 ASYNC_ERROR(nonzero_argument, 1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 -(void)m3:(void (^)(void))block
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 ASYNC_ERROR(zero_argument, 1) // expected-error {{'swift_async_error' attribute parameter 2 is out of bounds}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 ASYNC(swift_private, 1);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 -(void)m4:(void (^)(double, int, float))handler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 ASYNC_ERROR(nonzero_argument, 1); // expected-error{{swift_async_error' attribute with 'nonzero_argument' convention must have an integral-typed parameter in completion handler at index 1, type here is 'double'}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 -(void)m5:(void (^)(NSError *))handler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 ASYNC_ERROR(nonnull_error);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 -(void)m6:(void (^)(void *))handler
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 ASYNC_ERROR(nonnull_error); // expected-error{{'swift_async_error' attribute with 'nonnull_error' convention can only be applied to a method with a completion handler with an error parameter}}
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 @end
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 // 'swift_error' and 'swift_async_error' are OK on one function.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 ASYNC(swift_private, 1)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 ASYNC_ERROR(nonnull_error)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 __attribute__((swift_error(nonnull_error)))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 void swift_error_and_swift_async_error(void (^handler)(NSError *), NSError **);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 @interface TestNoSwiftAsync
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 // swift_async_error can make sense without swift_async.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 -(void)doAThingWithCompletion:(void (^)(NSError *))completion
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 ASYNC_ERROR(nonnull_error);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 @end