Apparent compiler bug relating to Optional witnessing failable initializer requirement #78409
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
conformances
Feature → protocol: protocol conformances
init
Feature → declarations: Initializers
Optional
Area → standard library: The `Optional` type
SILGen
Area → compiler: The SIL generation stage
swift 6.0
unexpected behavior
Bug: Unexpected behavior or incorrect output
Description
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 theOptional
initializer.The Test
Passes If Optional Conforms Like This:
Fails If Optional Conforms Like This:
Original Swift Forums Post: https://forums.swift.org/t/apparent-compiler-bug-relating-to-optional-witnessing-failable-initializer-requirement/76759
Reproduction
Expected behavior
I expected that the unwrapping
if let a = T.init() { }
would succeed since in this caseT == Optional<Int>
andOptional
unconditionally succeeds in initializing itself to.none
.Environment
Swift 6
Additional information
No response
The text was updated successfully, but these errors were encountered: