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-492 Protocol extenstion methods aren't exposed to Objective-C
Issue Description:
The following code should reproduce the issue: When a protocol(MyProtocol in this case) inherits from a protocol(OptionalDelegate) containing optional methods(doTheOptionalThing) and an extension is providing a default implementation for the optional methods they are not invoked when conforming instance is assigned to a property (delegate pattern).
See especially comments 2. and 3. below, the line "I am doing the OPTIONAL thing!" is not showing up as it should. It seems the optional method is not copied correctly to the property's instance.
Am I missing something critical?
importFoundation@objcprotocolOptionalDelegate: class {
@objcoptionalfuncdoTheOptionalThing()
}
protocolNonOptionalDelegate: class {
funcdoTheNonOptionalThing()
}
protocolMyProtocol: OptionalDelegate, NonOptionalDelegate {
}
extensionOptionalDelegatewhereSelf: MyProtocol {
funcdoTheOptionalThing() {
print("I am doing the OPTIONAL thing!")
}
funcdoTheNonOptionalThing() {
print("I am doing the NON OPTIONAL thing!")
}
}
classTestWithoutOptionalImpl: NSObject, MyProtocol {
}
classTestWithOptionalImpl: NSObject, MyProtocol {
funcdoTheOptionalThing() {
print("I am doing the OPTIONAL thing by overwriting implemenation in class")
}
}
classTestDelegator {
weakvardelegateOptional: OptionalDelegate?
weakvardelegateNonOptional: NonOptionalDelegate?
funcgoAhead(){
guardletdelegateOptional = delegateOptionalelse { return}
delegateOptional.doTheOptionalThing?()
guardletdelegateNonOptional = delegateNonOptionalelse { return}
delegateNonOptional.doTheNonOptionalThing()
}
}
print("--- Testing direct invokation ---")
lettestWithoutOptionalImpl = TestWithoutOptionalImpl()
testWithoutOptionalImpl.doTheOptionalThing()
testWithoutOptionalImpl.doTheNonOptionalThing()
print("--- Testing for indirection through property ---")
lettestDelegator = TestDelegator()
testDelegator.delegateOptional = testWithoutOptionalImpl// 1. Testing if the the instance is actually assignedprint("Do we have an instance stored in the property? -> \(testDelegator.delegateOptional)" )
// 2. Is not invoking doTheOptionalThing() testDelegator.delegateOptional?.doTheOptionalThing?()
testDelegator.delegateNonOptional = testWithoutOptionalImpl// 3. Is not invoking doTheOptionalThing() testDelegator.goAhead()
print("--- Testing for indirection through property with a direct implementation in class ---")
lettestWithOptionalImpl = TestWithOptionalImpl()
testDelegator.delegateOptional = testWithOptionalImpltestDelegator.delegateNonOptional = testWithOptionalImpltestDelegator.goAhead()
Additional Detail from JIRA
md5: c948e1f6e6fec2b19196b6af4576171b
duplicates:
Issue Description:
The following code should reproduce the issue: When a protocol(
MyProtocol
in this case) inherits from a protocol(OptionalDelegate
) containing optional methods(doTheOptionalThing
) and an extension is providing a default implementation for the optional methods they are not invoked when conforming instance is assigned to a property (delegate pattern).See especially comments 2. and 3. below, the line "I am doing the OPTIONAL thing!" is not showing up as it should. It seems the optional method is not copied correctly to the property's instance.
Am I missing something critical?
Output
Expected Output
The text was updated successfully, but these errors were encountered: