Open
Description
Description
A common trick employed in Swift is to conform Optional
to some protocol in order to work around a lack of parameterized extensions (see this pitch).
This trick unfortunately broke in Swift 6.
Reproduction
Here's a test case:
import Testing
private protocol OptionalProtocol { static var none: Self { get } }
extension Optional: OptionalProtocol {}
func none<Result>(_: Result.Type) throws -> Result {
if let result = Result.self as? any OptionalProtocol.Type {
return result.none as! Result
}
throw MyError()
}
struct MyError: Error {}
@Test func example() async throws {
let int = try none(Int?.self)
#expect(int == nil)
}
Expected behavior
I would expect the test to pass, but instead an error is thrown.
Environment
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0
Additional information
No response