You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-103 Protocol Extension: function's implementation cannot be overridden by a subclass
SR-118 Protocol extensions cannot be overridden in subclasses
Issue Description:
I have come across an issue where I want to have a class conform to a protocol by default, but the protocol has default implementations of all it's methods through an extension. I then want to subclass the original class and optionally implement the protocol methods.
Unfortunately by trying to do this I ran into a problem where the methods in the protocol extension were being called over the methods implemented in the subclass which I believe is unintended behaviour. The methods implemented in the main class were being called instead of the protocol extension methods fine.
I have included a Xcode playground to demonstrate this behaviour.
protocolMyProtocol {
funcdoTheFirstThing()
funcdoTheSecondThing()
funcdoTheThirdThing()
}
extensionMyProtocol {
funcdoTheFirstThing() {
print("The DEFAULT first thing")
}
funcdoTheSecondThing() {
print("The DEFAULT second thing")
}
funcdoTheThirdThing() {
print("The DEFAULT third thing")
}
}
classMyClass: MyProtocol {
funcmyMethod() {
self.doTheFirstThing()
self.doTheSecondThing()
self.doTheThirdThing()
}
funcdoTheFirstThing() {
print("This implementation of the first thing should be called instead of the default implementation")
}
}
classMySubclass: MyClass {
funcdoTheSecondThing() {
print("This implementation of the second thing should be called instead of the default implementation")
}
}
MySubclass().myMethod()
// This implementation of the first thing should be called instead of the default implementation// The DEFAULT second thing (This should be the implementation from the subclass)// The DEFAULT third thing
The text was updated successfully, but these errors were encountered:
After having a search around I've found this is a duplicate of SR-118, but according to that ticket it was resolved on 8th December 2015. As it stands that was several months before Swift 2.2 so I would assume that it would be included in that release, but this is not the case.
I don't know where to track this particular fix in the codebase as there are no references to releases in the resolved issue. I will link this open issue to it as a duplicate, but it's an ongoing issue that has yet to be resolved.
Attachment: Download
Environment
Xcode 7.3, Swift 2.2, OSX 10.11.4
Additional Detail from JIRA
md5: 606381dd1b70783cd53f6d0bee513f00
duplicates:
Issue Description:
I have come across an issue where I want to have a class conform to a protocol by default, but the protocol has default implementations of all it's methods through an extension. I then want to subclass the original class and optionally implement the protocol methods.
Unfortunately by trying to do this I ran into a problem where the methods in the protocol extension were being called over the methods implemented in the subclass which I believe is unintended behaviour. The methods implemented in the main class were being called instead of the protocol extension methods fine.
I have included a Xcode playground to demonstrate this behaviour.
The text was updated successfully, but these errors were encountered: