-
Notifications
You must be signed in to change notification settings - Fork 10.5k
CSGen, SILGen: Fix delegations to Optional
initializers
#59171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSGen, SILGen: Fix delegations to Optional
initializers
#59171
Conversation
@swift-ci please smoke test macOS |
@swift-ci please test source compatibility |
@jckarter ping |
…zers Using `replaceCovariantResultType`, which looks through optionals, to substitute the container type for the result type would add an extra level of optionality to the result type whenever the container type was `Optional`, causing a crash later in the game. Besides, we don't have to do this in the first place, because we know these types match in the case of an initializer (neglecting optionality).
Relying on the optionality depth of the 'new self' value to flatten an extra level of optionality or handle a failure is not sufficient, because we may be delegating to an `Optional` initializer. Instead, flattening should occur if the result type of the enclosing initializer is less optional than 'new self', and failure handling — if the enclosing initializer is failable and its result type is as optional as the potentially flattened 'new self' value.
…onal` initializers We need the extra level of optionality here to discern between failures and constructed values.
9eaa365
to
1842772
Compare
I think we should reject those other cases involving Optional that unwrap into the constructed value itself. The |
@swift-ci Please test |
Thanks! Will put the addition of a tailored diagnostic for these force-unwraps on my radar. |
Resolves #57012 and more.
There remains a family of malfunctioning edge cases that I'm not sure what to make of. Specifically, when the constructed
Optional
value is force-unwrapped:I guess we should either deal with them using optional injections or ban them.