[SR-4347] Improve inference of optional supertypes #46926
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: 20d0e6f1bcce37e45b35dd11807d17ac
Issue Description:
If an array literal contains at least one element that is a nil literal and at least one other element that is of type T, the type checker will set the element type of the array to Optional<T>:
This also works in other situations, where the type checker tries to find a common supertype of multiple expressions:
However, this currently only seems to work if T is a nominal type. If T is any other kind of type, there's a type error:
There is no reason why this shouldn't work with other types as well.
The text was updated successfully, but these errors were encountered: