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-6771] "Cast always fails" false positive warning when casting to a generic subclass #49320

Closed
swift-ci opened this issue Jan 16, 2018 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-6771
Radar None
Original Reporter averello (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 6ec41517e9a1f2c684d6ec7852978b33

duplicates:

  • SR-5252 Warning: Cast from … to unrelated type false positive?
  • SR-6353 Cast from to unrelated type always fails but doesn't fail

Issue Description:

class View {}
protocol Delegate: class {}
class ViewAndDelegate: View, Delegate {}

class Subview<T>: View where T: View, T: Delegate {
    func something(argument: View) {
        guard let subtype = argument as? Subview<T> else { return }
        // do something with `subtype`
        let _ = subtype
        print("does not fail")
    }
}

let subview = Subview<ViewAndDelegate>()
subview.something(argument: subview)

The line with the guard produces the following warning:

Cast from 'View' to unrelated type 'Subview<T>' always fails

The cast succeeds if the user calls something(argument: subview) and "does not fail" gets printed on the console.

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant