Skip to content
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-923] override a property of a NSObject subclass generates inconsistent behavior #43535

Closed
swift-ci opened this issue Mar 11, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-923
Radar None
Original Reporter henrik (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 78a01c56a5144f376019aa284e056e65

duplicates:

  • SR-584 Unexpected behavior when overriding a superclass’ method in an extension

Issue Description:

There is an inconsistent behavior in overriding a property or method of a NSObject subclass.

In Swift you are allowed to override a property or a method in an extension to the class, if the class derives from a NSObject subclass. But in the result the behavior of the class is not the same as if you would override the method or property in the subclass itself.

This is the Base Class:

public class LevelA : NSObject {
public var levelDescription : String {
return "LevelA"
}
}

There is a inconsistent behavior (bug) when overriding a property of a NSObject subclass in swift between these two cases :

Case 1:

public class LevelB1 : LevelA {
}
public extension LevelB1 {
override public var levelDescription : String {
return "LevelB1"
}
}

Case 2:

public class LevelB2 : LevelA {
override public var levelDescription : String {
return "LevelB2"
}
}

You can see the Bug with this code or the attached file in Xcode:

let value1 : LevelA = LevelB1()
let value2 : LevelB1 = LevelB1()

print(value1.levelDescription) // Wrong output in this line!
print(value2.levelDescription)

let value3 : LevelA = LevelB2()
let value4 : LevelB2 = LevelB2()

print(value3.levelDescription)
print(value4.levelDescription)

As a result you should not override any properties in a extension. It breaks the ObjC behavior.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant