-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomerstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
Previous ID | SR-13899 |
Radar | None |
Original Reporter | @dan-zheng |
Type | Bug |
Status | Closed |
Resolution | Done |
Additional Detail from JIRA
Votes | 1 |
Component/s | Compiler |
Labels | Bug, DiagnosticsQol, StarterBug, TypeChecker |
Assignee | luciano (JIRA) |
Priority | Medium |
md5: 79f973c3624b69402e948da2cfdd28c7
Issue Description:
let any: Any = 1
if let int = any as Int {
// ...
}
$ swiftc missing-checked-cast-fixit.swift
missing-conditional-cast-fixit.swift:2:18: error: 'Any' is not convertible to 'Int'; did you mean to use 'as!' to force downcast?
if let int = any as Int {
~~~~^~~~~~
as!
There's only a fix-it for force downcasting (as!
). It could also make sense to have one for conditional downcasting (as?
), I ran into such a case in practice. Example:
missing-checked-cast-fixit.swift:2:18: error: 'Any' is not convertible to 'Int'; did you mean to use 'as?' to conditionally downcast?
if let int = any as Int {
~~~~^~~~~~
as?
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationBug: Diagnostics Quality of Implementationgood first issueGood for newcomersGood for newcomerstype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis