forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathattr_ibaction.swift
125 lines (103 loc) · 6.91 KB
/
attr_ibaction.swift
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// RUN: %target-typecheck-verify-swift
// REQUIRES: objc_interop
@IBAction // expected-error {{@IBAction may only be used on 'func' declarations}} {{1-11=}}
var iboutlet_global: Int
@IBAction // expected-error {{@IBAction may only be used on 'func' declarations}} {{1-11=}}
class IBOutletClassTy {}
@IBAction // expected-error {{@IBAction may only be used on 'func' declarations}} {{1-11=}}
struct IBStructTy {}
@IBAction // expected-error {{only instance methods can be declared @IBAction}} {{1-11=}}
func IBFunction() -> () {}
class IBActionWrapperTy {
@IBAction
func click(_: AnyObject) -> () {} // no-warning
func outer(_: AnyObject) -> () {
@IBAction // expected-error {{only instance methods can be declared @IBAction}} {{5-15=}}
func inner(_: AnyObject) -> () {}
}
@IBAction // expected-error {{@IBAction may only be used on 'func' declarations}} {{3-13=}}
var value : Void = ()
@IBAction
func process(x: AnyObject) -> Int {} // expected-error {{methods declared @IBAction must return 'Void' (not 'Int')}}
// @IBAction does /not/ semantically imply @objc.
@IBAction // expected-note {{attribute already specified here}}
@IBAction // expected-error {{duplicate attribute}}
func doMagic(_: AnyObject) -> () {}
@IBAction @objc
func moreMagic(_: AnyObject) -> () {} // no-warning
@objc @IBAction
func evenMoreMagic(_: AnyObject) -> () {} // no-warning
}
struct S { }
enum E { }
protocol P1 { }
protocol P2 { }
protocol CP1 : class { }
protocol CP2 : class { }
@objc protocol OP1 { }
@objc protocol OP2 { }
// Check which argument types @IBAction can take.
@objc class X {
// Class type
@IBAction func action1(_: X) {}
@IBAction func action2(_: X?) {}
@IBAction func action3(_: X!) {}
// AnyObject
@IBAction func action4(_: AnyObject) {}
@IBAction func action5(_: AnyObject?) {}
@IBAction func action6(_: AnyObject!) {}
// Any
@IBAction func action4a(_: Any) {}
@IBAction func action5a(_: Any?) {}
@IBAction func action6a(_: Any!) {}
// Protocol types
@IBAction func action7(_: P1) {} // expected-error{{argument to @IBAction method cannot have non-object type 'P1'}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2{{protocol 'P1' is not '@objc'}}
@IBAction func action8(_: CP1) {} // expected-error{{argument to @IBAction method cannot have non-object type 'CP1'}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2{{protocol 'CP1' is not '@objc'}}
@IBAction func action9(_: OP1) {}
@IBAction func action10(_: P1?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action11(_: CP1?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action12(_: OP1?) {}
@IBAction func action13(_: P1!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action14(_: CP1!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action15(_: OP1!) {}
// Class metatype
@IBAction func action15b(_: X.Type) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
@IBAction func action16(_: X.Type?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
@IBAction func action17(_: X.Type!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// AnyClass
@IBAction func action18(_: AnyClass) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
@IBAction func action19(_: AnyClass?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
@IBAction func action20(_: AnyClass!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// Protocol types
@IBAction func action21(_: P1.Type) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action22(_: CP1.Type) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action23(_: OP1.Type) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
@IBAction func action24(_: P1.Type?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action25(_: CP1.Type?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action26(_: OP1.Type?) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
@IBAction func action27(_: P1.Type!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
//expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action28(_: CP1.Type!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
//expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
@IBAction func action29(_: OP1.Type!) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// Other bad cases
@IBAction func action30(_: S) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2{{Swift structs cannot be represented in Objective-C}}
@IBAction func action31(_: E) {} // expected-error{{argument to @IBAction method cannot have non-object type}}
// expected-error@-1{{method cannot be marked @IBAction because the type of the parameter cannot be represented in Objective-C}}
// expected-note@-2{{non-'@objc' enums cannot be represented in Objective-C}}
init() { }
}