I think this must be a bug. The following test passes if the Optional
initializer is declared as a failable initializer, but fails if the ?
is removed from the Optional
initializer.
The Test
@Test
func foo() {
#expect(
Demo<Optional<Int>>.test()
)
}
struct Demo<T: Foo> {
static func test() -> Bool {
if let a = T.init() {
return true
}
return false
}
}
protocol Foo {
init?()
}
Passes If Optional Conforms Like This:
extension Optional: Foo {
init?() {
self = Self.none
}
}
Fails If Optional Conforms Like This:
extension Optional: Foo {
init() {
self = Self.none
}
}