File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,9 @@ struct Allocation<T>: ~Copyable {
35
35
_ body: ( inout OutputSpan < T > ) throws ( E ) -> Void
36
36
) throws ( E) {
37
37
if count != nil { fatalError ( ) }
38
- var outputBuffer = OutputSpan < T > ( buffer: allocation, initializedCount: 0 )
38
+ var allocation = allocation
39
+ if allocation. count == 0 { allocation = . init( start: nil , count: 0 ) }
40
+ var outputBuffer = OutputSpan ( buffer: allocation, initializedCount: 0 )
39
41
do {
40
42
try body ( & outputBuffer)
41
43
let initialized = outputBuffer. finalize ( for: allocation)
@@ -188,6 +190,20 @@ suite.test("deinitialize buffer")
188
190
catch {
189
191
expectTrue ( false )
190
192
}
193
+
194
+ a = Allocation ( of: 0 , Int . self)
195
+ do {
196
+ try a. initialize {
197
+ expectEqual ( $0. freeCapacity, 0 )
198
+ throw MyTestError . error
199
+ }
200
+ }
201
+ catch MyTestError . error {
202
+ expectEqual ( a. isEmpty, true )
203
+ }
204
+ catch {
205
+ expectTrue ( false )
206
+ }
191
207
}
192
208
193
209
suite. test ( " InlineArray initialization " )
You can’t perform that action at this time.
0 commit comments