[SR-8326] Surprising interaction between casting to Any and optional promotion #50854
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: d3ffe3ad04c62bbbfa33f820cf0e61f4
relates to:
Issue Description:
Consider the code below.
The first condition always succeeds because wat is promoted to Int??, and produces a nice compiler warning about it. However, there is a surprising mismatch between the first and second conditions – the coercion to Any disables optional promotion, and instead, it attempts to unwrap wat and cast it to an Optional<Any> value. When run, the program prints "1" only.
I'd have expected the two conditions to either both pass, or both fail. (The latter option seems to make slightly more sense – it seems surprising that we allow optional promotion of an optional value in an optional check.)
The text was updated successfully, but these errors were encountered: