Skip to content

Commit bce544a

Browse files
author
Greg Titus
committed
Add validation test for issue #46000
1 parent 25830d6 commit bce544a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// https://github.com/apple/swift/issues/46000
4+
5+
import Dispatch
6+
import Foundation
7+
8+
extension DispatchData {
9+
10+
func asFoundationData<T>(execute: (Data) throws -> T) rethrows -> T {
11+
12+
//FIXME: SWIFT(SR-3097) - DispatchData.withUnsafeBytes crashes when empty.
13+
guard isEmpty == false else {
14+
return try execute(Data())
15+
}
16+
17+
return try withUnsafeBytes { (ptr: UnsafePointer<Int8>) -> Void in
18+
// expected-error@-1 {{cannot convert return expression of type 'Void' to return type 'T'}}
19+
let foundationData = Data(bytesNoCopy: UnsafeMutableRawPointer(mutating: ptr), count: count, deallocator: .none)
20+
return try execute(foundationData) // expected-error {{cannot convert value of type 'T' to closure result type 'Void'}}
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)