@@ -66,34 +66,33 @@ Runtime.test("_canBeClass") {
66
66
67
67
//===----------------------------------------------------------------------===//
68
68
69
- protocol MyBoolean {
70
- var boolValue : Bool { get }
71
- }
72
-
73
- extension Bool : MyBoolean {
74
- var boolValue : Bool { return self }
75
- }
76
-
77
69
// The protocol should be defined in the standard library, otherwise the cast
78
70
// does not work.
79
- typealias P1 = MyBoolean
71
+ typealias P1 = CustomReflectable
80
72
typealias P2 = CustomStringConvertible
81
73
protocol Q1 {}
82
74
75
+ extension P1 {
76
+ var success: Bool {
77
+ print(String(customMirror))
78
+ return String(customMirror) == "Mirror for ()"
79
+ }
80
+ }
81
+
83
82
// A small struct that can be stored inline in an opaque buffer.
84
- struct StructConformsToP1 : MyBoolean , Q1 {
85
- var boolValue: Bool {
86
- return true
83
+ struct StructConformsToP1 : CustomReflectable , Q1 {
84
+ var customMirror: Mirror {
85
+ return Mirror(reflecting: ())
87
86
}
88
87
}
89
88
90
89
// A small struct that can be stored inline in an opaque buffer.
91
- struct Struct2ConformsToP1<T : MyBoolean > : MyBoolean , Q1 {
90
+ struct Struct2ConformsToP1<T : CustomReflectable > : CustomReflectable , Q1 {
92
91
init(_ value: T) {
93
92
self.value = value
94
93
}
95
- var boolValue: Bool {
96
- return value.boolValue
94
+ var customMirror: Mirror {
95
+ return value.customMirror
97
96
}
98
97
var value: T
99
98
}
@@ -143,18 +142,18 @@ struct Struct4ConformsToP2<T : CustomStringConvertible> : CustomStringConvertibl
143
142
144
143
struct StructDoesNotConformToP1 : Q1 {}
145
144
146
- class ClassConformsToP1 : MyBoolean , Q1 {
147
- var boolValue: Bool {
148
- return true
145
+ class ClassConformsToP1 : CustomReflectable , Q1 {
146
+ var customMirror: Mirror {
147
+ return Mirror(reflecting: ())
149
148
}
150
149
}
151
150
152
- class Class2ConformsToP1<T : MyBoolean > : MyBoolean , Q1 {
151
+ class Class2ConformsToP1<T : CustomReflectable > : CustomReflectable , Q1 {
153
152
init(_ value: T) {
154
153
self.value = [value]
155
154
}
156
- var boolValue: Bool {
157
- return value[0].boolValue
155
+ var customMirror: Mirror {
156
+ return value[0].customMirror
158
157
}
159
158
// FIXME: should be "var value: T", but we don't support it now.
160
159
var value: Array<T>
@@ -164,12 +163,12 @@ class ClassDoesNotConformToP1 : Q1 {}
164
163
165
164
Runtime.test("dynamicCasting with as") {
166
165
var someP1Value = StructConformsToP1()
167
- var someP1Value2 = Struct2ConformsToP1(true )
166
+ var someP1Value2 = Struct2ConformsToP1(StructConformsToP1() )
168
167
var someNotP1Value = StructDoesNotConformToP1()
169
168
var someP2Value = Struct3ConformsToP2()
170
169
var someP2Value2 = Struct4ConformsToP2(Struct3ConformsToP2())
171
170
var someP1Ref = ClassConformsToP1()
172
- var someP1Ref2 = Class2ConformsToP1(true )
171
+ var someP1Ref2 = Class2ConformsToP1(ClassConformsToP1() )
173
172
var someNotP1Ref = ClassDoesNotConformToP1()
174
173
175
174
expectTrue(someP1Value is P1)
@@ -209,57 +208,57 @@ Runtime.test("dynamicCasting with as") {
209
208
expectTrue(someP1Ref2 as AnyObject is P1)
210
209
expectFalse(someNotP1Ref as AnyObject is P1)
211
210
212
- expectTrue((someP1Value as P1).boolValue )
213
- expectTrue((someP1Value2 as P1).boolValue )
211
+ expectTrue((someP1Value as P1).success )
212
+ expectTrue((someP1Value2 as P1).success )
214
213
expectEqual("10 20 30 40", (someP2Value as P2).description)
215
214
expectEqual("10 20 30 40 50 60 70 80", (someP2Value2 as P2).description)
216
215
217
- expectTrue((someP1Ref as P1).boolValue )
218
- expectTrue((someP1Ref2 as P1).boolValue )
216
+ expectTrue((someP1Ref as P1).success )
217
+ expectTrue((someP1Ref2 as P1).success )
219
218
220
- expectTrue(((someP1Value as Q1) as! P1).boolValue )
221
- expectTrue(((someP1Value2 as Q1) as! P1).boolValue )
219
+ expectTrue(((someP1Value as Q1) as! P1).success )
220
+ expectTrue(((someP1Value2 as Q1) as! P1).success )
222
221
expectEqual("10 20 30 40", ((someP2Value as Q1) as! P2).description)
223
222
expectEqual("10 20 30 40 50 60 70 80",
224
223
((someP2Value2 as Q1) as! P2).description)
225
- expectTrue(((someP1Ref as Q1) as! P1).boolValue )
226
- expectTrue(((someP1Ref2 as Q1) as! P1).boolValue )
224
+ expectTrue(((someP1Ref as Q1) as! P1).success )
225
+ expectTrue(((someP1Ref2 as Q1) as! P1).success )
227
226
228
- expectTrue(((someP1Value as Any) as! P1).boolValue )
229
- expectTrue(((someP1Value2 as Any) as! P1).boolValue )
227
+ expectTrue(((someP1Value as Any) as! P1).success )
228
+ expectTrue(((someP1Value2 as Any) as! P1).success )
230
229
expectEqual("10 20 30 40", ((someP2Value as Any) as! P2).description)
231
230
expectEqual("10 20 30 40 50 60 70 80",
232
231
((someP2Value2 as Any) as! P2).description)
233
- expectTrue(((someP1Ref as Any) as! P1).boolValue )
234
- expectTrue(((someP1Ref2 as Any) as! P1).boolValue )
232
+ expectTrue(((someP1Ref as Any) as! P1).success )
233
+ expectTrue(((someP1Ref2 as Any) as! P1).success )
235
234
236
- expectTrue(((someP1Ref as AnyObject) as! P1).boolValue )
235
+ expectTrue(((someP1Ref as AnyObject) as! P1).success )
237
236
238
237
expectEmpty((someNotP1Value as? P1))
239
238
expectEmpty((someNotP1Ref as? P1))
240
239
241
- expectTrue(((someP1Value as Q1) as? P1)!.boolValue )
242
- expectTrue(((someP1Value2 as Q1) as? P1)!.boolValue )
240
+ expectTrue(((someP1Value as Q1) as? P1)!.success )
241
+ expectTrue(((someP1Value2 as Q1) as? P1)!.success )
243
242
expectEmpty(((someNotP1Value as Q1) as? P1))
244
243
expectEqual("10 20 30 40", ((someP2Value as Q1) as? P2)!.description)
245
244
expectEqual("10 20 30 40 50 60 70 80",
246
245
((someP2Value2 as Q1) as? P2)!.description)
247
- expectTrue(((someP1Ref as Q1) as? P1)!.boolValue )
248
- expectTrue(((someP1Ref2 as Q1) as? P1)!.boolValue )
246
+ expectTrue(((someP1Ref as Q1) as? P1)!.success )
247
+ expectTrue(((someP1Ref2 as Q1) as? P1)!.success )
249
248
expectEmpty(((someNotP1Ref as Q1) as? P1))
250
249
251
- expectTrue(((someP1Value as Any) as? P1)!.boolValue )
252
- expectTrue(((someP1Value2 as Any) as? P1)!.boolValue )
250
+ expectTrue(((someP1Value as Any) as? P1)!.success )
251
+ expectTrue(((someP1Value2 as Any) as? P1)!.success )
253
252
expectEmpty(((someNotP1Value as Any) as? P1))
254
253
expectEqual("10 20 30 40", ((someP2Value as Any) as? P2)!.description)
255
254
expectEqual("10 20 30 40 50 60 70 80",
256
255
((someP2Value2 as Any) as? P2)!.description)
257
- expectTrue(((someP1Ref as Any) as? P1)!.boolValue )
258
- expectTrue(((someP1Ref2 as Any) as? P1)!.boolValue )
256
+ expectTrue(((someP1Ref as Any) as? P1)!.success )
257
+ expectTrue(((someP1Ref2 as Any) as? P1)!.success )
259
258
expectEmpty(((someNotP1Ref as Any) as? P1))
260
259
261
- expectTrue(((someP1Ref as AnyObject) as? P1)!.boolValue )
262
- expectTrue(((someP1Ref2 as AnyObject) as? P1)!.boolValue )
260
+ expectTrue(((someP1Ref as AnyObject) as? P1)!.success )
261
+ expectTrue(((someP1Ref2 as AnyObject) as? P1)!.success )
263
262
expectEmpty(((someNotP1Ref as AnyObject) as? P1))
264
263
265
264
let doesThrow: (Int) throws -> Int = { $0 }
0 commit comments