Swift: strange error when using Self as return type
| Originator: | garth | ||
| Number: | rdar://19668559 | Date Originated: | 30-Jan-2015 01:51 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.2b4 6C107a |
| Classification: | Serious Bug | Reproducible: | Always |
I’m not sure if Self is allowed in this context, but even if it’s not, this error message is very strange:
import Foundation
@objc protocol TestProtocol {}
@objc class TestClass: TestProtocol {
func test() -> Self {
let test = self as TestProtocol // cannot downcast from 'Self' to non-@objc protocol type 'TestProtocol'
return self
}
}
If you adjust the signature of test() to return TestClass, the compiler is happy.
Here’s another variant presentation of what seems to be the same issue:
import Foundation
@objc protocol TestProtocol {}
@objc class TestClass: TestProtocol {
func test() -> Self {
// Error: Type 'Self' does not conform to protocol 'TestProtocol'
testFunction(self)
return self
}
}
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!