5
5
6
6
import Foundation
7
7
8
+ @objc protocol P {
9
+ @objc optional func e( )
10
+ }
11
+
8
12
class X {
9
13
init ( ) { }
10
14
@@ -15,11 +19,15 @@ class X {
15
19
return 17
16
20
}
17
21
}
22
+ extension X : P {
23
+ @objc func e( ) { print ( " X.e() " ) }
24
+ }
18
25
19
26
class Y {
20
27
init ( ) { }
21
28
@objc class func g( ) { print ( " Y.g() " ) }
22
29
}
30
+ extension Y : P { }
23
31
24
32
class Z {
25
33
init ( ) { }
@@ -44,7 +52,16 @@ func test_dynamic_lookup_f_unbound(_ obj: AnyObject) {
44
52
if of != nil {
45
53
of!( )
46
54
} else {
47
- print ( " Object does not respond to the selector \" f \" . \n " , terminator: " " )
55
+ print ( " \( type ( of: obj) ) does not respond to the selector \" f \" " )
56
+ }
57
+ }
58
+
59
+ func test_dynamic_lookup_e_unbound( _ obj: AnyObject ) {
60
+ var oe = AnyObject . e ( obj)
61
+ if oe != nil {
62
+ oe!( )
63
+ } else {
64
+ print ( " \( type ( of: obj) ) does not respond to the selector \" e \" " )
48
65
}
49
66
}
50
67
@@ -77,11 +94,20 @@ test_dynamic_lookup_f(Z())
77
94
print ( type ( of: AnyObject . f) )
78
95
// CHECK-NEXT: X.f()
79
96
test_dynamic_lookup_f_unbound ( X ( ) )
80
- // CHECK-NEXT: Object does not respond to the selector "f"
97
+ // CHECK-NEXT: Y does not respond to the selector "f"
81
98
test_dynamic_lookup_f_unbound ( Y ( ) )
82
99
// CHECK-NEXT: Z.f()
83
100
test_dynamic_lookup_f_unbound ( Z ( ) )
84
101
102
+ // CHECK-NEXT: (AnyObject) -> Optional<() -> ()>
103
+ print ( type ( of: AnyObject . e) )
104
+ // CHECK-NEXT: X.e()
105
+ test_dynamic_lookup_e_unbound ( X ( ) )
106
+ // CHECK-NEXT: Y does not respond to the selector "e"
107
+ test_dynamic_lookup_e_unbound ( Y ( ) )
108
+ // CHECK-NEXT: Z does not respond to the selector "e"
109
+ test_dynamic_lookup_e_unbound ( Z ( ) )
110
+
85
111
// CHECK: Class does not respond to the selector "g"
86
112
test_dynamic_lookup_g ( X ( ) )
87
113
// CHECK: Y.g()
0 commit comments