[SR-16058][Sema] Consider wrapping type variable layers of optionality when warning about checked casts #42050
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #39648 I have only considered an extra layer of optionality coming from a value-to-optional constraint restriction.
But that is not the only case where extra optionals need to be added. This can come from overload resolution of a unresolved member producing as result a generic argument that would be bound by context wrapped in layers of optionality. For example the case in the SR:
If we look to the constraints debugging we can se that
checked cast
constraint is$T3 checked cast to String
Where overload being attempted is
selected overload set choice Int?.flatMap: $T1 == (($T2) throws -> $T3?) throws -> $T3?
So when recording warning fixes we should consider these extra layer of optionality(
$T3?
) in the "from" checked cast sub-expression.This changes the logic to be based on type of checked cast "from" expression when it is a type variable wrapped in optionals to handle this correctly.
Resolves SR-16058.