Skip to content

Commit cfdb957

Browse files
committed
Update Interpreter tests for id-as-Any.
1 parent ee9675d commit cfdb957

14 files changed

+114
-114
lines changed

test/Interpreter/SDK/Foundation_bridge.swift

Lines changed: 61 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -8,137 +8,131 @@
88
import Foundation
99

1010
// CHECK: 17 bridges to 17
11-
var i = 17
12-
if let obj = _bridgeToObjectiveC(i) {
11+
do {
12+
var i = 17
13+
let obj = _bridgeAnythingToObjectiveC(i)
1314
print("\(i) bridges to \(obj.description!)")
14-
} else {
15-
print("\(i) is not bridged to Objective-C")
1615
}
1716

1817
// CHECK: 3.14159 bridges to 3.14159
19-
var d = 3.14159
20-
if let obj = _bridgeToObjectiveC(d) {
18+
do {
19+
var d = 3.14159
20+
let obj = _bridgeAnythingToObjectiveC(d)
2121
print("\(d) bridges to \(obj.description!)")
22-
} else {
23-
print("\(d) is not bridged to Objective-C")
2422
}
2523

2624
// CHECK: Hello, world! bridges to Hello, world!
27-
var s = "Hello, world!"
28-
if let obj = _bridgeToObjectiveC(s) {
25+
do {
26+
var s = "Hello, world!"
27+
let obj = _bridgeAnythingToObjectiveC(s)
2928
print("\(s) bridges to \(obj.description!)")
30-
} else {
31-
print("\(s) is not bridged to Objective-C")
3229
}
3330

34-
// CHECK: int array bridges to (
35-
// CHECK: 1
36-
// CHECK: 2
37-
// CHECK: 3
38-
// CHECK: )
39-
var a = [1, 2, 3]
40-
if let obj = _bridgeToObjectiveC(a) {
31+
// CHECK: int array bridges to (
32+
// CHECK: 1
33+
// CHECK: 2
34+
// CHECK: 3
35+
// CHECK: )
36+
do {
37+
var a = [1, 2, 3]
38+
let obj = _bridgeAnythingToObjectiveC(a)
4139
print("int array bridges to \(obj.description!)")
42-
} else {
43-
print("int array is not bridged to Objective-C")
4440
}
4541

46-
// CHECK: uint array bridges to (
47-
// CHECK: 1
48-
// CHECK: 2
49-
// CHECK: 3
50-
// CHECK: )
51-
var aui: [UInt] = [1, 2, 3]
52-
if let obj = _bridgeToObjectiveC(aui) {
42+
// CHECK: uint array bridges to (
43+
// CHECK: 1
44+
// CHECK: 2
45+
// CHECK: 3
46+
// CHECK: )
47+
do {
48+
var aui: [UInt] = [1, 2, 3]
49+
let obj = _bridgeAnythingToObjectiveC(aui)
5350
print("uint array bridges to \(obj.description!)")
54-
} else {
55-
print("uint array is not bridged to Objective-C")
5651
}
5752

5853
// CHECK: float array bridges to (
5954
// CHECK: 1.5
6055
// CHECK: 2.5
6156
// CHECK: 3.5
6257
// CHECK: )
63-
var af: [Float] = [1.5, 2.5, 3.5]
64-
if let obj = _bridgeToObjectiveC(af) {
58+
do {
59+
var af: [Float] = [1.5, 2.5, 3.5]
60+
let obj = _bridgeAnythingToObjectiveC(af)
6561
print("float array bridges to \(obj.description!)")
66-
} else {
67-
print("float array is not bridged to Objective-C")
6862
}
6963

7064
// CHECK: double array bridges to (
7165
// CHECK: 1.5
7266
// CHECK: 2.5
7367
// CHECK: 3.5
7468
// CHECK: )
75-
var ad = [1.5, 2.5, 3.5]
76-
if let obj = _bridgeToObjectiveC(ad) {
69+
do {
70+
var ad = [1.5, 2.5, 3.5]
71+
let obj = _bridgeAnythingToObjectiveC(ad)
7772
print("double array bridges to \(obj.description!)")
78-
} else {
79-
print("double array is not bridged to Objective-C")
8073
}
8174

8275
// CHECK: string array bridges to (
8376
// CHECK: Hello
8477
// CHECK: Swift
8578
// CHECK: World
8679
// CHECK: )
87-
var a2 = ["Hello", "Swift", "World"]
88-
if let obj = _bridgeToObjectiveC(a2) {
80+
do {
81+
var a2 = ["Hello", "Swift", "World"]
82+
let obj = _bridgeAnythingToObjectiveC(a2)
8983
print("string array bridges to \(obj.description!)")
90-
} else {
91-
print("string array is not bridged to Objective-C")
9284
}
9385

9486
// CHECK: bool array bridges to (
9587
// CHECK: 0
9688
// CHECK: 1
9789
// CHECK: 0
9890
// CHECK: )
99-
var ab = [false, true, false]
100-
if let obj = _bridgeToObjectiveC(ab) {
91+
do {
92+
var ab = [false, true, false]
93+
let obj = _bridgeAnythingToObjectiveC(ab)
10194
print("bool array bridges to \(obj.description!)")
102-
} else {
103-
print("bool array is not bridged to Objective-C")
10495
}
10596

106-
// CHECK: tuple array is not bridged to Objective-C
107-
var a3 = [(1, 1), (1, 1), (1, 2)]
108-
if let obj = _bridgeToObjectiveC(a3) {
97+
// CHECK: tuple array bridges to (
98+
// CHECK: (1, 1)
99+
// CHECK: (1, 1)
100+
// CHECK: (1, 2)
101+
// CHECK: )
102+
do {
103+
var a3 = [(1, 1), (1, 1), (1, 2)]
104+
let obj = _bridgeAnythingToObjectiveC(a3)
109105
print("tuple array bridges to \(obj.description!)")
110-
} else {
111-
print("tuple array is not bridged to Objective-C")
112106
}
113107

114108
// CHECK: dictionary bridges to {
115109
// CHECK-NEXT: 2 = World;
116110
// CHECK-NEXT: 1 = Hello;
117111
// CHECK-NEXT: }
118-
var dict: Dictionary<NSNumber, NSString> = [1: "Hello", 2: "World"]
119-
if let obj = _bridgeToObjectiveC(dict) {
112+
do {
113+
var dict: Dictionary<NSNumber, NSString> = [1: "Hello", 2: "World"]
114+
let obj = _bridgeAnythingToObjectiveC(dict)
120115
print("dictionary bridges to \(obj.description!)")
121-
} else {
122-
print("dictionary is not bridged to Objective-C")
123116
}
124117

125118
// CHECK: dictionary bridges to {
126119
// CHECK-NEXT: 2 = World;
127120
// CHECK-NEXT: 1 = Hello;
128121
// CHECK-NEXT: }
129-
var dict2 = [1: "Hello", 2: "World"]
130-
if let obj = _bridgeToObjectiveC(dict2) {
122+
do {
123+
var dict2 = [1: "Hello", 2: "World"]
124+
let obj = _bridgeAnythingToObjectiveC(dict2)
131125
print("dictionary bridges to \(obj.description!)")
132-
} else {
133-
print("dictionary is not bridged to Objective-C")
134126
}
135127

136-
// CHECK: dictionary is not bridged to Objective-C
137-
var dict3 = [1: ("Hello", 1), 2: ("World", 2)]
138-
if let obj = _bridgeToObjectiveC(dict3) {
139-
print("dictionary bridges to \(obj.description!)")
140-
} else {
141-
print("dictionary is not bridged to Objective-C")
128+
// CHECK: dictionary bridges to {
129+
// CHECK-NEXT: 2 = "(\"World\", 2)";
130+
// CHECK-NEXT: 1 = "(\"Hello\", 1)";
131+
// CHECK-NEXT: }
132+
do {
133+
var dict3 = [1: ("Hello", 1), 2: ("World", 2)]
134+
let obj = _bridgeAnythingToObjectiveC(dict3)
135+
print("dictionary bridges to \(obj)")
142136
}
143137

144138
// Check dictionary bridging.
@@ -155,9 +149,9 @@ for key in dict4.keys {
155149
}
156150

157151
// CHECK: Hello: 1
158-
print("Hello: \(dict4[hello]!.description!)")
152+
print("Hello: \(dict4[hello]!)")
159153
// CHECK: World: 2
160-
print("World: \(dict4[world]!.description!)")
154+
print("World: \(dict4[world]!)")
161155

162156
// <rdar://problem/17035548> bridging array of blocks.
163157
class Foo: NSObject {

test/Interpreter/SDK/Foundation_test.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ FoundationTestSuite.test("NSArray") {
7979

8080
// Iteration
8181
var result = [String]()
82-
for x: AnyObject in nsArr {
82+
for x: Any in nsArr {
8383
result.append((x as! NSObject).description)
8484
}
8585
expectEqualSequence(["1", "2.5", "Hello"], result)
@@ -127,8 +127,8 @@ FoundationTestSuite.test("NSDictionary") {
127127
assert((nsDict[2]! as! NSString).isEqual("World"))
128128

129129
let nsMutableDict: NSMutableDictionary = ["Hello" : 1, "World" : 2]
130-
assert(nsMutableDict["Hello"]!.isEqual(1))
131-
assert(nsMutableDict["World"]!.isEqual(2))
130+
assert((nsMutableDict["Hello"]! as AnyObject).isEqual(1))
131+
assert((nsMutableDict["World"]! as AnyObject).isEqual(2))
132132
}
133133

134134
//===----------------------------------------------------------------------===//
@@ -190,7 +190,7 @@ FoundationTestSuite.test("rdar://17584531") {
190190
// <rdar://problem/17584531>
191191
// Type checker used to be confused by this.
192192
var dict: NSDictionary = ["status": 200, "people": [["id": 255, "name": ["first": "John", "last": "Appleseed"]]]]
193-
var dict2 = dict["people"]?[0] as! NSDictionary
193+
var dict2 = dict["people"].map { $0 as AnyObject }?[0] as! NSDictionary
194194
expectEqual("Optional(255)", String(dict2["id"]))
195195
}
196196

test/Interpreter/SDK/KVO.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ class Observer : NSObject {
3131
model.number = 42
3232
}
3333

34-
override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?) {
34+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutablePointer<Void>?) {
3535
if context != &kvoContext {
3636
// FIXME: we shouldn't need to unwrap these here, but it doesn't work on
3737
// older SDKs where these are non-optional types.
3838
return super.observeValue(forKeyPath: keyPath!, of: object!, change: change!, context: context)
3939
}
4040

41-
print(object!.value(forKeyPath: keyPath!))
41+
print((object! as AnyObject).value(forKeyPath: keyPath!))
4242
}
4343
}
4444

test/Interpreter/SDK/OS_objects.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import DispatchObjects
1616

1717
// CHECK: Get current queue
1818
print("Get current queue")
19-
let obj = dispatch_get_current_queue();
19+
// TODO: Properly implement generalized dynamic casts from Any to
20+
// runtime-visible classes. `as AnyObject` should be unnecessary here.
21+
let obj = dispatch_get_current_queue() as AnyObject
2022

2123
// CHECK-NEXT: Object is a dispatch queue
2224
if let q = obj as? OS_dispatch_queue {

test/Interpreter/SDK/Reflection_KVO.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ValueObserver: NSObject {
2525
observedValue.removeObserver(self, forKeyPath: "amount")
2626
}
2727

28-
override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?) {
28+
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutablePointer<Void>?) {
2929
if context == &observeContext {
3030
if let change_ = change {
3131
if let amount = change_[.newKey] as? Int {

test/Interpreter/SDK/class_as_object.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ classes.add(NSObject.self)
1212
classes.add(NSString.self)
1313
classes.add(NSNumber.self)
1414

15-
for obj: AnyObject in classes {
16-
print(obj.description)
15+
for obj in classes {
16+
print((obj as AnyObject).description)
1717
}
1818
// CHECK: NSObject
1919
// CHECK-NEXT: NSString

test/Interpreter/SDK/errors.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,27 @@ import StdlibUnittest
1414
struct Problem : Error {}
1515

1616
class ErrorImpl : NSObject, ErrorTest {
17-
func succeed() throws -> AnyObject { return self }
18-
func fail() throws -> AnyObject { throw Problem() }
17+
func succeed() throws -> Any { return self }
18+
func fail() throws -> Any { throw Problem() }
1919
}
2020

2121

2222
var ErrorHandlingTests = TestSuite("ErrorHandling")
2323

24+
func sameObject(_ x: Any?, _ y: Any?) -> Bool {
25+
return x.map { $0 as AnyObject } === y.map { $0 as AnyObject }
26+
}
27+
2428
ErrorHandlingTests.test("succeed") {
2529
let obj = ErrorImpl()
2630
let result = testSucceed(obj)
27-
expectTrue(obj === result)
31+
expectTrue(sameObject(obj, result))
2832
}
2933

3034
ErrorHandlingTests.test("succeedIgnoringError") {
3135
let obj = ErrorImpl()
3236
let result = testSucceedIgnoringError(obj)
33-
expectTrue(obj === result)
37+
expectTrue(sameObject(obj, result))
3438
}
3539

3640
ErrorHandlingTests.test("fail") {

test/Interpreter/SDK/objc_array_of_classes.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ ArrayOfClassObjectBridging.test("bridging class object array to NSArray") {
3232
let classesBridged: NSArray = classes as NSArray
3333

3434
expectTrue(classesBridged.count == 3)
35-
expectTrue(classesBridged[0] === NSObject.self)
36-
expectTrue(classesBridged[1] === NSString.self)
37-
expectTrue(classesBridged[2] === NSArray.self)
35+
expectTrue(classesBridged[0] as AnyObject === NSObject.self)
36+
expectTrue(classesBridged[1] as AnyObject === NSString.self)
37+
expectTrue(classesBridged[2] as AnyObject === NSArray.self)
3838
}
3939

4040
ArrayOfClassObjectBridging.test("bridging NSArray of class objects to [AnyObject]") {

test/Interpreter/SDK/objc_dynamic_lookup.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import Foundation
88
// Dynamic subscripting of NSArray, dynamic method dispatch
99
// CHECK: {{^3$}}
1010
var array : AnyObject = [1, 2, 3, 4, 5]
11-
print(array[2].description)
11+
print((array[2] as AnyObject).description)
1212

1313
// Dynamic subscripting on an array using an object (fails)
1414
// CHECK: NSArray subscript with an object fails
1515
var optVal1 = array["Hello"]
1616
if optVal1 != nil {
17-
print((optVal1!)!.description)
17+
print(((optVal1!)! as AnyObject).description)
1818
} else {
1919
print("NSArray subscript with an object fails")
2020
}
@@ -23,13 +23,13 @@ if optVal1 != nil {
2323
// CHECK: {{^2$}}
2424
var nsdict : NSDictionary = ["Hello" : 1, "World" : 2]
2525
var dict : AnyObject = nsdict
26-
print((dict["World"]!)!.description)
26+
print(((dict["World"]!)! as AnyObject).description)
2727

2828
// Dynamic subscripting on a dictionary using an index (fails)
2929
// CHECK: NSDictionary subscript with an index fails
3030
var optVal2 = dict[1]
3131
if optVal2 != nil {
32-
print(optVal2!.description)
32+
print((optVal2! as AnyObject).description)
3333
} else {
3434
print("NSDictionary subscript with an index fails")
3535
}

0 commit comments

Comments
 (0)