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
2016 MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
macOS Mojave
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 25c7673210e45a80636c5e66f7f8983a
duplicates:
SR-103 Protocol Extension: function's implementation cannot be overridden by a subclass
Issue Description:
If a protocol has an extension with default values for the protocol's properties, and a class implements that protocol without defining those property values, and a subclass of that class does define property values, passing an instance of that subclass to a function that takes a protocol argument doesn't
Steps to Reproduce:
1. Declare a protocol with a read-only properties.
protocol Protocol {
var string: String { get }
}
2. Declare a protocol extension that implements the properties by returning fixed values.
6. Inside the function, access the subclass instance's properties. Instead of seeing the subclass's own values, the protocol extension's values are returned.
Passing an instance to the function should print the SubclassOfEmptyClass's string property ("SubclassOfEmptyClass's string").
Actual Results:
It prints the protocol extension's string property ("Protocol extension's string"). This happens even if the original protocol is declared as a class-only protocol (i.e. protocol Protocol: class).
The obvious workaround is to implement the properties in the EmptyClass, which will force the SubclassOfEmptyClass's properties to specify that they override the superclass's values, but that requires any class that implements the protocol to lose access to the protocol extension's default values.
The text was updated successfully, but these errors were encountered:
Attachment: Download
Environment
Xcode 10.2 (10E125)
2016 MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports)
macOS Mojave
Additional Detail from JIRA
md5: 25c7673210e45a80636c5e66f7f8983a
duplicates:
Issue Description:
If a protocol has an extension with default values for the protocol's properties, and a class implements that protocol without defining those property values, and a subclass of that class does define property values, passing an instance of that subclass to a function that takes a protocol argument doesn't
Steps to Reproduce:
1. Declare a protocol with a read-only properties.
2. Declare a protocol extension that implements the properties by returning fixed values.
3. Declare an NSObject subclass that implements the protocol, but do NOT implement the protocol's properties.
4. Subclass the empty class from step 3, and implement the protocol's properties to return the subclass's own values.
5. Pass an instance of the subclass to a function that takes a parameter of the protocol's type.
6. Inside the function, access the subclass instance's properties. Instead of seeing the subclass's own values, the protocol extension's values are returned.
Expected Results:
Passing an instance to the function should print the SubclassOfEmptyClass's string property ("SubclassOfEmptyClass's string").
Actual Results:
It prints the protocol extension's string property ("Protocol extension's string"). This happens even if the original protocol is declared as a class-only protocol (i.e. protocol Protocol: class).
The obvious workaround is to implement the properties in the EmptyClass, which will force the SubclassOfEmptyClass's properties to specify that they override the superclass's values, but that requires any class that implements the protocol to lose access to the protocol extension's default values.
The text was updated successfully, but these errors were encountered: