Skip to content

Commit fd6197f

Browse files
authored
Merge pull request #74453 from gregomni/issue-46000
[Sema] Add validation test for issue #46000
2 parents 9300c16 + 56f0958 commit fd6197f

File tree

1 file changed

+24
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)