File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,12 @@ public struct Mirror {
137
137
138
138
/// A collection of `Child` elements describing the structure of the
139
139
/// reflected subject.
140
- public var children : Children { AnyCollection ( _children) }
140
+ public var children : Children {
141
+ switch _children {
142
+ case let . left( l) : return AnyCollection ( l)
143
+ case let . right( r) : return AnyCollection ( r)
144
+ }
145
+ }
141
146
142
147
/// A suggested display style for the reflected subject.
143
148
public let displayStyle : DisplayStyle ?
Original file line number Diff line number Diff line change @@ -150,6 +150,25 @@ mirrors.test("LabeledStructure") {
150
150
expectEqual ( " [bark: 1, bite: Zee] " , h. testDescription)
151
151
}
152
152
153
+ mirrors. test ( " ErasedChildren " ) {
154
+ let m1 = Mirror ( reflecting: 1 ..< 4 )
155
+ let c1 = AnyRandomAccessCollection ( m1. children)
156
+ expectNotNil ( c1)
157
+ expectNil ( c1? . first? . label)
158
+ expectTrue ( c1? . first? . label as? Int == 1 )
159
+ expectNil ( c1? . last? . label)
160
+ expectTrue ( c1? . last? . value as? Int == 3 )
161
+
162
+ struct Foo { let i = 42 ; let s = " bar " }
163
+ let m2 = Mirror ( reflecting: Foo ( ) )
164
+ let c2 = AnyRandomAccessCollection ( m2. children)
165
+ expectNotNil ( c2)
166
+ expectTrue ( c2? . first? . label == " i " )
167
+ expectTrue ( c2? . first? . label as? Int == 42 )
168
+ expectTrue ( c2? . last? . label == " s " )
169
+ expectTrue ( c2? . last? . value as? String == " bar " )
170
+ }
171
+
153
172
mirrors. test ( " Legacy " ) {
154
173
let m = Mirror ( reflecting: [ 1 , 2 , 3 ] )
155
174
expectTrue ( m. subjectType == [ Int ] . self)
You can’t perform that action at this time.
0 commit comments