File: attr-swift-async-error.m

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (102 lines) | stat: -rw-r--r-- 3,699 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// RUN: %clang_cc1 %s -fblocks -fsyntax-only -verify

#define ASYNC(...) __attribute__((swift_async(__VA_ARGS__)))
#define ASYNC_ERROR(...) __attribute__((swift_async_error(__VA_ARGS__)))

ASYNC(swift_private, 1)
ASYNC_ERROR(zero_argument, 1)
void test_good(void (^handler)(int));

ASYNC(swift_private, 2)
ASYNC_ERROR(nonzero_argument, 2)
void test_good2(double, void (^handler)(double, int, double));

enum SomeEnum { SE_a, SE_b };

ASYNC(swift_private, 1)
ASYNC_ERROR(nonzero_argument, 1)
void test_good3(void (^handler)(enum SomeEnum, double));

ASYNC_ERROR(zero_argument, 1)
ASYNC(swift_private, 1)
void test_rev_order(void (^handler)(int));

@class NSError;

ASYNC(swift_private, 1)
ASYNC_ERROR(nonnull_error)
void test_nserror(void (^handler)(NSError *));

typedef struct __attribute__((objc_bridge(NSError))) __CFError * CFErrorRef;

ASYNC(swift_private, 1)
ASYNC_ERROR(nonnull_error)
void test_cferror(void (^handler)(CFErrorRef));

ASYNC(swift_private, 1)
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}}
void test_interror(void (^handler)(int));

ASYNC(swift_private, 1)
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'}}
void test_not_integral(void (^handler)(double));

ASYNC(swift_private, 1)
ASYNC_ERROR(none)
void test_none(void (^)(void));

ASYNC(none)
ASYNC_ERROR(none)
void test_double_none(void (^)(void));

ASYNC(none)
ASYNC_ERROR(none, 1) // expected-error {{'swift_async_error' attribute takes one argument}}
void test_double_none_args(void);

ASYNC(swift_private, 1)
ASYNC_ERROR(nonnull_error, 1) // expected-error{{'swift_async_error' attribute takes one argument}}
void test_args(void (^)(void));

ASYNC(swift_private, 1)
ASYNC_ERROR(zero_argument, 1, 1) // expected-error{{'swift_async_error' attribute takes no more than 2 arguments}}
void test_args2(void (^)(int));

ASYNC_ERROR(none) int x; // expected-warning{{'swift_async_error' attribute only applies to functions and Objective-C methods}}

@interface ObjC
-(void)m1:(void (^)(int))handler
  ASYNC(swift_private, 1)
  ASYNC_ERROR(zero_argument, 1);

-(void)m2:(int)first withSecond:(void (^)(int))handler
  ASYNC(swift_private, 2)
  ASYNC_ERROR(nonzero_argument, 1);

-(void)m3:(void (^)(void))block
  ASYNC_ERROR(zero_argument, 1) // expected-error {{'swift_async_error' attribute parameter 2 is out of bounds}}
  ASYNC(swift_private, 1);

-(void)m4:(void (^)(double, int, float))handler
  ASYNC(swift_private, 1)
  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'}}

-(void)m5:(void (^)(NSError *))handler
  ASYNC(swift_private, 1)
  ASYNC_ERROR(nonnull_error);

-(void)m6:(void (^)(void *))handler
  ASYNC(swift_private, 1)
  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}}
@end

// 'swift_error' and 'swift_async_error' are OK on one function.
ASYNC(swift_private, 1)
ASYNC_ERROR(nonnull_error)
__attribute__((swift_error(nonnull_error)))
void swift_error_and_swift_async_error(void (^handler)(NSError *), NSError **);

@interface TestNoSwiftAsync
// swift_async_error can make sense without swift_async.
-(void)doAThingWithCompletion:(void (^)(NSError *))completion
  ASYNC_ERROR(nonnull_error);
@end