Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13899] Missing conditional cast fix-it #56297

Closed
dan-zheng opened this issue Nov 26, 2020 · 1 comment
Closed

[SR-13899] Missing conditional cast fix-it #56297

dan-zheng opened this issue Nov 26, 2020 · 1 comment

Comments

@dan-zheng
Copy link
Collaborator

dan-zheng commented Nov 26, 2020

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?
@dan-zheng
Copy link
Collaborator Author

dan-zheng commented Dec 2, 2020

Done in #34883

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants