-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
castingFeature: explicit casting (is, as, as? and as!)Feature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfThe Swift compiler itselfimprovementliteralsFeature → expressions: Literals such as an integer or string literalFeature → expressions: Literals such as an integer or string literalswift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposalFlag → feature: A feature that warrants a Swift evolution proposal
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.
Metadata
Metadata
Assignees
Labels
castingFeature: explicit casting (is, as, as? and as!)Feature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfThe Swift compiler itselfimprovementliteralsFeature → expressions: Literals such as an integer or string literalFeature → expressions: Literals such as an integer or string literalswift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposalFlag → feature: A feature that warrants a Swift evolution proposal