Skip to content

Commit 97eb772

Browse files
committed
Add executable tests for the edge case of unbound reference to optional method on AnyObject
1 parent ad8a1eb commit 97eb772

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/Interpreter/dynamic_lookup.swift

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
import Foundation
77

8+
@objc protocol P {
9+
@objc optional func e()
10+
}
11+
812
class 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

1926
class Y {
2027
init() {}
2128
@objc class func g() { print("Y.g()") }
2229
}
30+
extension Y: P {}
2331

2432
class 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())
7794
print(type(of: AnyObject.f))
7895
// CHECK-NEXT: X.f()
7996
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"
8198
test_dynamic_lookup_f_unbound(Y())
8299
// CHECK-NEXT: Z.f()
83100
test_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"
86112
test_dynamic_lookup_g(X())
87113
// CHECK: Y.g()

0 commit comments

Comments
 (0)