Skip to content

Commit 09e2e68

Browse files
committed
[Runtime] Fix the error callback test for platforms without ObjC interop.
rdar://problem/53400364
1 parent b8f5e84 commit 09e2e68

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/stdlib/Error.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,14 @@ ErrorTests.test("test dealloc empty error box") {
193193

194194
var errors: [Error] = []
195195
ErrorTests.test("willThrow") {
196-
typealias WillThrow = @convention(c) (Error) -> Void
196+
// Error isn't allowed in a @convention(c) function when ObjC interop is
197+
// not available, so pass it through an OpaquePointer.
198+
typealias WillThrow = @convention(c) (OpaquePointer) -> Void
197199
let willThrow = pointerToSwiftCoreSymbol(name: "_swift_willThrow")!
198-
willThrow.storeBytes(of: { errors.append($0) }, as: WillThrow.self)
200+
let callback: WillThrow = {
201+
errors.append(unsafeBitCast($0, to: Error.self))
202+
}
203+
willThrow.storeBytes(of: callback, as: WillThrow.self)
199204
expectTrue(errors.isEmpty)
200205
do {
201206
throw UnsignedError.negativeOne

0 commit comments

Comments
 (0)