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-6001] Protocols inheriting from classes #48558
Comments
@DougGregor, @slavapestov, sound familiar? |
We haven't implemented protocols inheriting from classes yet, however it is a part of SE-0156 and we should do it eventually. I'll take this. |
Comment by Erich Graham (JIRA) Looks like SE-0156's status is Implemented. Is this bug still slated to be done then? Relevant forum post: https://forums.swift.org/t/defining-protocols-for-certain-class-types-only/8702/11 |
I think we just forgot to update the status of this, no? Works fine for me with Swift 4.1: class Strawman {
}
protocol Fooable where Self: Strawman {
func foo()
}
extension Strawman: Fooable {
public func foo() { print("Foo!") }
}
let s = Strawman()
s.foo() prints |
Comment by Erich Graham (JIRA) This code does not work, Swift 4.1: protocol HeaderViewing where Self: UIView {
func set(title: String)
}
class MyView: UIView, HeaderViewing {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func set(title: String) {
}
}
let myView: HeaderViewing = MyView(frame: .zero)
myView.set(title: "Hello")
myView.removeFromSuperview() /** Value of type 'HeaderViewing' has no member 'removeFromSuperview' */ |
Comment by Erich Graham (JIRA) Any idea if this bug will be resolved in 4.2 or 5.0? This forces the above example to define the variable as `let myView: HeaderViewing & UIView` when it should work as written, `let myView: HeaderViewing` |
Environment
Swift 4
Additional Detail from JIRA
md5: e5e571eae12cbeb9d9440144200dc67c
duplicates:
Issue Description:
class Strawman {
}
protocol Fooable where Self: Strawman {
func foo()
}
// This doesn't seem like an especially useful thing to do
// and might reasonably be an error, but I think hard
// crashing the compiler is a bit much.
extension Strawman: Fooable {
public func foo() { print("Foo!") }
}
The text was updated successfully, but these errors were encountered: