Files
swift-mirror/test/Concurrency/Runtime/objc_exception_in_task.swift
Mike Ash 058b1ed822 [Concurrency] Block exception propagation through swift_job_run.
When an exception is thrown through swift_job_run, it leaves the Concurrency runtime in an inconsistent state, which can lead to misbehavior or crashes later on. It's very difficult to work out what the cause is when this happens. Since the program state is doomed once this happens, prevent exceptions from propagating through swift_job_run at all, and terminate immediately when throwing.

rdar://171909991
2026-05-08 10:16:29 -04:00

33 lines
718 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -import-objc-header %S/Inputs/ObjCExceptionHelpers.h %s -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out
// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: concurrency_runtime
// REQUIRES: objc_interop
// UNSUPPORTED: back_deployment_runtime
import Foundation
import StdlibUnittest
var tests = TestSuite("ObjCExceptionInTask")
tests.test("exception terminates in swift_job_runImpl") {
expectCrashLater()
Task { @MainActor in
ThrowObjCException()
}
_ = CatchingException {
RunLoop.current.run()
}
expectUnreachable("Exception should not propagate through swift_job_runImpl")
}
runAllTests()