55
66import Foundation
77
8+ @objc protocol P {
9+ @objc optional func e( )
10+ }
11+
812class X {
913 init ( ) { }
1014
@@ -15,11 +19,15 @@ class X {
1519 return 17
1620 }
1721}
22+ extension X : P {
23+ @objc func e( ) { print ( " X.e() " ) }
24+ }
1825
1926class Y {
2027 init ( ) { }
2128 @objc class func g( ) { print ( " Y.g() " ) }
2229}
30+ extension Y : P { }
2331
2432class Z {
2533 init ( ) { }
@@ -44,7 +52,16 @@ func test_dynamic_lookup_f_unbound(_ obj: AnyObject) {
4452 if of != nil {
4553 of!( )
4654 } 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 \" " )
4865 }
4966}
5067
@@ -77,11 +94,20 @@ test_dynamic_lookup_f(Z())
7794print ( type ( of: AnyObject . f) )
7895// CHECK-NEXT: X.f()
7996test_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"
8198test_dynamic_lookup_f_unbound ( Y ( ) )
8299// CHECK-NEXT: Z.f()
83100test_dynamic_lookup_f_unbound ( Z ( ) )
84101
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+
85111// CHECK: Class does not respond to the selector "g"
86112test_dynamic_lookup_g ( X ( ) )
87113// CHECK: Y.g()
0 commit comments