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-5252] Warning: Cast from … to unrelated type false positive? #47827
Comments
@slavapestov, look familiar? |
Comment by Hannes Oud (JIRA) Still getting this in Xcode 9.0 beta 3 |
Comment by Hannes Oud (JIRA) @slavapestov @belkadan Still gettting this in Xcode 9.0 beta 4 |
@swift-ci create |
Comment by Erik Kerber (JIRA) I get the same in Xcode 9 and 9.1 beta. Similarly, I observe this when making a generic subclass of UICollectionViewCell. |
Comment by Igor Silva (JIRA) It is still happening on 9.1 beta. It's definitely a bug, since "unreachable code" (according to the warning) runs. |
Comment by Joanna Carter (JIRA) This is still happening in Xcode Version 10.1 (10B61). The problem is definitely connected to the joining of two types, as in this thread on the Swift forums: https://forums.swift.org/t/generics-causing-pain-yet-again/21156?u=joanna_carter It might not show up in a playground |
This is fixed on master, apparently without direct intention. I'm going to add a regression test just in case. protocol P {}
class Helper {}
class Base {}
class Sub<T>: Base {}
// The subclass existential constraint was the culprit.
func foo<T: Helper & P>(base: Base, arg: T) {
_ = base as? Sub<T>
} |
"Suddenly fixed" 🙂 |
Comment by Hannes Oud (JIRA) @AnthonyLatsis great, glad to hear and thanks for following up on this!! |
Attachment: Download
Environment
Version 9.0 and 9.1 beta
Additional Detail from JIRA
md5: 36726ef60ce123c2e833d053b96ea84d
is duplicated by:
Issue Description:
I get a warning, which I think is a false positive, or am I missing something?
The warning arrives as soon as I constrain the Generic Type parameter to comply to a certain protocol. There should imho be no warning, as the attempted cast casts to a (generic) subclass of the given one.
For a few examples compile the attached swift file with Xcode 9 beta 1, swift 4.
Or look at this snippet:
The text was updated successfully, but these errors were encountered: