Open
Description
Previous ID | SR-12093 |
Radar | rdar://problem/58999135 |
Original Reporter | @CodaFi |
Type | Improvement |
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Improvement, StarterProposal |
Assignee | inatonix (JIRA) |
Priority | Medium |
md5: f23b80191801a31166f6b799915c7a23
cloned from:
- SR-11421 Checked Cast Diagnostics Should Be More Specific When Literals Are Involved
Issue Description:
Checked casts on literals can have surprising effects at face value
let character = "A" as Character
let bad = "A" as? Character
The former is a character literal and is statically coerced. The latter is a String literal that is being dynamically cast to a Character. This cast will always fail, and we note as much - this also works with as! force casts.
warning: cast from 'String' to unrelated type 'Character' always fails
This behavior is deeply unintuitive and should be revisited by a proposal to unify casting semantics for literals.